-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
114 - Adds destroy nfts transaction and associated burn command to cli (
#169) * added destroy nfts transaction and associated burn command to cli * Fixed variadic argument Co-authored-by: Peter Siemens <[email protected]> * Added fromBucketName argument Co-authored-by: Peter Siemens <[email protected]> * Updated description Co-authored-by: Peter Siemens <[email protected]> * Fixed comments, test description, command description, added burn command to list, added destroyNFTs transaction to generateEditionProject * Fixed argument * Fixed argument types, removed FreshmintError wrapping * Updated console log of burn command Co-authored-by: Loic Lesavre <[email protected]> Co-authored-by: Peter Siemens <[email protected]>
- Loading branch information
1 parent
8d820b2
commit 67b9239
Showing
8 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
cadence/nfts/common/transactions/destroy_nfts.template.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 {{{ imports.NonFungibleToken }}} | ||
import {{ contractName }} from {{{ contractAddress }}} | ||
|
||
/// This transaction withdraws multiple NFTs from the signer's collection and destroys them. | ||
/// | ||
transaction(ids: [UInt64], fromBucketName: String?) { | ||
|
||
/// A reference to the signer's {{ contractName }} collection. | ||
/// | ||
let collectionRef: &{{ contractName }}.Collection | ||
|
||
prepare(signer: AuthAccount) { | ||
|
||
// Derive the collection path from the bucket name | ||
let collectionName = {{ contractName }}.makeCollectionName(bucketName: fromBucketName) | ||
let collectionStoragePath = {{ contractName }}.getStoragePath(suffix: collectionName) | ||
|
||
self.collectionRef = signer.borrow<&{{ contractName }}.Collection>(from: collectionStoragePath) | ||
?? panic("failed to borrow collection") | ||
} | ||
|
||
execute { | ||
for id in ids { | ||
// withdraw the NFT from the signers's collection | ||
let nft <- self.collectionRef.withdraw(withdrawID: id) | ||
|
||
destroy nft | ||
} | ||
} | ||
} |
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
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
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
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,32 @@ | ||
import { Command } from 'commander'; | ||
import ora from 'ora'; | ||
import chalk from 'chalk'; | ||
|
||
import { FlowGateway, FlowNetwork } from '../flow'; | ||
import { loadConfig } from '../config'; | ||
|
||
export default new Command('burn') | ||
.argument('<ids...>', 'The IDs of NFTs to destroy (e.g. 3425 1235 4524 216661).') | ||
.description('burn (i.e. destroy) one or more NFTs') | ||
.option('-n, --network <network>', "Network to use. Either 'emulator', 'testnet' or 'mainnet'", 'emulator') | ||
.action(destroyNFTs); | ||
|
||
async function destroyNFTs(ids: string[], { network }: { network: FlowNetwork }) { | ||
const config = await loadConfig(); | ||
|
||
const flow = new FlowGateway(network, config.getContractAccount(network)); | ||
|
||
const spinner = ora(); | ||
|
||
console.log(chalk.gray('\n> flow transactions send ./cadence/transactions/destroy_nfts.cdc <...>\n')); | ||
|
||
spinner.start(`Destroying the NFTs...`); | ||
|
||
await flow.destroyNFTs(ids); | ||
|
||
if (ids.length == 1) { | ||
spinner.succeed(`1 NFT was destroyed.`); | ||
} else { | ||
spinner.succeed(`${ids.length} NFTs were destroyed.`); | ||
} | ||
} |
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
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
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