Skip to content

Commit

Permalink
update NonFungibleToken-v2 implementation from source repo
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Oct 25, 2023
1 parent 0cb177a commit a1be91b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
42 changes: 21 additions & 21 deletions contracts/utility/NonFungibleToken.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ access(all) contract NonFungibleToken {
///
access(all) event Withdraw(id: UInt64, uuid: UInt64, from: Address?, type: String)

access(self) fun emitNFTWithdraw(id: UInt64, uuid: UInt64, from: Address?, type: String): Bool
access(self) view fun emitNFTWithdraw(id: UInt64, uuid: UInt64, from: Address?, type: String): Bool
{
emit Withdraw(id: id, uuid: uuid, from: from, type: type)
return true
Expand All @@ -70,7 +70,7 @@ access(all) contract NonFungibleToken {
///
access(all) event Deposit(id: UInt64, uuid: UInt64, to: Address?, type: String)

access(self) fun emitNFTDeposit(id: UInt64, uuid: UInt64, to: Address?, type: String): Bool
access(self) view fun emitNFTDeposit(id: UInt64, uuid: UInt64, to: Address?, type: String): Bool
{
emit Deposit(id: id, uuid: uuid, to: to, type: type)
return true
Expand All @@ -82,7 +82,7 @@ access(all) contract NonFungibleToken {
///
access(all) event Transfer(id: UInt64, uuid: UInt64, from: Address?, to: Address?, type: String)

access(self) fun emitNFTTransfer(id: UInt64, uuid: UInt64?, from: Address?, to: Address?, type: String?): Bool
access(self) view fun emitNFTTransfer(id: UInt64, uuid: UInt64?, from: Address?, to: Address?, type: String?): Bool
{
// The transfer method can return false even if it didn't do a transfer
// in which case we don't want the event to be emitted
Expand All @@ -99,7 +99,7 @@ access(all) contract NonFungibleToken {
/// The event that should be emitted when an NFT is destroyed
access(all) event Destroy(id: UInt64, uuid: UInt64, type: String)

access(self) fun emitNFTDestroy(id: UInt64, uuid: UInt64, type: String): Bool
access(self) view fun emitNFTDestroy(id: UInt64, uuid: UInt64, type: String): Bool
{
emit Destroy(id: id, uuid: uuid, type: type)
return true
Expand All @@ -122,7 +122,7 @@ access(all) contract NonFungibleToken {
destroy() {
pre {
//NonFungibleToken.emitNFTDestroy(id: self.getID(), uuid: self.uuid, type: self.getType().identifier)
NonFungibleToken.emitNFTDestroy(id: self.getID(), uuid: self.uuid, type: self.getType().identifier)
}
}
}
Expand All @@ -143,7 +143,7 @@ access(all) contract NonFungibleToken {
access(Withdrawable) fun withdraw(withdrawID: UInt64): @{NFT} {
post {
result.getID() == withdrawID: "The ID of the withdrawn token must be the same as the requested ID"
//NonFungibleToken.emitNFTWithdraw(id: result.getID(), uuid: result.uuid, from: self.owner?.address, type: result.getType().identifier)
NonFungibleToken.emitNFTWithdraw(id: result.getID(), uuid: result.uuid, from: self.owner?.address, type: result.getType().identifier)
}
}

Expand All @@ -161,7 +161,7 @@ access(all) contract NonFungibleToken {
access(Withdrawable) fun withdrawWithUUID(_ uuid: UInt64): @{NFT} {
post {
result == nil || result!.uuid == uuid: "The ID of the withdrawn token must be the same as the requested ID"
//NonFungibleToken.emitNFTWithdraw(id: result.getID(), uuid: result.uuid, from: self.owner?.address, type: result.getType().identifier)
NonFungibleToken.emitNFTWithdraw(id: result.getID(), uuid: result.uuid, from: self.owner?.address, type: result.getType().identifier)
}
}

Expand All @@ -170,7 +170,7 @@ access(all) contract NonFungibleToken {
access(Withdrawable) fun withdrawWithType(type: Type, withdrawID: UInt64): @{NFT} {
post {
result == nil || result.getID() == withdrawID: "The ID of the withdrawn token must be the same as the requested ID"
//NonFungibleToken.emitNFTWithdraw(id: result.getID(), uuid: result.uuid, from: self.owner?.address, type: result.getType().identifier)
NonFungibleToken.emitNFTWithdraw(id: result.getID(), uuid: result.uuid, from: self.owner?.address, type: result.getType().identifier)
}
}

Expand All @@ -179,7 +179,7 @@ access(all) contract NonFungibleToken {
access(Withdrawable) fun withdrawWithTypeAndUUID(type: Type, uuid: UInt64): @{NFT} {
post {
result == nil || result!.uuid == uuid: "The ID of the withdrawn token must be the same as the requested ID"
//NonFungibleToken.emitNFTWithdraw(id: result.getID(), uuid: result.uuid, from: self.owner?.address, type: result.getType().identifier)
NonFungibleToken.emitNFTWithdraw(id: result.getID(), uuid: result.uuid, from: self.owner?.address, type: result.getType().identifier)
}
}
}
Expand Down Expand Up @@ -260,24 +260,24 @@ access(all) contract NonFungibleToken {

/// deposit takes a NFT and adds it to the collections dictionary
/// and adds the ID to the id array
access(all) fun deposit(token: @{NonFungibleToken.NFT})
// {
// pre {
// // We emit the deposit event in the `Collection` interface
// // because the `Collection` interface is almost always the final destination
// // of tokens and deposit emissions from custom receivers could be confusing
// // and hard to reconcile to event listeners
// //NonFungibleToken.emitNFTDeposit(id: token.getID(), uuid: token.uuid, to: self.owner?.address, type: token.getType().identifier)
// }
// }
access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
pre {
// We emit the deposit event in the `Collection` interface
// because the `Collection` interface is almost always the final destination
// of tokens and deposit emissions from custom receivers could be confusing
// and hard to reconcile to event listeners
NonFungibleToken.emitNFTDeposit(id: token.getID(), uuid: token.uuid, to: self.owner?.address, type: token.getType().identifier)
}
}

/// Function for a direct transfer instead of having to do a deposit and withdrawal
/// This can and should return false if the transfer doesn't succeed and true if it does succeed
///
access(Withdrawable) fun transfer(id: UInt64, receiver: Capability<&{NonFungibleToken.Receiver}>): Bool {
pre {
receiver.check(): "Could not borrow a reference to the NFT receiver"
//NonFungibleToken.emitNFTTransfer(id: id, uuid: self.borrowNFTSafe(id: id)?.uuid, from: self.owner?.address, to: receiver.borrow()?.owner?.address, type: self.borrowNFT(id).getType().identifier)
self.getIDs().contains(id): "The collection does not contain the specified ID"
NonFungibleToken.emitNFTTransfer(id: id, uuid: self.borrowNFTSafe(id: id)?.uuid, from: self.owner?.address, to: receiver.borrow()?.owner?.address, type: self.borrowNFT(id).getType().identifier)
}
}

Expand Down Expand Up @@ -305,7 +305,7 @@ access(all) contract NonFungibleToken {

access(all) view fun borrowNFTSafe(id: UInt64): &{NonFungibleToken.NFT}? {
post {
(result == nil) || (result?.getID() == id):
(result == nil) || (result?.getID() == id):
"Cannot borrow NFT reference: The ID of the returned reference does not match the ID that was specified"
}
return nil
Expand Down
Loading

0 comments on commit a1be91b

Please sign in to comment.