-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update NFTForwarding transactions for new implementation
- Loading branch information
1 parent
1a261c0
commit d9ef40e
Showing
8 changed files
with
135 additions
and
171 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
transactions/NFTForwarding/unlink_forwarder_link_collection.cdc
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
transactions/nft-forwarding/change_forwarder_recipient.cdc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import NonFungibleToken from "NonFungibleToken" | ||
import NFTForwarding from "NFTForwarding" | ||
|
||
/// This transaction updates the NFTForwarder recipient to the one given at the specified PublicPath | ||
/// | ||
transaction(newRecipientAddress: Address, collectionPublicPath: PublicPath) { | ||
|
||
// reference to the NFTFowarder Resource | ||
let forwarderRef: auth(NFTForwarding.Mutable) &NFTForwarding.NFTForwarder | ||
// Collection we will designate as forwarding recipient | ||
let newRecipientCollection: Capability<&{NonFungibleToken.Collection}> | ||
|
||
prepare(signer: auth(BorrowValue) &Account) { | ||
// borrow reference to NFTForwarder resource | ||
self.forwarderRef = signer.storage.borrow<auth(NFTForwarding.Mutable) &NFTForwarding.NFTForwarder>( | ||
from: NFTForwarding.StoragePath | ||
) ?? panic("Could not borrow reference to NFTForwarder") | ||
|
||
// get Collection Capability from the recipientAddress account | ||
self.newRecipientCollection = getAccount(newRecipientAddress).capabilities.get<&{NonFungibleToken.Collection}>( | ||
collectionPublicPath | ||
) ?? panic("Could not get Collection capability from recipient") | ||
|
||
} | ||
|
||
execute { | ||
// set new recipient | ||
self.forwarderRef.changeRecipient(self.newRecipientCollection) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import NonFungibleToken from "NonFungibleToken" | ||
import MetadataViews from "MetadataViews" | ||
import NFTForwarding from "NFTForwarding" | ||
|
||
/// This transaction is what an account would run to set itself up to forward NFTs to a designated recipient's | ||
/// NFT.Collection assuming the recipient is configured for the given NFT Collection | ||
/// | ||
transaction(recipientAddress: Address, collectionPublicPath: PublicPath) { | ||
|
||
prepare(signer: auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue) &Account) { | ||
|
||
// get Collection Capability from the recipientAddress account | ||
let recipientCollectionCap = getAccount(recipientAddress).capabilities.get<&{NonFungibleToken.Collection}>( | ||
collectionPublicPath | ||
) ?? panic("Recipient is not configured with NFT Collection at the given path") | ||
|
||
// create a new NFTForwarder resource & save in storage, forwarding to the recipient's Collection | ||
let forwarder <- NFTForwarding.createNewNFTForwarder(recipient: recipientCollectionCap) | ||
signer.storage.save(<-forwarder, to: NFTForwarding.StoragePath) | ||
|
||
// unpublish existing Collection capabilities from PublicPath | ||
signer.capabilities.unpublish(collectionPublicPath) | ||
|
||
// create & publish a capability for the forwarder where the collection would normally be | ||
let forwarderReceiverCap = signer.capabilities.storage.issue<&{NonFungibleToken.Receiver}>(NFTForwarding.StoragePath) | ||
signer.capabilities.publish(forwarderReceiverCap, at: collectionPublicPath) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import NonFungibleToken from "NonFungibleToken" | ||
import ViewResolver from "ViewResolver" | ||
import MetadataViews from "MetadataViews" | ||
|
||
/// This transaction is for transferring an NFT from one account to the recipient's Receiver | ||
/// | ||
transaction( | ||
contractAddress: Address, | ||
contractName: String, | ||
recipient: Address, | ||
withdrawID: UInt64 | ||
) { | ||
|
||
// reference to the withdrawer's collection | ||
let withdrawRef: auth(Withdrawable) &{NonFungibleToken.Collection} | ||
// reference of the Receiver to deposit the NFT to | ||
let depositRef: &{NonFungibleToken.Receiver} | ||
|
||
prepare(signer: auth(BorrowValue) &Account) { | ||
|
||
// get the collection data from the NFT contract | ||
let nftContract = getAccount(contractAddress).contracts.borrow<&ViewResolver>(name: contractName) | ||
?? panic("Could not borrow ViewResolver reference to the contract") | ||
let collectionData = nftContract.resolveView(Type<MetadataViews.NFTCollectionData>()) as MetadataViews.NFTCollectionData? | ||
?? panic("Could not resolve NFTCollectionData view") | ||
|
||
// borrow a reference to the signer's NFT collection | ||
self.withdrawRef = signer.storage.borrow<auth(Withdrawable) &{NonFungibleToken.Collection}>( | ||
from: collectionData.storagePath | ||
) ?? panic("Account does not store an object at the specified path") | ||
|
||
// borrow a public reference to the recipient's Receiver | ||
self.depositRef = getAccount(recipient).capabilities.borrow<&{NonFungibleToken.Receiver}>( | ||
collectionData.publicPath | ||
) ?? panic("Could not borrow a reference to the recipient's Receiver") | ||
} | ||
|
||
execute { | ||
|
||
// withdraw the NFT from the owner's collection | ||
let nft <- self.withdrawRef.withdraw(withdrawID: withdrawID) | ||
|
||
// Deposit the NFT in the recipient | ||
self.depositRef.deposit(token: <-nft) | ||
} | ||
|
||
post { | ||
!self.withdrawRef.getIDs().contains(withdrawID): "Original owner should not have the NFT anymore" | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
transactions/nft-forwarding/unlink_forwarder_link_collection.cdc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
import NonFungibleToken from "NonFungibleToken" | ||
import MetadataViews from "MetadataViews" | ||
import NFTForwarding from "NFTForwarding" | ||
|
||
// This transaction replaces NFTForwarder Receiver Capabilities with a collection to its public storage after having configured | ||
// its NFTForwarder | ||
/// | ||
transaction(collectionStoragePath: StoragePath, receiverPublicPath: PublicPath) { | ||
|
||
prepare(signer: AuthAccount) { | ||
|
||
// a collection is already published, do nothing - remember .NFTForwarder only conforms to NFT.Receiver | ||
if signer.capabilities.get<&{NonFungibleToken.Collection}>(receiverPublicPath) != nil { | ||
return | ||
} | ||
|
||
// otherwise, unpublish the published Capability | ||
signer.capabilities.unpublish(receiverPublicPath) | ||
|
||
// create & publish a capability for the collection | ||
let collectionCap = signer.capabilities.storage.issue<&{NonFungibleToken.Collection}>(collectionStoragePath) | ||
signer.capabilities.publish(collectionCap, receiverPublicPath) | ||
|
||
} | ||
} |