From 5722b9e1c105f03fc29084ff10afc9ada24ca1d7 Mon Sep 17 00:00:00 2001 From: nikhils9 Date: Mon, 11 Sep 2023 18:01:20 +0530 Subject: [PATCH] Add script to remove ref tokens from store Add MetaDatum type --- off-chain/burn-nft.ts | 0 off-chain/common/types.ts | 10 +++++++ off-chain/nft-metadata.json | 2 +- off-chain/remove-nft.ts | 53 +++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 off-chain/burn-nft.ts create mode 100644 off-chain/remove-nft.ts diff --git a/off-chain/burn-nft.ts b/off-chain/burn-nft.ts new file mode 100644 index 0000000..e69de29 diff --git a/off-chain/common/types.ts b/off-chain/common/types.ts index 0da6dd1..c49472e 100644 --- a/off-chain/common/types.ts +++ b/off-chain/common/types.ts @@ -1,8 +1,18 @@ import { Data, Script } from "lucid"; +/// Type to store an applied validator and its properties export type AppliedValidator = { validator: Script; policyId: string; lockAddress: string; params: Data[]; }; + +/// Type of datum for tokens adhering to CIP-68 +export const MetaDatum = Data.Object({ + metadata: Data.Map(Data.Any(), Data.Any()), + version: Data.Integer(), + extra: Data.Bytes(), +}); + +export type MetaDatum = Data.Static; diff --git a/off-chain/nft-metadata.json b/off-chain/nft-metadata.json index e23963f..1691235 100644 --- a/off-chain/nft-metadata.json +++ b/off-chain/nft-metadata.json @@ -18,7 +18,7 @@ } ], "image": "ipfs://Qmda82xY8k6BnFZLWAA5TuhwtoWFzmEpaPGugo7DhJzHxZ", - "name": "BlockOwls Telly", + "name": "BlockOwls Telly2", "power": 37, "rarity": "Common" } \ No newline at end of file diff --git a/off-chain/remove-nft.ts b/off-chain/remove-nft.ts new file mode 100644 index 0000000..b4fa0a4 --- /dev/null +++ b/off-chain/remove-nft.ts @@ -0,0 +1,53 @@ +// deno-lint-ignore-file no-explicit-any +import { Constr, Data, fromHex, fromText, toHex, toUnit, UTxO } from "lucid"; +import { createLucidInstance, getCredential } from "./utils/lucid/utils.ts"; +import { crypto } from "crypto"; +import { + APPLIED_VALIDATOR_PATH, + NON_FUNGIBLE_TOKEN_LABEL, + REFERENCE_TOKEN_LABEL, +} from "./common/constants.ts"; +import { AppliedValidator, MetaDatum } from "./common/types.ts"; + +const lucid = await createLucidInstance(); + +const storeValidator: AppliedValidator = JSON.parse( + await Deno.readTextFile( + APPLIED_VALIDATOR_PATH + "reference_store.store.json", + ), +); +const scriptUtxos = await lucid.utxosAt(storeValidator.lockAddress); + +lucid.selectWalletFromPrivateKey(await getCredential("issuer.sk")); + +const userAddr = await getCredential("user.addr"); +const rdmr = Data.to(new Constr(1, [])); +const utxo = scriptUtxos[0]; + +const tx = lucid + .newTx() + .collectFrom(scriptUtxos, rdmr) + .payToAddressWithData(userAddr, { inline: utxo.datum! }, utxo.assets); + +// scriptUtxos.forEach((utxo) => { +// if (utxo.datum) { +// tx.payToAddressWithData(userAddr, { inline: utxo.datum }, utxo.assets); +// // console.log(utxo.datum); +// // console.log(Data.from(utxo.datum)); +// } else console.log("UTxO without datum found" + utxo); +// }); + +const completedTx = await tx.addSigner(await lucid.wallet.address()) + .attachSpendingValidator(storeValidator.validator) + .complete(); + +const signedTx = await completedTx.sign().complete(); +const txHash = await signedTx.submit(); +await lucid.awaitTx(txHash); + +console.log( + `Successfully removed all assets from +storeAddress: ${storeValidator.lockAddress}, +to userAddress: ${userAddr}, +txHash: ${txHash}`, +);