Skip to content

Commit

Permalink
add subNFTs method, update forwarder events
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Jan 16, 2024
1 parent 2c9be03 commit b73ac84
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
14 changes: 13 additions & 1 deletion contracts/NonFungibleToken.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ access(all) contract NonFungibleToken {
}
}

/// Return a dictionary of all subNFTS if any
access(all) view fun getAvailableSubNFTS(): {Type: UInt64} {
return {}
}

/// Get a reference to an NFT that this NFT owns
/// Both arguments are optional to allow the NFT to choose
/// how it returns sub NFTs depending on what arguments are provided
Expand Down Expand Up @@ -157,7 +162,14 @@ access(all) contract NonFungibleToken {
access(all) resource interface Collection: Provider, Receiver {

/// Return the NFT CollectionData View
/// has to be AnyStruct and cast to the view later to avoid circular dependency issues
/// has to be AnyStruct to avoid circular dependency issues
/// the return value should be cast to MetadataViews.NFTCollectionData after it is returned
///
/// Metadata Views are a critical piece that NFT projects need to implement
/// in order to function properly in the flow ecosystem
///
/// Check out https://developers.flow.com/build/advanced-concepts/metadata-views
/// for a detailed guide on how to implement metadata views properly
access(all) fun getNFTCollectionDataView(): AnyStruct

/// Normally we would require that the collection specify
Expand Down
14 changes: 8 additions & 6 deletions contracts/utility/NFTForwarding.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ access(all) contract NFTForwarding {

access(all) entitlement Mutable

access(all) event ForwardedNFTDeposit(id: UInt64, from: Address?)
access(all) event UpdatedNFTForwarderRecipient(forwarder: Address?)
access(all) event ForwardedNFTDeposit(id: UInt64, uuid: UInt64, from: Address?, fromUUID: UInt64, to: Address, toUUID: UInt64)
access(all) event UpdatedNFTForwarderRecipient(forwarderAddress: Address?, forwarderUUID: UInt64, newRecipientAddress: Address, newRecipientUUID: UInt64)

/// Canonical Storage and Public paths
///
Expand All @@ -45,11 +45,11 @@ access(all) contract NFTForwarding {
let recipientRef = self.borrowRecipientCollection()
?? panic("Could not borrow reference to recipient's Collection!")
let id = token.id
let uuid = token.uuid

recipientRef.deposit(token: <-token)

emit ForwardedNFTDeposit(id: id, from: self.owner?.address)

emit ForwardedNFTDeposit(id: id, uuid: uuid, from: self.owner?.address, fromUUID: self.uuid, to: recipientRef.owner?.address, toUUID: recipientRef.uuid)
}

/// Enables reference retrieval of the recipient's Collection or nil
Expand All @@ -71,15 +71,17 @@ access(all) contract NFTForwarding {
}

self.recipient = newRecipient
emit UpdatedNFTForwarderRecipient(forwarder: self.owner?.address)
let recipientRef = self.recipientRef.borrow()!
emit UpdatedNFTForwarderRecipient(forwarderAddress: self.owner?.address, forwardarUUID: self.uuid, newRecipientAddress: recipientRef.owner?.address, newRecipientUUID: recipientRef.uuid)
}

init(_ recipient: Capability<&{NonFungibleToken.Collection}>) {
pre {
recipient.check(): "Could not borrow Collection reference from the given Capability"
}
self.recipient = recipient
emit UpdatedNFTForwarderRecipient(forwarder: self.owner?.address)
let recipientRef = self.recipientRef.borrow()!
emit UpdatedNFTForwarderRecipient(forwarderAddress: self.owner?.address, forwardarUUID: self.uuid, newRecipientAddress: recipientRef.owner?.address, newRecipientUUID: recipientRef.uuid)
}
}

Expand Down
Loading

0 comments on commit b73ac84

Please sign in to comment.