Skip to content

Commit

Permalink
add transaction comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Jun 26, 2024
1 parent c8c4fd0 commit 5bb8db3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import "MetadataViews"

import "FlowEVMBridgeUtils"

/// Configures a Collection according to the shared NonFungibleToken standard and the defaults specified by the NFT's
/// defining contract.
///
/// @param nftIdentifier: The identifier of the NFT to configure.
///
transaction(nftIdentifier: String) {

prepare(signer: auth(BorrowValue, SaveValue, IssueStorageCapabilityController, PublishCapability, UnpublishCapability) &Account) {
// Gather identifying information about the NFT and its defining contract
let nftType = CompositeType(nftIdentifier) ?? panic("Invalid NFT identifier: ".concat(nftIdentifier))
Expand All @@ -18,7 +24,20 @@ transaction(nftIdentifier: String) {
resourceType: nftType,
viewType: Type<MetadataViews.NFTCollectionData>()
) as! MetadataViews.NFTCollectionData?
?? panic("Could not resolve collection data for NFT type: ".concat(nftIdentifier))
?? panic("Could not resolve NFTCollection data for NFT type: ".concat(nftIdentifier))

// Check for collision, returning if the collection already exists or reverting on unexpected collision
let storedType = signer.storage.type(at: data.storagePath)
if storedType == nftType {
return
} else if storedType != nil {
panic(
"Another resource of type "
.concat(storedType!.identifier)
.concat(" already exists at the storage path: ")
.concat(data.storagePath.toString())
)
}

// Create a new collection and save it to signer's storage at the collection's default storage path
signer.storage.save(<-data.createEmptyCollection(), to: data.storagePath)
Expand Down
25 changes: 22 additions & 3 deletions cadence/transactions/example-assets/setup/setup_generic_vault.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import "FungibleTokenMetadataViews"

import "FlowEVMBridgeUtils"

/// Configures a Vault according to the shared FungibleToken standard and the defaults specified by the Vault's
/// defining contract.
///
/// @param vaultIdentifier: The identifier of the Vault to configure.
///
transaction(vaultIdentifier: String) {

prepare(signer: auth(BorrowValue, SaveValue, IssueStorageCapabilityController, PublishCapability, UnpublishCapability) &Account) {
// Gather identifying information about the Vault and its defining contract
let vaultType = CompositeType(vaultIdentifier) ?? panic("Invalid Vault identifier: ".concat(vaultIdentifier))
Expand All @@ -20,12 +26,25 @@ transaction(vaultIdentifier: String) {
resourceType: vaultType,
viewType: Type<FungibleTokenMetadataViews.FTVaultData>()
) as! FungibleTokenMetadataViews.FTVaultData?
?? panic("Could not resolve collection data for Vault type: ".concat(vaultIdentifier))
?? panic("Could not resolve FTVaultData for Vault type: ".concat(vaultIdentifier))

// Check for collision, returning if the vault already exists or reverting on unexpected collision
let storedType = signer.storage.type(at: data.storagePath)
if storedType == vaultType {
return
} else if storedType != nil {
panic(
"Another resource of type "
.concat(storedType!.identifier)
.concat(" already exists at the storage path: ")
.concat(data.storagePath.toString())
)
}

// Create a new collection and save it to signer's storage at the collection's default storage path
// Create a new vault and save it to signer's storage at the vault's default storage path
signer.storage.save(<-data.createEmptyVault(), to: data.storagePath)

// Issue a public Collection capability and publish it to the collection's default public path
// Issue a public Vault capability and publish it to the vault's default public path
signer.capabilities.unpublish(data.receiverPath)
let receiverCap = signer.capabilities.storage.issue<&{FungibleToken.Vault}>(data.storagePath)
signer.capabilities.publish(receiverCap, at: data.receiverPath)
Expand Down

0 comments on commit 5bb8db3

Please sign in to comment.