From 60cc1ed49dd3b7f4ea828d417d66970db4c45c4b Mon Sep 17 00:00:00 2001 From: danielailie Date: Fri, 15 Nov 2024 12:54:44 +0200 Subject: [PATCH 1/6] Add token Management controller --- src/index.ts | 1 + src/interface.ts | 4 +- src/testutils/mockNetworkProvider.ts | 12 +- src/tokenManagement/index.ts | 3 + src/tokenManagement/resources.ts | 113 ++++ .../tokenManagementController.ts | 495 ++++++++++++++++++ ...tokenManagementTransactionFactory.spec.ts} | 120 ++--- .../tokenManagementTransactionsFactory.ts | 366 ++++--------- ...anagementTransactionsOutcomeParser.spec.ts | 7 +- ...okenManagementTransactionsOutcomeParser.ts | 21 +- src/transactionWatcher.spec.ts | 2 +- src/transactionWatcher.ts | 7 +- src/transactionsFactories/index.ts | 1 - src/transactionsOutcomeParsers/index.ts | 2 +- 14 files changed, 808 insertions(+), 346 deletions(-) create mode 100644 src/tokenManagement/index.ts create mode 100644 src/tokenManagement/resources.ts create mode 100644 src/tokenManagement/tokenManagementController.ts rename src/{transactionsFactories/tokenManagementTransactionIntentsFactory.spec.ts => tokenManagement/tokenManagementTransactionFactory.spec.ts} (87%) rename src/{transactionsFactories => tokenManagement}/tokenManagementTransactionsFactory.ts (72%) rename src/{transactionsOutcomeParsers => tokenManagement}/tokenManagementTransactionsOutcomeParser.spec.ts (99%) rename src/{transactionsOutcomeParsers => tokenManagement}/tokenManagementTransactionsOutcomeParser.ts (97%) diff --git a/src/index.ts b/src/index.ts index 87ed40c94..7b89d4c2c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,6 +28,7 @@ export * from "./relayedTransactionV1Builder"; export * from "./relayedTransactionV2Builder"; export * from "./signableMessage"; export * from "./smartContractQueriesController"; +export * from "./tokenManagement"; export * from "./tokenOperations"; export * from "./tokens"; export * from "./transaction"; diff --git a/src/interface.ts b/src/interface.ts index 97c86a54f..5adf540bd 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -1,11 +1,11 @@ import BigNumber from "bignumber.js"; -import { ITransactionOnNetwork } from "./interfaceOfNetwork"; +import { TransactionOnNetwork } from "./networkProviders"; export interface ITransactionFetcher { /** * Fetches the state of a {@link Transaction}. */ - getTransaction(txHash: string): Promise; + getTransaction(txHash: string): Promise; } export interface IPlainTransactionObject { diff --git a/src/testutils/mockNetworkProvider.ts b/src/testutils/mockNetworkProvider.ts index 53276a27b..432f58243 100644 --- a/src/testutils/mockNetworkProvider.ts +++ b/src/testutils/mockNetworkProvider.ts @@ -20,14 +20,14 @@ export class MockNetworkProvider { static AddressOfBob = new Address("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"); static AddressOfCarol = new Address("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8"); - private readonly transactions: Map; + private readonly transactions: Map; private nextTransactionTimelinePoints: any[] = []; private readonly accounts: Map; private readonly queryContractResponders: QueryContractResponder[] = []; private readonly getTransactionResponders: GetTransactionResponder[] = []; constructor() { - this.transactions = new Map(); + this.transactions = new Map(); this.accounts = new Map(); this.accounts.set(MockNetworkProvider.AddressOfAlice.bech32(), { @@ -55,7 +55,7 @@ export class MockNetworkProvider { } } - mockPutTransaction(hash: TransactionHash, item: ITransactionOnNetwork) { + mockPutTransaction(hash: TransactionHash, item: TransactionOnNetwork) { item.isCompleted = false; this.transactions.set(hash.toString(), item); } @@ -134,7 +134,7 @@ export class MockNetworkProvider { return {}; } - async getTransaction(txHash: string): Promise { + async getTransaction(txHash: string): Promise { // At first, try to use a mock responder for (const responder of this.getTransactionResponders) { if (responder.matches(txHash)) { @@ -193,9 +193,9 @@ class QueryContractResponder { class GetTransactionResponder { readonly matches: (hash: string) => boolean; - readonly response: ITransactionOnNetwork; + readonly response: TransactionOnNetwork; - constructor(matches: (hash: string) => boolean, response: ITransactionOnNetwork) { + constructor(matches: (hash: string) => boolean, response: TransactionOnNetwork) { this.matches = matches; this.response = response; } diff --git a/src/tokenManagement/index.ts b/src/tokenManagement/index.ts new file mode 100644 index 000000000..c5b0ff043 --- /dev/null +++ b/src/tokenManagement/index.ts @@ -0,0 +1,3 @@ +export * from "./tokenManagementController"; +export * from "./tokenManagementTransactionsFactory"; +export * from "./tokenManagementTransactionsOutcomeParser"; diff --git a/src/tokenManagement/resources.ts b/src/tokenManagement/resources.ts new file mode 100644 index 000000000..32e4ce3c6 --- /dev/null +++ b/src/tokenManagement/resources.ts @@ -0,0 +1,113 @@ +import { IAddress } from "../interface"; + +export type IssueFungibleInput = IssueInput & { initialSupply: bigint; numDecimals: bigint }; + +export type IssueSemiFungibleInput = IssueNonFungibleInput; + +export type IssueNonFungibleInput = IssueInput & { canTransferNFTCreateRole: boolean }; + +export type IssueInput = { + tokenName: string; + tokenTicker: string; + canFreeze: boolean; + canWipe: boolean; + canPause: boolean; + canChangeOwner: boolean; + canUpgrade: boolean; + canAddSpecialRoles: boolean; +}; + +export type FungibleSpecialRoleInput = { + user: IAddress; + tokenIdentifier: string; + addRoleLocalMint: boolean; + addRoleLocalBurn: boolean; + addRoleESDTTransferRole: boolean; +}; +export type SemiFungibleSpecialRoleInput = SpecialRoleInput & { addRoleNFTAddQuantity: boolean }; + +export type SpecialRoleInput = { + user: IAddress; + tokenIdentifier: string; + addRoleNFTCreate: boolean; + addRoleNFTBurn: boolean; + addRoleNFTUpdateAttributes: boolean; + addRoleNFTAddURI: boolean; + addRoleESDTTransferRole: boolean; + addRoleESDTModifyCreator?: boolean; + addRoleNFTRecreate?: boolean; + addRoleESDTSetNewURI?: boolean; + addRoleESDTModifyRoyalties?: boolean; +}; + +export type MintInput = { + tokenIdentifier: string; + initialQuantity: bigint; + name: string; + royalties: number; + hash: string; + attributes: Uint8Array; + uris: string[]; +}; +export type ManagementInput = { user: IAddress; tokenIdentifier: string }; +export type LocalBurnInput = { tokenIdentifier: string; supplyToBurn: bigint }; +export type LocalMintInput = { tokenIdentifier: string; supplyToMint: bigint }; + +export type UpdateAttributesInput = UpdateInput & { attributes: Uint8Array }; + +export type UpdateQuantityInput = UpdateInput & { quantity: bigint }; + +export type UpdateInput = { tokenIdentifier: string; tokenNonce: bigint }; +export type BurnRoleGloballyInput = { tokenIdentifier: string }; + +export type RegisterRolesInput = { + tokenName: string; + tokenTicker: string; + tokenType: TokenType; + numDecimals: bigint; +}; + +export type RegisterMetaESDTInput = { + tokenName: string; + tokenTicker: string; + numDecimals: bigint; + canFreeze: boolean; + canWipe: boolean; + canPause: boolean; + canTransferNFTCreateRole: boolean; + canChangeOwner: boolean; + canUpgrade: boolean; + canAddSpecialRoles: boolean; +}; + +export type ModifyRoyaltiesInput = BaseInput & { newRoyalties: bigint }; + +export type BaseInput = { tokenIdentifier: string; tokenNonce: bigint }; + +export type SetNewUriInput = BaseInput & { newUris: string[] }; + +export type UpdateMetadataInput = { + tokenIdentifier: string; + tokenNonce: bigint; + newTokenName?: string; + newRoyalties?: bigint; + newHash?: string; + newAttributes?: Uint8Array; + newUris?: string[]; +}; + +export type RegisteringDynamicTokenInput = { tokenName: string; tokenTicker: string; tokenType: TokenType }; + +type TokenType = "NFT" | "SFT" | "META" | "FNG"; + +export type SpecialRoleOutput = { + userAddress: string; + tokenIdentifier: string; + roles: string[]; +}; + +export type MintNftOutput = { + tokenIdentifier: string; + nonce: bigint; + initialQuantity: bigint; +}; diff --git a/src/tokenManagement/tokenManagementController.ts b/src/tokenManagement/tokenManagementController.ts new file mode 100644 index 000000000..a552b895c --- /dev/null +++ b/src/tokenManagement/tokenManagementController.ts @@ -0,0 +1,495 @@ +import { IAccount } from "../accounts/interfaces"; +import { TransactionOnNetwork } from "../networkProviders"; +import { INetworkProvider } from "../networkProviders/interface"; +import { IESDTIssueOutcome } from "../tokenOperations"; +import { Transaction } from "../transaction"; +import { TransactionComputer } from "../transactionComputer"; +import { TransactionsFactoryConfig } from "../transactionsFactories"; +import { TokenManagementTransactionsOutcomeParser } from "../transactionsOutcomeParsers"; +import { TransactionWatcher } from "../transactionWatcher"; +import * as resources from "./resources"; +import { TokenManagementTransactionsFactory } from "./tokenManagementTransactionsFactory"; + +export class TokenManagementController { + private factory: TokenManagementTransactionsFactory; + private transactionAwaiter: TransactionWatcher; + private txComputer: TransactionComputer; + private parser: TokenManagementTransactionsOutcomeParser; + + constructor(options: { chainID: string; networkProvider: INetworkProvider }) { + this.factory = new TokenManagementTransactionsFactory({ + config: new TransactionsFactoryConfig({ chainID: options.chainID }), + }); + this.transactionAwaiter = new TransactionWatcher(options.networkProvider); + this.txComputer = new TransactionComputer(); + this.parser = new TokenManagementTransactionsOutcomeParser(); + } + + async createTransactionForIssuingFungible( + sender: IAccount, + nonce: bigint, + options: resources.IssueFungibleInput, + ): Promise { + const transaction = this.factory.createTransactionForIssuingFungible(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedIssueFungible(txHash: string): Promise { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseIssueFungible(transaction); + } + + parseIssueFungible(transactionOnNetwork: TransactionOnNetwork): IESDTIssueOutcome[] { + return this.parser.parseIssueFungible(transactionOnNetwork); + } + + async createTransactionForIssuingSemiFungible( + sender: IAccount, + nonce: bigint, + options: resources.IssueSemiFungibleInput, + ): Promise { + const transaction = this.factory.createTransactionForIssuingSemiFungible(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedIssueSemiFungible(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseIssueSemiFungible(transaction); + } + + parseIssueSemiFungible(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseIssueSemiFungible(transactionOnNetwork); + } + + async createTransactionForIssuingNonFungible( + sender: IAccount, + nonce: bigint, + options: resources.IssueNonFungibleInput, + ): Promise { + const transaction = this.factory.createTransactionForIssuingNonFungible(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedIssueNonFungible(txHash: string): Promise { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseIssueNonFungible(transaction); + } + + parseIssueNonFungible(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseIssueNonFungible(transactionOnNetwork); + } + + async createTransactionForRegisteringMetaEsdt( + sender: IAccount, + nonce: bigint, + options: resources.RegisterMetaESDTInput, + ): Promise { + const transaction = this.factory.createTransactionForRegisteringMetaESDT(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedRegisterMetaEsdt(txHash: string): Promise { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseRegisterMetaEsdt(transaction); + } + + parseRegisterMetaEsdt(transactionOnNetwork: TransactionOnNetwork): IESDTIssueOutcome[] { + return this.parser.parseRegisterMetaEsdt(transactionOnNetwork); + } + + async createTransactionForRegisteringAndSettingRoles( + sender: IAccount, + nonce: bigint, + options: resources.RegisterRolesInput, + ): Promise { + const transaction = this.factory.createTransactionForRegisteringAndSettingRoles(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedRegisterAndSettingRoles(txHash: string): Promise { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseRegisterAndSetAllRoles(transaction); + } + + parseRegisterAndSetAllRoles(transactionOnNetwork: TransactionOnNetwork): IESDTIssueOutcome[] { + return this.parser.parseRegisterMetaEsdt(transactionOnNetwork); + } + + async createTransactionForSetBurnRoleGlobally( + sender: IAccount, + nonce: bigint, + options: resources.BurnRoleGloballyInput, + ): Promise { + const transaction = this.factory.createTransactionForSettingBurnRoleGlobally(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedSetBurnRoleGlobally(txHash: string): Promise { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseSetBurnRoleGlobally(transaction); + } + + parseSetBurnRoleGlobally(transactionOnNetwork: TransactionOnNetwork): void { + return this.parser.parseSetBurnRoleGlobally(transactionOnNetwork); + } + + async createTransactionForUnsettingBurnRoleGlobally( + sender: IAccount, + nonce: bigint, + options: resources.BurnRoleGloballyInput, + ): Promise { + const transaction = this.factory.createTransactionForUnsettingBurnRoleGlobally(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedUnsetBurnRoleGlobally(txHash: string): Promise { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseUnsetBurnRoleGlobally(transaction); + } + + parseUnsetBurnRoleGlobally(transactionOnNetwork: TransactionOnNetwork): void { + return this.parser.parseUnsetBurnRoleGlobally(transactionOnNetwork); + } + + async createTransactionForSettingSpecialRoleOnFungibleToken( + sender: IAccount, + nonce: bigint, + options: resources.FungibleSpecialRoleInput, + ): Promise { + const transaction = this.factory.createTransactionForSettingSpecialRoleOnFungibleToken(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedSetSpecialRoleOnFungibleToken(txHash: string): Promise { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseSetSpecialRoleOnFungible(transaction); + } + + parseSetSpecialRoleOnFungible(transactionOnNetwork: TransactionOnNetwork): resources.SpecialRoleOutput[] { + return this.parser.parseSetSpecialRole(transactionOnNetwork); + } + + async createTransactionForSettingSpecialRoleOnSemiFungibleToken( + sender: IAccount, + nonce: bigint, + options: resources.SemiFungibleSpecialRoleInput, + ): Promise { + const transaction = this.factory.createTransactionForSettingSpecialRoleOnSemiFungibleToken( + sender.address, + options, + ); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedSetSpecialRoleOnSemiFungibleToken(txHash: string): Promise { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseSetSpecialRoleOnSemiFungibleToken(transaction); + } + + parseSetSpecialRoleOnSemiFungibleToken(transactionOnNetwork: TransactionOnNetwork): resources.SpecialRoleOutput[] { + return this.parser.parseSetSpecialRole(transactionOnNetwork); + } + + async createTransactionForSettingSpecialRoleOnNonFungibleToken( + sender: IAccount, + nonce: bigint, + options: resources.SpecialRoleInput, + ): Promise { + const transaction = this.factory.createTransactionForSettingSpecialRoleOnNonFungibleToken( + sender.address, + options, + ); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedSetSpecialRoleOnNonFungibleToken(txHash: string): Promise { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseSetSpecialRoleOnNonFungibleToken(transaction); + } + + parseSetSpecialRoleOnNonFungibleToken(transactionOnNetwork: TransactionOnNetwork): resources.SpecialRoleOutput[] { + return this.parser.parseSetSpecialRole(transactionOnNetwork); + } + + async createTransactionForCreatingNft( + sender: IAccount, + nonce: bigint, + options: resources.MintInput, + ): Promise { + const transaction = this.factory.createTransactionForCreatingNFT(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedCreateNft(txHash: string): Promise { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseNftCreate(transaction); + } + + parseNftCreate(transactionOnNetwork: TransactionOnNetwork): resources.MintNftOutput[] { + return this.parser.parseNftCreate(transactionOnNetwork); + } + + async createTransactionForPausing( + sender: IAccount, + nonce: bigint, + options: resources.ManagementInput, + ): Promise { + const transaction = this.factory.createTransactionForPausing(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedPause(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parsePause(transaction); + } + + parsePause(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parsePause(transactionOnNetwork); + } + + async createTransactionForUnpausing( + sender: IAccount, + nonce: bigint, + options: resources.ManagementInput, + ): Promise { + const transaction = this.factory.createTransactionForUnpausing(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedUnpause(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseUnpause(transaction); + } + + parseUnpause(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseUnpause(transactionOnNetwork); + } + + async createTransactionForFreezing( + sender: IAccount, + nonce: bigint, + options: resources.ManagementInput, + ): Promise { + const transaction = this.factory.createTransactionForFreezing(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedFreeze(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseFreeze(transaction); + } + + parseFreeze(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseFreeze(transactionOnNetwork); + } + + async createTransactionForUnFreezing( + sender: IAccount, + nonce: bigint, + options: resources.ManagementInput, + ): Promise { + const transaction = this.factory.createTransactionForUnfreezing(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedUnfreeze(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseUnfreeze(transaction); + } + + parseUnfreeze(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseUnfreeze(transactionOnNetwork); + } + + async createTransactionForWiping( + sender: IAccount, + nonce: bigint, + options: resources.ManagementInput, + ): Promise { + const transaction = this.factory.createTransactionForWiping(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedWipe(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parser.parseWipe(transaction); + } + + parseWipe(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseWipe(transactionOnNetwork); + } + + async createTransactionForLocaMinting( + sender: IAccount, + nonce: bigint, + options: resources.LocalMintInput, + ): Promise { + const transaction = this.factory.createTransactionForLocalMint(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedLocalMint(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseLocalMint(transaction); + } + + parseLocalMint(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseLocalMint(transactionOnNetwork); + } + + async createTransactionForLocalBurning( + sender: IAccount, + nonce: bigint, + options: resources.LocalBurnInput, + ): Promise { + const transaction = this.factory.createTransactionForLocalBurning(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompleteLocalBurn(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseLocalBurn(transaction); + } + + parseLocalBurn(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseLocalBurn(transactionOnNetwork); + } + + async createTransactionForUpdatingAttributes( + sender: IAccount, + nonce: bigint, + options: resources.UpdateAttributesInput, + ): Promise { + const transaction = this.factory.createTransactionForUpdatingAttributes(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedUpdateAttributes(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseUpdateAttributes(transaction); + } + + parseUpdateAttributes(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseUpdateAttributes(transactionOnNetwork); + } + + async createTransactionForAddingQuantity( + sender: IAccount, + nonce: bigint, + options: resources.UpdateQuantityInput, + ): Promise { + const transaction = this.factory.createTransactionForAddingQuantity(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedAddQuantity(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseAddQuantity(transaction); + } + + parseAddQuantity(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseAddQuantity(transactionOnNetwork); + } + + async createTransactionForBurningQuantity( + sender: IAccount, + nonce: bigint, + options: resources.UpdateQuantityInput, + ): Promise { + const transaction = this.factory.createTransactionForBurningQuantity(sender.address, options); + + transaction.nonce = nonce; + transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); + + return transaction; + } + + async awaitCompletedBurnQuantity(txHash: string): Promise<{ tokenIdentifier: string }[]> { + const transaction = await this.transactionAwaiter.awaitCompleted(txHash); + return this.parseBurnQuantity(transaction); + } + + parseBurnQuantity(transactionOnNetwork: TransactionOnNetwork): { tokenIdentifier: string }[] { + return this.parser.parseBurnQuantity(transactionOnNetwork); + } +} diff --git a/src/transactionsFactories/tokenManagementTransactionIntentsFactory.spec.ts b/src/tokenManagement/tokenManagementTransactionFactory.spec.ts similarity index 87% rename from src/transactionsFactories/tokenManagementTransactionIntentsFactory.spec.ts rename to src/tokenManagement/tokenManagementTransactionFactory.spec.ts index f5c489903..2c2d432cc 100644 --- a/src/transactionsFactories/tokenManagementTransactionIntentsFactory.spec.ts +++ b/src/tokenManagement/tokenManagementTransactionFactory.spec.ts @@ -2,8 +2,8 @@ import { assert } from "chai"; import { Address } from "../address"; import { ESDT_CONTRACT_ADDRESS_HEX } from "../constants"; import { loadTestWallets, TestWallet } from "../testutils"; +import { TransactionsFactoryConfig } from "../transactionsFactories"; import { TokenManagementTransactionsFactory } from "./tokenManagementTransactionsFactory"; -import { TransactionsFactoryConfig } from "./transactionsFactoryConfig"; describe("test token management transactions factory", () => { let frank: TestWallet, grace: TestWallet; @@ -17,8 +17,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for registering and setting roles", () => { - const transaction = tokenManagementFactory.createTransactionForRegisteringAndSettingRoles({ - sender: frank.address, + const transaction = tokenManagementFactory.createTransactionForRegisteringAndSettingRoles(frank.address, { tokenName: "TEST", tokenTicker: "TEST", tokenType: "FNG", @@ -33,8 +32,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for issuing fungible token", () => { - const transaction = tokenManagementFactory.createTransactionForIssuingFungible({ - sender: frank.address, + const transaction = tokenManagementFactory.createTransactionForIssuingFungible(frank.address, { tokenName: "FRANK", tokenTicker: "FRANK", initialSupply: 100n, @@ -59,8 +57,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for issuing semi-fungible token", () => { - const transaction = tokenManagementFactory.createTransactionForIssuingSemiFungible({ - sender: frank.address, + const transaction = tokenManagementFactory.createTransactionForIssuingSemiFungible(frank.address, { tokenName: "FRANK", tokenTicker: "FRANK", canFreeze: true, @@ -84,8 +81,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for issuing non-fungible token", () => { - const transaction = tokenManagementFactory.createTransactionForIssuingNonFungible({ - sender: frank.address, + const transaction = tokenManagementFactory.createTransactionForIssuingNonFungible(frank.address, { tokenName: "FRANK", tokenTicker: "FRANK", canFreeze: true, @@ -109,8 +105,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for registering metaEsdt", () => { - const transaction = tokenManagementFactory.createTransactionForRegisteringMetaESDT({ - sender: frank.address, + const transaction = tokenManagementFactory.createTransactionForRegisteringMetaESDT(frank.address, { tokenName: "FRANK", tokenTicker: "FRANK", numDecimals: 10n, @@ -135,14 +130,16 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for setting special role on fungible token", () => { - const transaction = tokenManagementFactory.createTransactionForSettingSpecialRoleOnFungibleToken({ - sender: frank.address, - user: grace.address, - tokenIdentifier: "FRANK-11ce3e", - addRoleLocalMint: true, - addRoleLocalBurn: false, - addRoleESDTTransferRole: false, - }); + const transaction = tokenManagementFactory.createTransactionForSettingSpecialRoleOnFungibleToken( + frank.address, + { + user: grace.address, + tokenIdentifier: "FRANK-11ce3e", + addRoleLocalMint: true, + addRoleLocalBurn: false, + addRoleESDTTransferRole: false, + }, + ); assert.deepEqual( transaction.data, @@ -156,14 +153,16 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for setting all special roles on fungible token", () => { - const transaction = tokenManagementFactory.createTransactionForSettingSpecialRoleOnFungibleToken({ - sender: frank.address, - user: grace.address, - tokenIdentifier: "FRANK-11ce3e", - addRoleLocalMint: true, - addRoleLocalBurn: true, - addRoleESDTTransferRole: true, - }); + const transaction = tokenManagementFactory.createTransactionForSettingSpecialRoleOnFungibleToken( + frank.address, + { + user: grace.address, + tokenIdentifier: "FRANK-11ce3e", + addRoleLocalMint: true, + addRoleLocalBurn: true, + addRoleESDTTransferRole: true, + }, + ); assert.deepEqual( transaction.data, @@ -177,18 +176,20 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for setting special role on non-fungible token", () => { - const transaction = tokenManagementFactory.createTransactionForSettingSpecialRoleOnNonFungibleToken({ - sender: frank.address, - user: grace.address, - tokenIdentifier: "FRANK-11ce3e", - addRoleNFTCreate: true, - addRoleNFTBurn: false, - addRoleNFTUpdateAttributes: true, - addRoleNFTAddURI: true, - addRoleESDTTransferRole: false, - addRoleESDTModifyCreator: true, - addRoleNFTRecreate: true, - }); + const transaction = tokenManagementFactory.createTransactionForSettingSpecialRoleOnNonFungibleToken( + frank.address, + { + user: grace.address, + tokenIdentifier: "FRANK-11ce3e", + addRoleNFTCreate: true, + addRoleNFTBurn: false, + addRoleNFTUpdateAttributes: true, + addRoleNFTAddURI: true, + addRoleESDTTransferRole: false, + addRoleESDTModifyCreator: true, + addRoleNFTRecreate: true, + }, + ); assert.deepEqual( transaction.data, @@ -202,8 +203,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for creating nft", () => { - const transaction = tokenManagementFactory.createTransactionForCreatingNFT({ - sender: grace.address, + const transaction = tokenManagementFactory.createTransactionForCreatingNFT(grace.address, { tokenIdentifier: "FRANK-aa9e8d", initialQuantity: 1n, name: "test", @@ -223,8 +223,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for modifying royalties", () => { - const transaction = tokenManagementFactory.createTransactionForModifyingRoyalties({ - sender: grace.address, + const transaction = tokenManagementFactory.createTransactionForModifyingRoyalties(grace.address, { tokenIdentifier: "TEST-123456", tokenNonce: 1n, newRoyalties: 1234n, @@ -238,8 +237,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for setting new URIs", () => { - const transaction = tokenManagementFactory.createTransactionForSettingNewUris({ - sender: grace.address, + const transaction = tokenManagementFactory.createTransactionForSettingNewUris(grace.address, { tokenIdentifier: "TEST-123456", tokenNonce: 1n, newUris: ["firstURI", "secondURI"], @@ -256,8 +254,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for modifying creator", () => { - const transaction = tokenManagementFactory.createTransactionForModifyingCreator({ - sender: grace.address, + const transaction = tokenManagementFactory.createTransactionForModifyingCreator(grace.address, { tokenIdentifier: "TEST-123456", tokenNonce: 1n, }); @@ -270,8 +267,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for updating metadata", () => { - const transaction = tokenManagementFactory.createTransactionForUpdatingMetadata({ - sender: grace.address, + const transaction = tokenManagementFactory.createTransactionForUpdatingMetadata(grace.address, { tokenIdentifier: "TEST-123456", tokenNonce: 1n, newTokenName: "Test", @@ -294,8 +290,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for recreating metadata", () => { - const transaction = tokenManagementFactory.createTransactionForMetadataRecreate({ - sender: grace.address, + const transaction = tokenManagementFactory.createTransactionForMetadataRecreate(grace.address, { tokenIdentifier: "TEST-123456", tokenNonce: 1n, newTokenName: "Test", @@ -318,8 +313,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for changing to dynamic", () => { - const transaction = tokenManagementFactory.createTransactionForChangingTokenToDynamic({ - sender: grace.address, + const transaction = tokenManagementFactory.createTransactionForChangingTokenToDynamic(grace.address, { tokenIdentifier: "TEST-123456", }); @@ -331,8 +325,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for updating token id", () => { - const transaction = tokenManagementFactory.createTransactionForUpdatingTokenId({ - sender: grace.address, + const transaction = tokenManagementFactory.createTransactionForUpdatingTokenId(grace.address, { tokenIdentifier: "TEST-123456", }); @@ -344,8 +337,7 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for registering dynamic", () => { - const transaction = tokenManagementFactory.createTransactionForRegisteringDynamicToken({ - sender: grace.address, + const transaction = tokenManagementFactory.createTransactionForRegisteringDynamicToken(grace.address, { tokenName: "Test", tokenTicker: "TEST-123456", tokenType: "FNG", @@ -359,12 +351,14 @@ describe("test token management transactions factory", () => { }); it("should create 'Transaction' for registering and setting all roles", () => { - const transaction = tokenManagementFactory.createTransactionForRegisteringDynamicAndSettingRoles({ - sender: grace.address, - tokenName: "Test", - tokenTicker: "TEST-123456", - tokenType: "FNG", - }); + const transaction = tokenManagementFactory.createTransactionForRegisteringDynamicAndSettingRoles( + grace.address, + { + tokenName: "Test", + tokenTicker: "TEST-123456", + tokenType: "FNG", + }, + ); assert.deepEqual( transaction.data, diff --git a/src/transactionsFactories/tokenManagementTransactionsFactory.ts b/src/tokenManagement/tokenManagementTransactionsFactory.ts similarity index 72% rename from src/transactionsFactories/tokenManagementTransactionsFactory.ts rename to src/tokenManagement/tokenManagementTransactionsFactory.ts index eff2cdf69..2388a2df1 100644 --- a/src/transactionsFactories/tokenManagementTransactionsFactory.ts +++ b/src/tokenManagement/tokenManagementTransactionsFactory.ts @@ -5,7 +5,8 @@ import { ErrBadUsage } from "../errors"; import { IAddress } from "../interface"; import { Logger } from "../logger"; import { Transaction } from "../transaction"; -import { TransactionBuilder } from "./transactionBuilder"; +import { TransactionBuilder } from "../transactionsFactories/transactionBuilder"; +import * as resources from "./resources"; interface IConfig { chainID: string; @@ -36,8 +37,6 @@ interface IConfig { issueCost: bigint; } -type TokenType = "NFT" | "SFT" | "META" | "FNG"; - /** * Use this class to create token management transactions like issuing ESDTs, creating NFTs, setting roles, etc. */ @@ -56,19 +55,7 @@ export class TokenManagementTransactionsFactory { this.esdtContractAddress = Address.fromHex(ESDT_CONTRACT_ADDRESS_HEX, this.config.addressHrp); } - createTransactionForIssuingFungible(options: { - sender: IAddress; - tokenName: string; - tokenTicker: string; - initialSupply: bigint; - numDecimals: bigint; - canFreeze: boolean; - canWipe: boolean; - canPause: boolean; - canChangeOwner: boolean; - canUpgrade: boolean; - canAddSpecialRoles: boolean; - }): Transaction { + createTransactionForIssuingFungible(sender: IAddress, options: resources.IssueFungibleInput): Transaction { this.notifyAboutUnsettingBurnRoleGlobally(); const args = [ @@ -94,7 +81,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitIssue, @@ -103,18 +90,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForIssuingSemiFungible(options: { - sender: IAddress; - tokenName: string; - tokenTicker: string; - canFreeze: boolean; - canWipe: boolean; - canPause: boolean; - canTransferNFTCreateRole: boolean; - canChangeOwner: boolean; - canUpgrade: boolean; - canAddSpecialRoles: boolean; - }): Transaction { + createTransactionForIssuingSemiFungible(sender: IAddress, options: resources.IssueSemiFungibleInput): Transaction { this.notifyAboutUnsettingBurnRoleGlobally(); const args = [ @@ -140,7 +116,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitIssue, @@ -149,18 +125,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForIssuingNonFungible(options: { - sender: IAddress; - tokenName: string; - tokenTicker: string; - canFreeze: boolean; - canWipe: boolean; - canPause: boolean; - canTransferNFTCreateRole: boolean; - canChangeOwner: boolean; - canUpgrade: boolean; - canAddSpecialRoles: boolean; - }): Transaction { + createTransactionForIssuingNonFungible(sender: IAddress, options: resources.IssueNonFungibleInput): Transaction { this.notifyAboutUnsettingBurnRoleGlobally(); const args = [ @@ -186,7 +151,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitIssue, @@ -195,19 +160,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForRegisteringMetaESDT(options: { - sender: IAddress; - tokenName: string; - tokenTicker: string; - numDecimals: bigint; - canFreeze: boolean; - canWipe: boolean; - canPause: boolean; - canTransferNFTCreateRole: boolean; - canChangeOwner: boolean; - canUpgrade: boolean; - canAddSpecialRoles: boolean; - }): Transaction { + createTransactionForRegisteringMetaESDT(sender: IAddress, options: resources.RegisterMetaESDTInput): Transaction { this.notifyAboutUnsettingBurnRoleGlobally(); const args = [ @@ -234,7 +187,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitIssue, @@ -243,13 +196,10 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForRegisteringAndSettingRoles(options: { - sender: IAddress; - tokenName: string; - tokenTicker: string; - tokenType: TokenType; - numDecimals: bigint; - }): Transaction { + createTransactionForRegisteringAndSettingRoles( + sender: IAddress, + options: resources.RegisterRolesInput, + ): Transaction { this.notifyAboutUnsettingBurnRoleGlobally(); const dataParts = [ @@ -264,7 +214,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitIssue, @@ -273,7 +223,10 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForSettingBurnRoleGlobally(options: { sender: IAddress; tokenIdentifier: string }): Transaction { + createTransactionForSettingBurnRoleGlobally( + sender: IAddress, + options: resources.BurnRoleGloballyInput, + ): Transaction { const dataParts = [ "setBurnRoleGlobally", ...this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)]), @@ -281,7 +234,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitToggleBurnRoleGlobally, @@ -289,7 +242,10 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForUnsettingBurnRoleGlobally(options: { sender: IAddress; tokenIdentifier: string }): Transaction { + createTransactionForUnsettingBurnRoleGlobally( + sender: IAddress, + options: resources.BurnRoleGloballyInput, + ): Transaction { const dataParts = [ "unsetBurnRoleGlobally", ...this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)]), @@ -297,7 +253,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitToggleBurnRoleGlobally, @@ -305,14 +261,10 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForSettingSpecialRoleOnFungibleToken(options: { - sender: IAddress; - user: IAddress; - tokenIdentifier: string; - addRoleLocalMint: boolean; - addRoleLocalBurn: boolean; - addRoleESDTTransferRole: boolean; - }): Transaction { + createTransactionForSettingSpecialRoleOnFungibleToken( + sender: IAddress, + options: resources.FungibleSpecialRoleInput, + ): Transaction { const args = [new StringValue(options.tokenIdentifier), new AddressValue(options.user)]; options.addRoleLocalMint ? args.push(new StringValue("ESDTRoleLocalMint")) : 0; @@ -323,7 +275,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitSetSpecialRole, @@ -331,16 +283,10 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForSettingSpecialRoleOnSemiFungibleToken(options: { - sender: IAddress; - user: IAddress; - tokenIdentifier: string; - addRoleNFTCreate: boolean; - addRoleNFTBurn: boolean; - addRoleNFTAddQuantity: boolean; - addRoleESDTTransferRole: boolean; - addRoleESDTModifyCreator?: boolean; - }): Transaction { + createTransactionForSettingSpecialRoleOnSemiFungibleToken( + sender: IAddress, + options: resources.SemiFungibleSpecialRoleInput, + ): Transaction { const args = [new StringValue(options.tokenIdentifier), new AddressValue(options.user)]; options.addRoleNFTCreate ? args.push(new StringValue("ESDTRoleNFTCreate")) : 0; @@ -353,7 +299,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitSetSpecialRole, @@ -361,32 +307,17 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForSettingSpecialRoleOnMetaESDT(options: { - sender: IAddress; - user: IAddress; - tokenIdentifier: string; - addRoleNFTCreate: boolean; - addRoleNFTBurn: boolean; - addRoleNFTAddQuantity: boolean; - addRoleESDTTransferRole: boolean; - }): Transaction { - return this.createTransactionForSettingSpecialRoleOnSemiFungibleToken(options); - } - - createTransactionForSettingSpecialRoleOnNonFungibleToken(options: { - sender: IAddress; - user: IAddress; - tokenIdentifier: string; - addRoleNFTCreate: boolean; - addRoleNFTBurn: boolean; - addRoleNFTUpdateAttributes: boolean; - addRoleNFTAddURI: boolean; - addRoleESDTTransferRole: boolean; - addRoleESDTModifyCreator?: boolean; - addRoleNFTRecreate?: boolean; - addRoleESDTSetNewURI?: boolean; - addRoleESDTModifyRoyalties?: boolean; - }): Transaction { + createTransactionForSettingSpecialRoleOnMetaESDT( + sender: IAddress, + options: resources.SemiFungibleSpecialRoleInput, + ): Transaction { + return this.createTransactionForSettingSpecialRoleOnSemiFungibleToken(sender, options); + } + + createTransactionForSettingSpecialRoleOnNonFungibleToken( + sender: IAddress, + options: resources.SpecialRoleInput, + ): Transaction { const args = [new StringValue(options.tokenIdentifier), new AddressValue(options.user)]; options.addRoleNFTCreate ? args.push(new StringValue("ESDTRoleNFTCreate")) : 0; @@ -403,7 +334,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitSetSpecialRole, @@ -411,16 +342,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForCreatingNFT(options: { - sender: IAddress; - tokenIdentifier: string; - initialQuantity: bigint; - name: string; - royalties: number; - hash: string; - attributes: Uint8Array; - uris: string[]; - }): Transaction { + createTransactionForCreatingNFT(sender: IAddress, options: resources.MintInput): Transaction { const dataParts = [ "ESDTNFTCreate", ...this.argSerializer.valuesToStrings([ @@ -440,28 +362,28 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitEsdtNftCreate + storageGasLimit, addDataMovementGas: true, }).build(); } - createTransactionForPausing(options: { sender: IAddress; tokenIdentifier: string }): Transaction { + createTransactionForPausing(sender: IAddress, options: resources.ManagementInput): Transaction { const dataParts = ["pause", ...this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)])]; return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitPausing, addDataMovementGas: true, }).build(); } - createTransactionForUnpausing(options: { sender: IAddress; tokenIdentifier: string }): Transaction { + createTransactionForUnpausing(sender: IAddress, options: resources.ManagementInput): Transaction { const dataParts = [ "unPause", ...this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)]), @@ -469,15 +391,15 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitPausing, addDataMovementGas: true, }).build(); } - createTransactionForFreezing(options: { sender: IAddress; user: IAddress; tokenIdentifier: string }): Transaction { + createTransactionForFreezing(sender: IAddress, options: resources.ManagementInput): Transaction { const dataParts = [ "freeze", ...this.argSerializer.valuesToStrings([ @@ -488,19 +410,15 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitFreezing, addDataMovementGas: true, }).build(); } - createTransactionForUnfreezing(options: { - sender: IAddress; - user: IAddress; - tokenIdentifier: string; - }): Transaction { + createTransactionForUnfreezing(sender: IAddress, options: resources.ManagementInput): Transaction { const dataParts = [ "UnFreeze", ...this.argSerializer.valuesToStrings([ @@ -511,15 +429,15 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitFreezing, addDataMovementGas: true, }).build(); } - createTransactionForWiping(options: { sender: IAddress; user: IAddress; tokenIdentifier: string }): Transaction { + createTransactionForWiping(sender: IAddress, options: resources.ManagementInput): Transaction { const dataParts = [ "wipe", ...this.argSerializer.valuesToStrings([ @@ -530,19 +448,15 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitWiping, addDataMovementGas: true, }).build(); } - createTransactionForLocalMint(options: { - sender: IAddress; - tokenIdentifier: string; - supplyToMint: bigint; - }): Transaction { + createTransactionForLocalMint(sender: IAddress, options: resources.LocalMintInput): Transaction { const dataParts = [ "ESDTLocalMint", ...this.argSerializer.valuesToStrings([ @@ -553,19 +467,15 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitEsdtLocalMint, addDataMovementGas: true, }).build(); } - createTransactionForLocalBurning(options: { - sender: IAddress; - tokenIdentifier: string; - supplyToBurn: bigint; - }): Transaction { + createTransactionForLocalBurning(sender: IAddress, options: resources.LocalBurnInput): Transaction { const dataParts = [ "ESDTLocalBurn", ...this.argSerializer.valuesToStrings([ @@ -576,20 +486,15 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitEsdtLocalBurn, addDataMovementGas: true, }).build(); } - createTransactionForUpdatingAttributes(options: { - sender: IAddress; - tokenIdentifier: string; - tokenNonce: bigint; - attributes: Uint8Array; - }): Transaction { + createTransactionForUpdatingAttributes(sender: IAddress, options: resources.UpdateAttributesInput): Transaction { const dataParts = [ "ESDTNFTUpdateAttributes", ...this.argSerializer.valuesToStrings([ @@ -601,70 +506,55 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitEsdtNftUpdateAttributes, addDataMovementGas: true, }).build(); } - createTransactionForAddingQuantity(options: { - sender: IAddress; - tokenIdentifier: string; - tokenNonce: bigint; - quantityToAdd: bigint; - }): Transaction { + createTransactionForAddingQuantity(sender: IAddress, options: resources.UpdateQuantityInput): Transaction { const dataParts = [ "ESDTNFTAddQuantity", ...this.argSerializer.valuesToStrings([ new StringValue(options.tokenIdentifier), new BigUIntValue(options.tokenNonce), - new BigUIntValue(options.quantityToAdd), + new BigUIntValue(options.quantity), ]), ]; return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitEsdtNftAddQuantity, addDataMovementGas: true, }).build(); } - createTransactionForBurningQuantity(options: { - sender: IAddress; - tokenIdentifier: string; - tokenNonce: bigint; - quantityToBurn: bigint; - }): Transaction { + createTransactionForBurningQuantity(sender: IAddress, options: resources.UpdateQuantityInput): Transaction { const dataParts = [ "ESDTNFTBurn", ...this.argSerializer.valuesToStrings([ new StringValue(options.tokenIdentifier), new BigUIntValue(options.tokenNonce), - new BigUIntValue(options.quantityToBurn), + new BigUIntValue(options.quantity), ]), ]; return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitEsdtNftBurn, addDataMovementGas: true, }).build(); } - createTransactionForModifyingRoyalties(options: { - sender: IAddress; - tokenIdentifier: string; - tokenNonce: bigint; - newRoyalties: bigint; - }): Transaction { + createTransactionForModifyingRoyalties(sender: IAddress, options: resources.ModifyRoyaltiesInput): Transaction { const dataParts = [ "ESDTModifyRoyalties", ...this.argSerializer.valuesToStrings([ @@ -676,20 +566,15 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitEsdtModifyRoyalties, addDataMovementGas: true, }).build(); } - createTransactionForSettingNewUris(options: { - sender: IAddress; - tokenIdentifier: string; - tokenNonce: bigint; - newUris: string[]; - }): Transaction { + createTransactionForSettingNewUris(sender: IAddress, options: resources.SetNewUriInput): Transaction { if (!options.newUris.length) { throw new ErrBadUsage("No URIs provided"); } @@ -705,19 +590,15 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitSetNewUris, addDataMovementGas: true, }).build(); } - createTransactionForModifyingCreator(options: { - sender: IAddress; - tokenIdentifier: string; - tokenNonce: bigint; - }): Transaction { + createTransactionForModifyingCreator(sender: IAddress, options: resources.BaseInput): Transaction { const dataParts = [ "ESDTModifyCreator", ...this.argSerializer.valuesToStrings([ @@ -728,24 +609,15 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitEsdtModifyCreator, addDataMovementGas: true, }).build(); } - createTransactionForUpdatingMetadata(options: { - sender: IAddress; - tokenIdentifier: string; - tokenNonce: bigint; - newTokenName?: string; - newRoyalties?: bigint; - newHash?: string; - newAttributes?: Uint8Array; - newUris?: string[]; - }): Transaction { + createTransactionForUpdatingMetadata(sender: IAddress, options: resources.UpdateMetadataInput): Transaction { const dataParts = [ "ESDTMetaDataUpdate", ...this.argSerializer.valuesToStrings([ @@ -761,24 +633,15 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitEsdtMetadataUpdate, addDataMovementGas: true, }).build(); } - createTransactionForMetadataRecreate(options: { - sender: IAddress; - tokenIdentifier: string; - tokenNonce: bigint; - newTokenName: string; - newRoyalties: bigint; - newHash: string; - newAttributes: Uint8Array; - newUris: string[]; - }): Transaction { + createTransactionForMetadataRecreate(sender: IAddress, options: resources.UpdateMetadataInput): Transaction { const dataParts = [ "ESDTMetaDataRecreate", ...this.argSerializer.valuesToStrings([ @@ -794,15 +657,18 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, - receiver: options.sender, + sender: sender, + receiver: sender, dataParts: dataParts, gasLimit: this.config.gasLimitNftMetadataRecreate, addDataMovementGas: true, }).build(); } - createTransactionForChangingTokenToDynamic(options: { sender: IAddress; tokenIdentifier: string }): Transaction { + createTransactionForChangingTokenToDynamic( + sender: IAddress, + options: resources.BurnRoleGloballyInput, + ): Transaction { const dataParts = [ "changeToDynamic", ...this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)]), @@ -810,7 +676,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitNftChangeToDynamic, @@ -818,7 +684,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForUpdatingTokenId(options: { sender: IAddress; tokenIdentifier: string }): Transaction { + createTransactionForUpdatingTokenId(sender: IAddress, options: resources.BurnRoleGloballyInput): Transaction { const dataParts = [ "updateTokenID", ...this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)]), @@ -826,7 +692,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitUpdateTokenId, @@ -834,12 +700,10 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForRegisteringDynamicToken(options: { - sender: IAddress; - tokenName: string; - tokenTicker: string; - tokenType: TokenType; - }): Transaction { + createTransactionForRegisteringDynamicToken( + sender: IAddress, + options: resources.RegisteringDynamicTokenInput, + ): Transaction { const dataParts = [ "registerDynamic", ...this.argSerializer.valuesToStrings([ @@ -851,7 +715,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitRegisterDynamic, @@ -860,12 +724,10 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForRegisteringDynamicAndSettingRoles(options: { - sender: IAddress; - tokenName: string; - tokenTicker: string; - tokenType: TokenType; - }): Transaction { + createTransactionForRegisteringDynamicAndSettingRoles( + sender: IAddress, + options: resources.RegisteringDynamicTokenInput, + ): Transaction { const dataParts = [ "registerAndSetAllRolesDynamic", ...this.argSerializer.valuesToStrings([ @@ -877,7 +739,7 @@ export class TokenManagementTransactionsFactory { return new TransactionBuilder({ config: this.config, - sender: options.sender, + sender: sender, receiver: this.esdtContractAddress, dataParts: dataParts, gasLimit: this.config.gasLimitRegisterDynamic, diff --git a/src/transactionsOutcomeParsers/tokenManagementTransactionsOutcomeParser.spec.ts b/src/tokenManagement/tokenManagementTransactionsOutcomeParser.spec.ts similarity index 99% rename from src/transactionsOutcomeParsers/tokenManagementTransactionsOutcomeParser.spec.ts rename to src/tokenManagement/tokenManagementTransactionsOutcomeParser.spec.ts index 136fe6d5b..4bb1a9a37 100644 --- a/src/transactionsOutcomeParsers/tokenManagementTransactionsOutcomeParser.spec.ts +++ b/src/tokenManagement/tokenManagementTransactionsOutcomeParser.spec.ts @@ -1,7 +1,12 @@ import { assert } from "chai"; import { ErrParseTransactionOutcome } from "../errors"; import { b64TopicsToBytes } from "../testutils"; -import { SmartContractResult, TransactionEvent, TransactionLogs, TransactionOutcome } from "./resources"; +import { + SmartContractResult, + TransactionEvent, + TransactionLogs, + TransactionOutcome, +} from "../transactionsOutcomeParsers/resources"; import { TokenManagementTransactionsOutcomeParser } from "./tokenManagementTransactionsOutcomeParser"; describe("test token management transactions outcome parser", () => { diff --git a/src/transactionsOutcomeParsers/tokenManagementTransactionsOutcomeParser.ts b/src/tokenManagement/tokenManagementTransactionsOutcomeParser.ts similarity index 97% rename from src/transactionsOutcomeParsers/tokenManagementTransactionsOutcomeParser.ts rename to src/tokenManagement/tokenManagementTransactionsOutcomeParser.ts index 43345ddc2..1c6696f51 100644 --- a/src/transactionsOutcomeParsers/tokenManagementTransactionsOutcomeParser.ts +++ b/src/tokenManagement/tokenManagementTransactionsOutcomeParser.ts @@ -3,7 +3,8 @@ import { Address } from "../address"; import { TransactionsConverter } from "../converters/transactionsConverter"; import { ErrParseTransactionOutcome } from "../errors"; import { ITransactionOnNetwork } from "../interfaceOfNetwork"; -import { TransactionEvent, TransactionOutcome, findEventsByIdentifier } from "./resources"; +import { TransactionEvent, TransactionOutcome, findEventsByIdentifier } from "../transactionsOutcomeParsers/resources"; +import { MintNftOutput, SpecialRoleOutput } from "./resources"; export class TokenManagementTransactionsOutcomeParser { constructor() {} @@ -79,11 +80,7 @@ export class TokenManagementTransactionsOutcomeParser { this.ensureNoError(transaction.logs.events); } - parseSetSpecialRole(transaction: TransactionOutcome | ITransactionOnNetwork): { - userAddress: string; - tokenIdentifier: string; - roles: string[]; - }[] { + parseSetSpecialRole(transaction: TransactionOutcome | ITransactionOnNetwork): SpecialRoleOutput[] { transaction = this.ensureTransactionOutcome(transaction); this.ensureNoError(transaction.logs.events); @@ -92,11 +89,7 @@ export class TokenManagementTransactionsOutcomeParser { return events.map((event) => this.getOutputForSetSpecialRoleEvent(event)); } - private getOutputForSetSpecialRoleEvent(event: TransactionEvent): { - userAddress: string; - tokenIdentifier: string; - roles: string[]; - } { + private getOutputForSetSpecialRoleEvent(event: TransactionEvent): SpecialRoleOutput { const userAddress = event.address; const tokenIdentifier = this.extractTokenIdentifier(event); const encodedRoles = event.topics.slice(3); @@ -105,11 +98,7 @@ export class TokenManagementTransactionsOutcomeParser { return { userAddress: userAddress, tokenIdentifier: tokenIdentifier, roles: roles }; } - parseNftCreate(transaction: TransactionOutcome | ITransactionOnNetwork): { - tokenIdentifier: string; - nonce: bigint; - initialQuantity: bigint; - }[] { + parseNftCreate(transaction: TransactionOutcome | ITransactionOnNetwork): MintNftOutput[] { transaction = this.ensureTransactionOutcome(transaction); this.ensureNoError(transaction.logs.events); diff --git a/src/transactionWatcher.spec.ts b/src/transactionWatcher.spec.ts index dd223af6d..018313440 100644 --- a/src/transactionWatcher.spec.ts +++ b/src/transactionWatcher.spec.ts @@ -1,5 +1,5 @@ -import { TransactionOnNetwork, TransactionStatus } from "./networkProviders"; import { assert } from "chai"; +import { TransactionOnNetwork, TransactionStatus } from "./networkProviders"; import { MarkCompleted, MockNetworkProvider, Wait } from "./testutils"; import { TransactionHash } from "./transaction"; import { TransactionWatcher } from "./transactionWatcher"; diff --git a/src/transactionWatcher.ts b/src/transactionWatcher.ts index ae077b38b..741548769 100644 --- a/src/transactionWatcher.ts +++ b/src/transactionWatcher.ts @@ -9,6 +9,7 @@ import { import { ITransactionFetcher } from "./interface"; import { ITransactionEvent, ITransactionOnNetwork, ITransactionStatus } from "./interfaceOfNetwork"; import { Logger } from "./logger"; +import { TransactionOnNetwork } from "./networkProviders"; export type PredicateIsAwaitedStatus = (status: ITransactionStatus) => boolean; @@ -77,7 +78,7 @@ export class TransactionWatcher { * Waits until the transaction is completely processed. * @param txHash The hex-encoded transaction hash */ - public async awaitCompleted(transactionOrTxHash: ITransaction | string): Promise { + public async awaitCompleted(transactionOrTxHash: ITransaction | string): Promise { const isCompleted = (transactionOnNetwork: ITransactionOnNetwork) => { if (transactionOnNetwork.isCompleted === undefined) { throw new ErrIsCompletedFieldIsMissingOnTransaction(); @@ -91,7 +92,7 @@ export class TransactionWatcher { }; const errorProvider = () => new ErrExpectedTransactionStatusNotReached(); - return this.awaitConditionally(isCompleted, doFetch, errorProvider); + return this.awaitConditionally(isCompleted, doFetch, errorProvider); } public async awaitAllEvents( @@ -236,7 +237,7 @@ class TransactionFetcherWithTracing implements ITransactionFetcher { this.fetcher = fetcher; } - async getTransaction(txHash: string): Promise { + async getTransaction(txHash: string): Promise { Logger.debug(`transactionWatcher, getTransaction(${txHash})`); return await this.fetcher.getTransaction(txHash); } diff --git a/src/transactionsFactories/index.ts b/src/transactionsFactories/index.ts index 23d727598..505dff76b 100644 --- a/src/transactionsFactories/index.ts +++ b/src/transactionsFactories/index.ts @@ -1,3 +1,2 @@ -export * from "./tokenManagementTransactionsFactory"; export * from "./transactionsFactoryConfig"; export * from "./transferTransactionsFactory"; diff --git a/src/transactionsOutcomeParsers/index.ts b/src/transactionsOutcomeParsers/index.ts index 6511796e7..e3f3bafff 100644 --- a/src/transactionsOutcomeParsers/index.ts +++ b/src/transactionsOutcomeParsers/index.ts @@ -1,4 +1,4 @@ export * from "../smartContracts/smartContractTransactionsOutcomeParser"; +export * from "../tokenManagement/tokenManagementTransactionsOutcomeParser"; export * from "./resources"; -export * from "./tokenManagementTransactionsOutcomeParser"; export * from "./transactionEventsParser"; From 1d206ec52f9fd2e801d67676400e01cdce3fb186 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 18 Nov 2024 10:57:09 +0200 Subject: [PATCH 2/6] Update types --- src/testutils/networkProviders.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/testutils/networkProviders.ts b/src/testutils/networkProviders.ts index 18c8f1b25..6e3bebaf1 100644 --- a/src/testutils/networkProviders.ts +++ b/src/testutils/networkProviders.ts @@ -1,13 +1,7 @@ import { Query } from "../abi"; import { IAddress } from "../interface"; -import { - IAccountOnNetwork, - IContractQueryResponse, - INetworkConfig, - ITransactionOnNetwork, - ITransactionStatus, -} from "../interfaceOfNetwork"; -import { ApiNetworkProvider, ProxyNetworkProvider } from "../networkProviders"; +import { IAccountOnNetwork, IContractQueryResponse, INetworkConfig, ITransactionStatus } from "../interfaceOfNetwork"; +import { ApiNetworkProvider, ProxyNetworkProvider, TransactionOnNetwork } from "../networkProviders"; import { Transaction } from "../transaction"; @@ -39,7 +33,7 @@ export function createMainnetProvider(): INetworkProvider { export interface INetworkProvider { getNetworkConfig(): Promise; getAccount(address: IAddress): Promise; - getTransaction(txHash: string, withProcessStatus?: boolean): Promise; + getTransaction(txHash: string, withProcessStatus?: boolean): Promise; getTransactionStatus(txHash: string): Promise; sendTransaction(tx: Transaction): Promise; simulateTransaction(tx: Transaction): Promise; From cf1d4787db2923a3c3b0670c0d9e7f4dc046be83 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 18 Nov 2024 12:08:59 +0200 Subject: [PATCH 3/6] Update input namings --- src/testutils/networkProviders.ts | 2 +- src/tokenManagement/resources.ts | 6 +++++- .../tokenManagementTransactionsFactory.ts | 14 +++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/testutils/networkProviders.ts b/src/testutils/networkProviders.ts index 6e3bebaf1..7e5f49ea0 100644 --- a/src/testutils/networkProviders.ts +++ b/src/testutils/networkProviders.ts @@ -33,7 +33,7 @@ export function createMainnetProvider(): INetworkProvider { export interface INetworkProvider { getNetworkConfig(): Promise; getAccount(address: IAddress): Promise; - getTransaction(txHash: string, withProcessStatus?: boolean): Promise; + getTransaction(txHash: string): Promise; getTransactionStatus(txHash: string): Promise; sendTransaction(tx: Transaction): Promise; simulateTransaction(tx: Transaction): Promise; diff --git a/src/tokenManagement/resources.ts b/src/tokenManagement/resources.ts index 32e4ce3c6..a08a4ec0a 100644 --- a/src/tokenManagement/resources.ts +++ b/src/tokenManagement/resources.ts @@ -50,6 +50,7 @@ export type MintInput = { uris: string[]; }; export type ManagementInput = { user: IAddress; tokenIdentifier: string }; +export type PausingInput = { tokenIdentifier: string }; export type LocalBurnInput = { tokenIdentifier: string; supplyToBurn: bigint }; export type LocalMintInput = { tokenIdentifier: string; supplyToMint: bigint }; @@ -59,6 +60,8 @@ export type UpdateQuantityInput = UpdateInput & { quantity: bigint }; export type UpdateInput = { tokenIdentifier: string; tokenNonce: bigint }; export type BurnRoleGloballyInput = { tokenIdentifier: string }; +export type UpdateTokenIDInput = { tokenIdentifier: string }; +export type ChangeTokenToDynamicInput = { tokenIdentifier: string }; export type RegisterRolesInput = { tokenName: string; @@ -81,12 +84,13 @@ export type RegisterMetaESDTInput = { }; export type ModifyRoyaltiesInput = BaseInput & { newRoyalties: bigint }; +export type ModifyCreatorInput = BaseInput; export type BaseInput = { tokenIdentifier: string; tokenNonce: bigint }; export type SetNewUriInput = BaseInput & { newUris: string[] }; -export type UpdateMetadataInput = { +export type ManageMetadataInput = { tokenIdentifier: string; tokenNonce: bigint; newTokenName?: string; diff --git a/src/tokenManagement/tokenManagementTransactionsFactory.ts b/src/tokenManagement/tokenManagementTransactionsFactory.ts index 2388a2df1..261912046 100644 --- a/src/tokenManagement/tokenManagementTransactionsFactory.ts +++ b/src/tokenManagement/tokenManagementTransactionsFactory.ts @@ -370,7 +370,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForPausing(sender: IAddress, options: resources.ManagementInput): Transaction { + createTransactionForPausing(sender: IAddress, options: resources.PausingInput): Transaction { const dataParts = ["pause", ...this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)])]; return new TransactionBuilder({ @@ -383,7 +383,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForUnpausing(sender: IAddress, options: resources.ManagementInput): Transaction { + createTransactionForUnpausing(sender: IAddress, options: resources.PausingInput): Transaction { const dataParts = [ "unPause", ...this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)]), @@ -598,7 +598,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForModifyingCreator(sender: IAddress, options: resources.BaseInput): Transaction { + createTransactionForModifyingCreator(sender: IAddress, options: resources.ModifyCreatorInput): Transaction { const dataParts = [ "ESDTModifyCreator", ...this.argSerializer.valuesToStrings([ @@ -617,7 +617,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForUpdatingMetadata(sender: IAddress, options: resources.UpdateMetadataInput): Transaction { + createTransactionForUpdatingMetadata(sender: IAddress, options: resources.ManageMetadataInput): Transaction { const dataParts = [ "ESDTMetaDataUpdate", ...this.argSerializer.valuesToStrings([ @@ -641,7 +641,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForMetadataRecreate(sender: IAddress, options: resources.UpdateMetadataInput): Transaction { + createTransactionForMetadataRecreate(sender: IAddress, options: resources.ManageMetadataInput): Transaction { const dataParts = [ "ESDTMetaDataRecreate", ...this.argSerializer.valuesToStrings([ @@ -667,7 +667,7 @@ export class TokenManagementTransactionsFactory { createTransactionForChangingTokenToDynamic( sender: IAddress, - options: resources.BurnRoleGloballyInput, + options: resources.ChangeTokenToDynamicInput, ): Transaction { const dataParts = [ "changeToDynamic", @@ -684,7 +684,7 @@ export class TokenManagementTransactionsFactory { }).build(); } - createTransactionForUpdatingTokenId(sender: IAddress, options: resources.BurnRoleGloballyInput): Transaction { + createTransactionForUpdatingTokenId(sender: IAddress, options: resources.UpdateTokenIDInput): Transaction { const dataParts = [ "updateTokenID", ...this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)]), From 4ab1934b5d2f42d198eb42ef5acfddff5fb7919f Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 18 Nov 2024 12:15:37 +0200 Subject: [PATCH 4/6] Fix test --- src/testutils/contractController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testutils/contractController.ts b/src/testutils/contractController.ts index a053e4431..b8643fcf3 100644 --- a/src/testutils/contractController.ts +++ b/src/testutils/contractController.ts @@ -15,7 +15,7 @@ export class ContractController { this.provider = provider; this.transactionCompletionAwaiter = new TransactionWatcher({ getTransaction: async (hash: string) => { - return await provider.getTransaction(hash, true); + return await provider.getTransaction(hash); }, }); } From 50a09e18ae97cddf6dd430ebf4e90ced4a5b171c Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 18 Nov 2024 12:27:18 +0200 Subject: [PATCH 5/6] Fix integration tests --- src/abi/interaction.local.net.spec.ts | 6 +++--- src/abi/smartContract.local.net.spec.ts | 2 +- src/abi/smartContractResults.local.net.spec.ts | 2 +- src/transaction.local.net.spec.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/abi/interaction.local.net.spec.ts b/src/abi/interaction.local.net.spec.ts index 2a2487688..68d119c79 100644 --- a/src/abi/interaction.local.net.spec.ts +++ b/src/abi/interaction.local.net.spec.ts @@ -118,7 +118,7 @@ describe("test smart contract interactor", function () { const transactionCompletionAwaiter = new TransactionWatcher({ getTransaction: async (hash: string) => { - return await provider.getTransaction(hash, true); + return await provider.getTransaction(hash); }, }); @@ -406,7 +406,7 @@ describe("test smart contract interactor", function () { const transactionCompletionAwaiter = new TransactionWatcher({ getTransaction: async (hash: string) => { - return await provider.getTransaction(hash, true); + return await provider.getTransaction(hash); }, }); @@ -600,7 +600,7 @@ describe("test smart contract interactor", function () { const transactionCompletionAwaiter = new TransactionWatcher({ getTransaction: async (hash: string) => { - return await provider.getTransaction(hash, true); + return await provider.getTransaction(hash); }, }); diff --git a/src/abi/smartContract.local.net.spec.ts b/src/abi/smartContract.local.net.spec.ts index 818cc0349..1bde9a611 100644 --- a/src/abi/smartContract.local.net.spec.ts +++ b/src/abi/smartContract.local.net.spec.ts @@ -35,7 +35,7 @@ describe("test on local testnet", function () { watcher = new TransactionWatcher({ getTransaction: async (hash: string) => { - return await provider.getTransaction(hash, true); + return await provider.getTransaction(hash); }, }); }); diff --git a/src/abi/smartContractResults.local.net.spec.ts b/src/abi/smartContractResults.local.net.spec.ts index 850bd9a35..5f74c6809 100644 --- a/src/abi/smartContractResults.local.net.spec.ts +++ b/src/abi/smartContractResults.local.net.spec.ts @@ -21,7 +21,7 @@ describe("fetch transactions from local testnet", function () { ({ alice } = await loadTestWallets()); watcher = new TransactionWatcher({ getTransaction: async (hash: string) => { - return await provider.getTransaction(hash, true); + return await provider.getTransaction(hash); }, }); }); diff --git a/src/transaction.local.net.spec.ts b/src/transaction.local.net.spec.ts index 15082da7d..ed8dd0ab7 100644 --- a/src/transaction.local.net.spec.ts +++ b/src/transaction.local.net.spec.ts @@ -22,7 +22,7 @@ describe("test transaction", function () { return new TransactionWatcher( { getTransaction: async (hash: string) => { - return await provider.getTransaction(hash, true); + return await provider.getTransaction(hash); }, }, { timeoutMilliseconds: 100000 }, From 266fdb3eca8b6fddf7f86f96fa3b877871dacb15 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 18 Nov 2024 12:38:37 +0200 Subject: [PATCH 6/6] Update naming to match factory --- src/tokenManagement/tokenManagementController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tokenManagement/tokenManagementController.ts b/src/tokenManagement/tokenManagementController.ts index a552b895c..9a36baf01 100644 --- a/src/tokenManagement/tokenManagementController.ts +++ b/src/tokenManagement/tokenManagementController.ts @@ -276,7 +276,7 @@ export class TokenManagementController { async createTransactionForPausing( sender: IAccount, nonce: bigint, - options: resources.ManagementInput, + options: resources.PausingInput, ): Promise { const transaction = this.factory.createTransactionForPausing(sender.address, options); @@ -298,7 +298,7 @@ export class TokenManagementController { async createTransactionForUnpausing( sender: IAccount, nonce: bigint, - options: resources.ManagementInput, + options: resources.PausingInput, ): Promise { const transaction = this.factory.createTransactionForUnpausing(sender.address, options);