From 62eaddf3b73dc34cdc33168c60a1016e256fe2ef Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 12 Dec 2023 16:51:11 +0200 Subject: [PATCH 1/7] remove old canMint and canBurn arguments --- package-lock.json | 4 +- package.json | 2 +- .../tokenOperationsFactory.test.net.spec.ts | 84 +++++------ src/tokenOperations/tokenOperationsFactory.ts | 135 +++++++----------- 4 files changed, 93 insertions(+), 132 deletions(-) diff --git a/package-lock.json b/package-lock.json index aab51dfc..60c2f972 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@multiversx/sdk-core", - "version": "12.15.0", + "version": "12.16.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@multiversx/sdk-core", - "version": "12.15.0", + "version": "12.16.0", "license": "MIT", "dependencies": { "@multiversx/sdk-transaction-decoder": "1.0.2", diff --git a/package.json b/package.json index 9a87d744..714d2c80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-core", - "version": "12.15.0", + "version": "12.16.0", "description": "MultiversX SDK for JavaScript and TypeScript", "main": "out/index.js", "types": "out/index.d.js", diff --git a/src/tokenOperations/tokenOperationsFactory.test.net.spec.ts b/src/tokenOperations/tokenOperationsFactory.test.net.spec.ts index f434fd7f..e9a4b968 100644 --- a/src/tokenOperations/tokenOperationsFactory.test.net.spec.ts +++ b/src/tokenOperations/tokenOperationsFactory.test.net.spec.ts @@ -43,7 +43,7 @@ describe("test factory on testnet", function () { tokenTicker: "TEST", tokenType: "FNG", numDecimals: 2, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -64,7 +64,7 @@ describe("test factory on testnet", function () { tokenTicker: "TEST", tokenType: "NFT", numDecimals: 0, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -87,7 +87,7 @@ describe("test factory on testnet", function () { tokenTicker: "TEST", tokenType: "SFT", numDecimals: 0, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -109,7 +109,7 @@ describe("test factory on testnet", function () { tokenTicker: "TEST", tokenType: "META", numDecimals: 2, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -135,12 +135,10 @@ describe("test factory on testnet", function () { canFreeze: true, canWipe: true, canPause: true, - canMint: true, - canBurn: true, canChangeOwner: true, canUpgrade: true, canAddSpecialRoles: true, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -152,7 +150,7 @@ describe("test factory on testnet", function () { const tx2 = factory.unsetBurnRoleGlobally({ manager: frank.address, tokenIdentifier: tx1Outcome.tokenIdentifier, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx2OnNetwork = await processTransaction(frank, tx2, "tx2"); @@ -162,7 +160,7 @@ describe("test factory on testnet", function () { const tx3 = factory.setBurnRoleGlobally({ manager: frank.address, tokenIdentifier: tx1Outcome.tokenIdentifier, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx3OnNetwork = await processTransaction(frank, tx3, "tx3"); @@ -184,12 +182,10 @@ describe("test factory on testnet", function () { canFreeze: true, canWipe: true, canPause: true, - canMint: true, - canBurn: true, canChangeOwner: true, canUpgrade: true, canAddSpecialRoles: true, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -204,7 +200,7 @@ describe("test factory on testnet", function () { tokenIdentifier: tx1Outcome.tokenIdentifier, addRoleLocalMint: true, addRoleLocalBurn: true, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx2OnNetwork = await processTransaction(frank, tx2, "tx2"); @@ -218,7 +214,7 @@ describe("test factory on testnet", function () { user: grace.address, tokenIdentifier: tokenIdentifier, supplyToMint: 200, - transactionNonce: grace.account.nonce + transactionNonce: grace.account.nonce, }); const tx3OnNetwork = await processTransaction(grace, tx3, "tx3"); @@ -231,7 +227,7 @@ describe("test factory on testnet", function () { user: grace.address, tokenIdentifier: tokenIdentifier, supplyToBurn: 50, - transactionNonce: grace.account.nonce + transactionNonce: grace.account.nonce, }); const tx4OnNetwork = await processTransaction(grace, tx4, "tx4"); @@ -253,12 +249,10 @@ describe("test factory on testnet", function () { canFreeze: true, canWipe: true, canPause: true, - canMint: true, - canBurn: true, canChangeOwner: true, canUpgrade: true, canAddSpecialRoles: true, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -270,7 +264,7 @@ describe("test factory on testnet", function () { const tx2 = factory.pause({ manager: frank.address, tokenIdentifier: tokenIdentifier, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx2OnNetwork = await processTransaction(frank, tx2, "tx2"); @@ -280,7 +274,7 @@ describe("test factory on testnet", function () { const tx3 = factory.unpause({ manager: frank.address, tokenIdentifier: tokenIdentifier, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx3OnNetwork = await processTransaction(frank, tx3, "tx3"); @@ -292,7 +286,7 @@ describe("test factory on testnet", function () { sender: frank.account.address, receiver: grace.account.address, chainID: network.ChainID, - nonce: frank.account.nonce + nonce: frank.account.nonce, }); const _tx4OnNetwork = await processTransaction(frank, tx4, "tx4"); @@ -312,12 +306,10 @@ describe("test factory on testnet", function () { canFreeze: true, canWipe: true, canPause: true, - canMint: true, - canBurn: true, canChangeOwner: true, canUpgrade: true, canAddSpecialRoles: true, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -331,7 +323,7 @@ describe("test factory on testnet", function () { sender: frank.account.address, receiver: grace.account.address, chainID: network.ChainID, - nonce: frank.account.nonce + nonce: frank.account.nonce, }); const _tx2OnNetwork = await processTransaction(frank, tx2, "tx2"); @@ -341,7 +333,7 @@ describe("test factory on testnet", function () { manager: frank.address, user: grace.address, tokenIdentifier: tokenIdentifier, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx3OnNetwork = await processTransaction(frank, tx3, "tx3"); @@ -356,7 +348,7 @@ describe("test factory on testnet", function () { manager: frank.address, user: grace.address, tokenIdentifier: tokenIdentifier, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx4OnNetwork = await processTransaction(frank, tx4, "tx4"); @@ -381,12 +373,10 @@ describe("test factory on testnet", function () { canFreeze: true, canWipe: true, canPause: true, - canMint: true, - canBurn: true, canChangeOwner: true, canUpgrade: true, canAddSpecialRoles: true, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -400,7 +390,7 @@ describe("test factory on testnet", function () { sender: frank.account.address, receiver: grace.account.address, chainID: network.ChainID, - nonce: frank.account.nonce + nonce: frank.account.nonce, }); const _tx2OnNetwork = await processTransaction(frank, tx2, "tx2"); @@ -410,7 +400,7 @@ describe("test factory on testnet", function () { manager: frank.address, user: grace.address, tokenIdentifier: tokenIdentifier, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx3OnNetwork = await processTransaction(frank, tx3, "tx3"); @@ -425,7 +415,7 @@ describe("test factory on testnet", function () { manager: frank.address, user: grace.address, tokenIdentifier: tokenIdentifier, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx4OnNetwork = await processTransaction(frank, tx4, "tx4"); @@ -453,7 +443,7 @@ describe("test factory on testnet", function () { canChangeOwner: true, canUpgrade: true, canAddSpecialRoles: true, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -471,7 +461,7 @@ describe("test factory on testnet", function () { addRoleNFTUpdateAttributes: true, addRoleNFTAddURI: true, addRoleESDTTransferRole: false, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx2OnNetwork = await processTransaction(frank, tx2, "tx2"); @@ -491,7 +481,7 @@ describe("test factory on testnet", function () { hash: "abba", attributes: Buffer.from("test"), uris: ["a", "b"], - transactionNonce: grace.account.nonce + transactionNonce: grace.account.nonce, }); const txCreateOnNetwork = await processTransaction(grace, txCreate, "txCreate"); @@ -536,7 +526,7 @@ describe("test factory on testnet", function () { canChangeOwner: true, canUpgrade: true, canAddSpecialRoles: true, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -553,7 +543,7 @@ describe("test factory on testnet", function () { addRoleNFTBurn: false, addRoleNFTAddQuantity: true, addRoleESDTTransferRole: false, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx2OnNetwork = await processTransaction(frank, tx2, "tx2"); @@ -572,7 +562,7 @@ describe("test factory on testnet", function () { hash: "abba", attributes: Buffer.from("test"), uris: ["a", "b"], - transactionNonce: grace.account.nonce + transactionNonce: grace.account.nonce, }); const txCreateOnNetwork = await processTransaction(grace, txCreate, "txCreate"); @@ -588,7 +578,7 @@ describe("test factory on testnet", function () { tokenIdentifier: txCreateOutcome.tokenIdentifier, tokenNonce: txCreateOutcome.nonce, quantityToAdd: "3", - transactionNonce: grace.account.nonce + transactionNonce: grace.account.nonce, }); const txAddQuantityOnNetwork = await processTransaction(grace, txAddQuantity, "txAddQuantity"); @@ -604,7 +594,7 @@ describe("test factory on testnet", function () { tokenIdentifier: txCreateOutcome.tokenIdentifier, tokenNonce: txCreateOutcome.nonce, quantityToBurn: "2", - transactionNonce: grace.account.nonce + transactionNonce: grace.account.nonce, }); const txBurnQuantityOnNetwork = await processTransaction(grace, txBurnQuantity, "txBurnQuantity"); @@ -634,7 +624,7 @@ describe("test factory on testnet", function () { canChangeOwner: true, canUpgrade: true, canAddSpecialRoles: true, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx1OnNetwork = await processTransaction(frank, tx1, "tx1"); @@ -651,7 +641,7 @@ describe("test factory on testnet", function () { addRoleNFTBurn: false, addRoleNFTAddQuantity: true, addRoleESDTTransferRole: false, - transactionNonce: frank.account.nonce + transactionNonce: frank.account.nonce, }); const tx2OnNetwork = await processTransaction(frank, tx2, "tx2"); @@ -670,7 +660,7 @@ describe("test factory on testnet", function () { hash: "abba", attributes: Buffer.from("test"), uris: ["a", "b"], - transactionNonce: grace.account.nonce + transactionNonce: grace.account.nonce, }); const txOnNetwork = await processTransaction(grace, tx, "tx"); @@ -682,7 +672,11 @@ describe("test factory on testnet", function () { } }); - async function processTransaction(wallet: TestWallet, transaction: Transaction, tag: string): Promise { + async function processTransaction( + wallet: TestWallet, + transaction: Transaction, + tag: string + ): Promise { wallet.account.incrementNonce(); await wallet.signer.sign(transaction); await provider.sendTransaction(transaction); diff --git a/src/tokenOperations/tokenOperationsFactory.ts b/src/tokenOperations/tokenOperationsFactory.ts index b41e8559..3dc02010 100644 --- a/src/tokenOperations/tokenOperationsFactory.ts +++ b/src/tokenOperations/tokenOperationsFactory.ts @@ -48,16 +48,6 @@ interface IIssueFungibleArgs extends IBaseArgs { canChangeOwner: boolean; canUpgrade: boolean; canAddSpecialRoles: boolean; - - /** - * @deprecated (not used anymore) - */ - canMint?: boolean; - - /** - * @deprecated (not used anymore) - */ - canBurn?: boolean; } interface IIssueSemiFungibleArgs extends IBaseArgs { @@ -73,8 +63,7 @@ interface IIssueSemiFungibleArgs extends IBaseArgs { canAddSpecialRoles: boolean; } -interface IIssueNonFungibleArgs extends IIssueSemiFungibleArgs { -} +interface IIssueNonFungibleArgs extends IIssueSemiFungibleArgs {} interface IRegisterMetaESDT extends IIssueSemiFungibleArgs { numDecimals: number; @@ -156,14 +145,14 @@ interface ILocalMintArgs extends IBaseArgs { manager: IAddress; user: IAddress; tokenIdentifier: string; - supplyToMint: BigNumber.Value + supplyToMint: BigNumber.Value; } interface ILocalBurnArgs extends IBaseArgs { manager: IAddress; user: IAddress; tokenIdentifier: string; - supplyToBurn: BigNumber.Value + supplyToBurn: BigNumber.Value; } interface IUpdateAttributesArgs extends IBaseArgs { @@ -177,14 +166,14 @@ interface IAddQuantityArgs extends IBaseArgs { manager: IAddress; tokenIdentifier: string; tokenNonce: BigNumber.Value; - quantityToAdd: BigNumber.Value + quantityToAdd: BigNumber.Value; } interface IBurnQuantityArgs extends IBaseArgs { manager: IAddress; tokenIdentifier: string; tokenNonce: BigNumber.Value; - quantityToBurn: BigNumber.Value + quantityToBurn: BigNumber.Value; } export class TokenOperationsFactory { @@ -221,7 +210,7 @@ export class TokenOperationsFactory { gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitIssue, - dataParts: parts + dataParts: parts, }); } @@ -258,7 +247,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitIssue, - dataParts: parts + dataParts: parts, }); } @@ -286,7 +275,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitIssue, - dataParts: parts + dataParts: parts, }); } @@ -315,7 +304,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitIssue, - dataParts: parts + dataParts: parts, }); } @@ -327,7 +316,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG utf8ToHex(args.tokenName), utf8ToHex(args.tokenTicker), utf8ToHex(args.tokenType), - bigIntToHex(args.numDecimals) + bigIntToHex(args.numDecimals), ]; return this.createTransaction({ @@ -338,15 +327,12 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitIssue, - dataParts: parts + dataParts: parts, }); } setBurnRoleGlobally(args: IToggleBurnRoleGloballyArgs): Transaction { - const parts = [ - "setBurnRoleGlobally", - utf8ToHex(args.tokenIdentifier) - ]; + const parts = ["setBurnRoleGlobally", utf8ToHex(args.tokenIdentifier)]; return this.createTransaction({ sender: args.manager, @@ -355,15 +341,12 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitToggleBurnRoleGlobally, - dataParts: parts + dataParts: parts, }); } unsetBurnRoleGlobally(args: IToggleBurnRoleGloballyArgs): Transaction { - const parts = [ - "unsetBurnRoleGlobally", - utf8ToHex(args.tokenIdentifier) - ]; + const parts = ["unsetBurnRoleGlobally", utf8ToHex(args.tokenIdentifier)]; return this.createTransaction({ sender: args.manager, @@ -372,7 +355,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitToggleBurnRoleGlobally, - dataParts: parts + dataParts: parts, }); } @@ -392,7 +375,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitSetSpecialRole, - dataParts: parts + dataParts: parts, }); } @@ -414,7 +397,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitSetSpecialRole, - dataParts: parts + dataParts: parts, }); } @@ -441,7 +424,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitSetSpecialRole, - dataParts: parts + dataParts: parts, }); } @@ -468,15 +451,12 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitESDTNFTCreate.valueOf() + storageGasLimit.valueOf(), - dataParts: parts + dataParts: parts, }); } pause(args: IPausingArgs): Transaction { - const parts = [ - "pause", - utf8ToHex(args.tokenIdentifier) - ]; + const parts = ["pause", utf8ToHex(args.tokenIdentifier)]; return this.createTransaction({ sender: args.manager, @@ -485,15 +465,12 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitPausing, - dataParts: parts + dataParts: parts, }); } unpause(args: IPausingArgs): Transaction { - const parts = [ - "unPause", - utf8ToHex(args.tokenIdentifier) - ]; + const parts = ["unPause", utf8ToHex(args.tokenIdentifier)]; return this.createTransaction({ sender: args.manager, @@ -502,16 +479,12 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitPausing, - dataParts: parts + dataParts: parts, }); } freeze(args: IFreezingArgs): Transaction { - const parts = [ - "freeze", - utf8ToHex(args.tokenIdentifier), - addressToHex(args.user) - ]; + const parts = ["freeze", utf8ToHex(args.tokenIdentifier), addressToHex(args.user)]; return this.createTransaction({ sender: args.manager, @@ -520,16 +493,12 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitFreezing, - dataParts: parts + dataParts: parts, }); } unfreeze(args: IFreezingArgs): Transaction { - const parts = [ - "unFreeze", - utf8ToHex(args.tokenIdentifier), - addressToHex(args.user) - ]; + const parts = ["unFreeze", utf8ToHex(args.tokenIdentifier), addressToHex(args.user)]; return this.createTransaction({ sender: args.manager, @@ -538,16 +507,12 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitFreezing, - dataParts: parts + dataParts: parts, }); } wipe(args: IWipingArgs): Transaction { - const parts = [ - "wipe", - utf8ToHex(args.tokenIdentifier), - addressToHex(args.user) - ]; + const parts = ["wipe", utf8ToHex(args.tokenIdentifier), addressToHex(args.user)]; return this.createTransaction({ sender: args.manager, @@ -556,16 +521,12 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitWiping, - dataParts: parts + dataParts: parts, }); } localMint(args: ILocalMintArgs): Transaction { - const parts = [ - "ESDTLocalMint", - utf8ToHex(args.tokenIdentifier), - bigIntToHex(args.supplyToMint), - ]; + const parts = ["ESDTLocalMint", utf8ToHex(args.tokenIdentifier), bigIntToHex(args.supplyToMint)]; return this.createTransaction({ sender: args.manager, @@ -574,16 +535,12 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitESDTLocalMint, - dataParts: parts + dataParts: parts, }); } localBurn(args: ILocalBurnArgs): Transaction { - const parts = [ - "ESDTLocalBurn", - utf8ToHex(args.tokenIdentifier), - bigIntToHex(args.supplyToBurn), - ]; + const parts = ["ESDTLocalBurn", utf8ToHex(args.tokenIdentifier), bigIntToHex(args.supplyToBurn)]; return this.createTransaction({ sender: args.manager, @@ -592,7 +549,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitESDTLocalBurn, - dataParts: parts + dataParts: parts, }); } @@ -611,7 +568,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitESDTNFTUpdateAttributes, - dataParts: parts + dataParts: parts, }); } @@ -620,7 +577,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG "ESDTNFTAddQuantity", utf8ToHex(args.tokenIdentifier), bigIntToHex(args.tokenNonce), - bigIntToHex(args.quantityToAdd) + bigIntToHex(args.quantityToAdd), ]; return this.createTransaction({ @@ -630,7 +587,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitESDTNFTAddQuantity, - dataParts: parts + dataParts: parts, }); } @@ -639,7 +596,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG "ESDTNFTBurn", utf8ToHex(args.tokenIdentifier), bigIntToHex(args.tokenNonce), - bigIntToHex(args.quantityToBurn) + bigIntToHex(args.quantityToBurn), ]; return this.createTransaction({ @@ -649,11 +606,20 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG gasPrice: args.gasPrice, gasLimitHint: args.gasLimit, executionGasLimit: this.config.gasLimitESDTNFTBurn, - dataParts: parts + dataParts: parts, }); } - private createTransaction({ sender, receiver, nonce, value, gasPrice, gasLimitHint, executionGasLimit, dataParts }: { + private createTransaction({ + sender, + receiver, + nonce, + value, + gasPrice, + gasLimitHint, + executionGasLimit, + dataParts, + }: { sender: IAddress; receiver: IAddress; nonce?: INonce; @@ -678,7 +644,7 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG value: value || 0, data: payload, version: version, - options: options + options: options, }); } @@ -688,7 +654,8 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG } private computeGasLimit(payload: TransactionPayload, executionGas: IGasLimit): IGasLimit { - const dataMovementGas = this.config.minGasLimit.valueOf() + this.config.gasLimitPerByte.valueOf() * payload.length(); + const dataMovementGas = + this.config.minGasLimit.valueOf() + this.config.gasLimitPerByte.valueOf() * payload.length(); return dataMovementGas + executionGas.valueOf(); } } From 8db7122b1ee091e4fbe63d5f9f74faf67d03f527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 13 Dec 2023 09:45:11 +0200 Subject: [PATCH 2/7] Fix flags when creating token management transactions. --- .../tokenOperationsFactory.spec.ts | 24 +++--- src/tokenOperations/tokenOperationsFactory.ts | 85 +++++++++++++------ 2 files changed, 69 insertions(+), 40 deletions(-) diff --git a/src/tokenOperations/tokenOperationsFactory.spec.ts b/src/tokenOperations/tokenOperationsFactory.spec.ts index f7257b6d..44c39761 100644 --- a/src/tokenOperations/tokenOperationsFactory.spec.ts +++ b/src/tokenOperations/tokenOperationsFactory.spec.ts @@ -39,12 +39,12 @@ describe("test factory", () => { canWipe: true, canPause: true, canChangeOwner: true, - canUpgrade: true, - canAddSpecialRoles: true, + canUpgrade: false, + canAddSpecialRoles: false, transactionNonce: 42 }); - assert.equal(transaction.getData().toString(), "issue@4652414e4b@4652414e4b@64@@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565") + assert.equal(transaction.getData().toString(), "issue@4652414e4b@4652414e4b@64@@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365") assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), frank.address.toString()); assert.equal(transaction.getReceiver().toString(), "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"); @@ -60,12 +60,12 @@ describe("test factory", () => { canPause: true, canTransferNFTCreateRole: true, canChangeOwner: true, - canUpgrade: true, - canAddSpecialRoles: true, + canUpgrade: false, + canAddSpecialRoles: false, transactionNonce: 42 }); - assert.equal(transaction.getData().toString(), "issueSemiFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565") + assert.equal(transaction.getData().toString(), "issueSemiFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365") assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), frank.address.toString()); assert.equal(transaction.getReceiver().toString(), "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"); @@ -81,12 +81,12 @@ describe("test factory", () => { canPause: true, canTransferNFTCreateRole: true, canChangeOwner: true, - canUpgrade: true, - canAddSpecialRoles: true, + canUpgrade: false, + canAddSpecialRoles: false, transactionNonce: 42 }); - assert.equal(transaction.getData().toString(), "issueNonFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565") + assert.equal(transaction.getData().toString(), "issueNonFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365") assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), frank.address.toString()); assert.equal(transaction.getReceiver().toString(), "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"); @@ -103,12 +103,12 @@ describe("test factory", () => { canPause: true, canTransferNFTCreateRole: true, canChangeOwner: true, - canUpgrade: true, - canAddSpecialRoles: true, + canUpgrade: false, + canAddSpecialRoles: false, transactionNonce: 42 }); - assert.equal(transaction.getData().toString(), "registerMetaESDT@4652414e4b@4652414e4b@0a@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565") + assert.equal(transaction.getData().toString(), "registerMetaESDT@4652414e4b@4652414e4b@0a@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365") assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), frank.address.toString()); assert.equal(transaction.getReceiver().toString(), "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"); diff --git a/src/tokenOperations/tokenOperationsFactory.ts b/src/tokenOperations/tokenOperationsFactory.ts index 3dc02010..4f8c8fc8 100644 --- a/src/tokenOperations/tokenOperationsFactory.ts +++ b/src/tokenOperations/tokenOperationsFactory.ts @@ -63,7 +63,7 @@ interface IIssueSemiFungibleArgs extends IBaseArgs { canAddSpecialRoles: boolean; } -interface IIssueNonFungibleArgs extends IIssueSemiFungibleArgs {} +interface IIssueNonFungibleArgs extends IIssueSemiFungibleArgs { } interface IRegisterMetaESDT extends IIssueSemiFungibleArgs { numDecimals: number; @@ -179,10 +179,12 @@ interface IBurnQuantityArgs extends IBaseArgs { export class TokenOperationsFactory { private readonly config: IConfig; private readonly trueAsHex; + private readonly falseAsHex; constructor(config: IConfig) { this.config = config; this.trueAsHex = utf8ToHex("true"); + this.falseAsHex = utf8ToHex("false"); } issueFungible(args: IIssueFungibleArgs): Transaction { @@ -194,12 +196,18 @@ export class TokenOperationsFactory { utf8ToHex(args.tokenTicker), bigIntToHex(args.initialSupply), bigIntToHex(args.numDecimals), - ...(args.canFreeze ? [utf8ToHex("canFreeze"), this.trueAsHex] : []), - ...(args.canWipe ? [utf8ToHex("canWipe"), this.trueAsHex] : []), - ...(args.canPause ? [utf8ToHex("canPause"), this.trueAsHex] : []), - ...(args.canChangeOwner ? [utf8ToHex("canChangeOwner"), this.trueAsHex] : []), - ...(args.canUpgrade ? [utf8ToHex("canUpgrade"), this.trueAsHex] : []), - ...(args.canAddSpecialRoles ? [utf8ToHex("canAddSpecialRoles"), this.trueAsHex] : []), + utf8ToHex("canFreeze"), + args.canFreeze ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canWipe"), + args.canWipe ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canPause"), + args.canPause ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canChangeOwner"), + args.canChangeOwner ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canUpgrade"), + args.canUpgrade ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canAddSpecialRoles"), + args.canAddSpecialRoles ? this.trueAsHex : this.falseAsHex ]; return this.createTransaction({ @@ -230,13 +238,20 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG "issueSemiFungible", utf8ToHex(args.tokenName), utf8ToHex(args.tokenTicker), - ...(args.canFreeze ? [utf8ToHex("canFreeze"), this.trueAsHex] : []), - ...(args.canWipe ? [utf8ToHex("canWipe"), this.trueAsHex] : []), - ...(args.canPause ? [utf8ToHex("canPause"), this.trueAsHex] : []), - ...(args.canTransferNFTCreateRole ? [utf8ToHex("canTransferNFTCreateRole"), this.trueAsHex] : []), - ...(args.canChangeOwner ? [utf8ToHex("canChangeOwner"), this.trueAsHex] : []), - ...(args.canUpgrade ? [utf8ToHex("canUpgrade"), this.trueAsHex] : []), - ...(args.canAddSpecialRoles ? [utf8ToHex("canAddSpecialRoles"), this.trueAsHex] : []), + utf8ToHex("canFreeze"), + args.canFreeze ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canWipe"), + args.canWipe ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canPause"), + args.canPause ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canTransferNFTCreateRole"), + args.canTransferNFTCreateRole ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canChangeOwner"), + args.canChangeOwner ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canUpgrade"), + args.canUpgrade ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canAddSpecialRoles"), + args.canAddSpecialRoles ? this.trueAsHex : this.falseAsHex ]; return this.createTransaction({ @@ -258,13 +273,20 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG "issueNonFungible", utf8ToHex(args.tokenName), utf8ToHex(args.tokenTicker), - ...(args.canFreeze ? [utf8ToHex("canFreeze"), this.trueAsHex] : []), - ...(args.canWipe ? [utf8ToHex("canWipe"), this.trueAsHex] : []), - ...(args.canPause ? [utf8ToHex("canPause"), this.trueAsHex] : []), - ...(args.canTransferNFTCreateRole ? [utf8ToHex("canTransferNFTCreateRole"), this.trueAsHex] : []), - ...(args.canChangeOwner ? [utf8ToHex("canChangeOwner"), this.trueAsHex] : []), - ...(args.canUpgrade ? [utf8ToHex("canUpgrade"), this.trueAsHex] : []), - ...(args.canAddSpecialRoles ? [utf8ToHex("canAddSpecialRoles"), this.trueAsHex] : []), + utf8ToHex("canFreeze"), + args.canFreeze ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canWipe"), + args.canWipe ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canPause"), + args.canPause ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canTransferNFTCreateRole"), + args.canTransferNFTCreateRole ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canChangeOwner"), + args.canChangeOwner ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canUpgrade"), + args.canUpgrade ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canAddSpecialRoles"), + args.canAddSpecialRoles ? this.trueAsHex : this.falseAsHex ]; return this.createTransaction({ @@ -287,13 +309,20 @@ Once the token is registered, you can unset this role by calling "unsetBurnRoleG utf8ToHex(args.tokenName), utf8ToHex(args.tokenTicker), bigIntToHex(args.numDecimals), - ...(args.canFreeze ? [utf8ToHex("canFreeze"), this.trueAsHex] : []), - ...(args.canWipe ? [utf8ToHex("canWipe"), this.trueAsHex] : []), - ...(args.canPause ? [utf8ToHex("canPause"), this.trueAsHex] : []), - ...(args.canTransferNFTCreateRole ? [utf8ToHex("canTransferNFTCreateRole"), this.trueAsHex] : []), - ...(args.canChangeOwner ? [utf8ToHex("canChangeOwner"), this.trueAsHex] : []), - ...(args.canUpgrade ? [utf8ToHex("canUpgrade"), this.trueAsHex] : []), - ...(args.canAddSpecialRoles ? [utf8ToHex("canAddSpecialRoles"), this.trueAsHex] : []), + utf8ToHex("canFreeze"), + args.canFreeze ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canWipe"), + args.canWipe ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canPause"), + args.canPause ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canTransferNFTCreateRole"), + args.canTransferNFTCreateRole ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canChangeOwner"), + args.canChangeOwner ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canUpgrade"), + args.canUpgrade ? this.trueAsHex : this.falseAsHex, + utf8ToHex("canAddSpecialRoles"), + args.canAddSpecialRoles ? this.trueAsHex : this.falseAsHex ]; return this.createTransaction({ From 759ad1f83b691a5a87338a4e6ccfdd30d6c77c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 14 Dec 2023 19:58:35 +0200 Subject: [PATCH 3/7] Handle explicit-enum types. Assign missing discriminants for enum variants. --- .../typesystem/abiRegistry.spec.ts | 12 +++++++ src/smartcontracts/typesystem/abiRegistry.ts | 2 +- src/smartcontracts/typesystem/enum.ts | 19 ++++++++++- src/testdata/explicit-enum.abi.json | 32 +++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/testdata/explicit-enum.abi.json diff --git a/src/smartcontracts/typesystem/abiRegistry.spec.ts b/src/smartcontracts/typesystem/abiRegistry.spec.ts index 55910ace..3d151e1d 100644 --- a/src/smartcontracts/typesystem/abiRegistry.spec.ts +++ b/src/smartcontracts/typesystem/abiRegistry.spec.ts @@ -156,4 +156,16 @@ describe("test abi registry", () => { assert.deepEqual(setStatusEvent.inputs[1].type, new U64Type()); assert.deepEqual(setStatusEvent.inputs[2].type, registry.getCustomType("TransactionStatus")); }); + + it("should load ABI explicit-enum", async () => { + const registry = await loadAbiRegistry("src/testdata/explicit-enum.abi.json"); + + const enumType = registry.getEnum("OperationCompletionStatus"); + + assert.deepEqual(enumType.variants[0].name, "completed"); + assert.deepEqual(enumType.variants[0].discriminant, 0); + + assert.deepEqual(enumType.variants[1].name, "interrupted"); + assert.deepEqual(enumType.variants[1].discriminant, 1); + }); }); diff --git a/src/smartcontracts/typesystem/abiRegistry.ts b/src/smartcontracts/typesystem/abiRegistry.ts index 41976255..27c300ee 100644 --- a/src/smartcontracts/typesystem/abiRegistry.ts +++ b/src/smartcontracts/typesystem/abiRegistry.ts @@ -53,7 +53,7 @@ export class AbiRegistry { if (typeDefinition.type == "struct") { customTypes.push(StructType.fromJSON({ name: customTypeName, fields: typeDefinition.fields })); - } else if (typeDefinition.type == "enum") { + } else if (typeDefinition.type == "enum" || typeDefinition.type == "explicit-enum") { customTypes.push(EnumType.fromJSON({ name: customTypeName, variants: typeDefinition.variants })); } else { throw new errors.ErrTypingSystem(`Cannot handle custom type: ${customTypeName}`); diff --git a/src/smartcontracts/typesystem/enum.ts b/src/smartcontracts/typesystem/enum.ts index 7ae08a1f..38458415 100644 --- a/src/smartcontracts/typesystem/enum.ts +++ b/src/smartcontracts/typesystem/enum.ts @@ -19,10 +19,27 @@ export class EnumType extends CustomType { } static fromJSON(json: { name: string; variants: any[] }): EnumType { - let variants = (json.variants || []).map((variant) => EnumVariantDefinition.fromJSON(variant)); + const rawVariants = EnumType.assignMissingDiscriminants(json.variants); + const variants = (rawVariants || []).map((variant) => EnumVariantDefinition.fromJSON(variant)); return new EnumType(json.name, variants); } + // For some enums (e.g. some "explicit-enum" types), the discriminants are missing. + private static assignMissingDiscriminants(variants: any[]): any[] { + const allDiscriminantsAreMissing = variants.every((variant) => variant.discriminant == undefined); + if (!allDiscriminantsAreMissing) { + // We only assign discriminants if all of them are missing. + return variants; + } + + return variants.map((variant, index) => { + return { + ...variant, + discriminant: index + } + }); + } + getVariantByDiscriminant(discriminant: number): EnumVariantDefinition { let result = this.variants.find((e) => e.discriminant == discriminant); guardValueIsSet(`variant by discriminant (${discriminant})`, result); diff --git a/src/testdata/explicit-enum.abi.json b/src/testdata/explicit-enum.abi.json new file mode 100644 index 00000000..7aab9202 --- /dev/null +++ b/src/testdata/explicit-enum.abi.json @@ -0,0 +1,32 @@ +{ + "endpoints": [ + { + "name": "foobar", + "inputs": [], + "outputs": [ + { + "type": "OperationCompletionStatus" + } + ] + } + ], + "types": { + "OperationCompletionStatus": { + "type": "explicit-enum", + "variants": [ + { + "docs": [ + "indicates that operation was completed" + ], + "name": "completed" + }, + { + "docs": [ + "indicates that operation was interrupted prematurely, due to low gas" + ], + "name": "interrupted" + } + ] + } + } +} From 1926fb7e1950dc31c7f9d70b9f1be5a318d7968a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 14 Dec 2023 19:59:25 +0200 Subject: [PATCH 4/7] Bump version. --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 60c2f972..3e310c85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@multiversx/sdk-core", - "version": "12.16.0", + "version": "12.17.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@multiversx/sdk-core", - "version": "12.16.0", + "version": "12.17.0", "license": "MIT", "dependencies": { "@multiversx/sdk-transaction-decoder": "1.0.2", diff --git a/package.json b/package.json index 714d2c80..44773a09 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-core", - "version": "12.16.0", + "version": "12.17.0", "description": "MultiversX SDK for JavaScript and TypeScript", "main": "out/index.js", "types": "out/index.d.js", From 34ee79d0a292a4f8dc36409588c9a90c7a9dc165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 14 Dec 2023 20:08:59 +0200 Subject: [PATCH 5/7] Minor refactoring. --- src/smartcontracts/typesystem/enum.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/smartcontracts/typesystem/enum.ts b/src/smartcontracts/typesystem/enum.ts index 38458415..1320a4b4 100644 --- a/src/smartcontracts/typesystem/enum.ts +++ b/src/smartcontracts/typesystem/enum.ts @@ -19,8 +19,8 @@ export class EnumType extends CustomType { } static fromJSON(json: { name: string; variants: any[] }): EnumType { - const rawVariants = EnumType.assignMissingDiscriminants(json.variants); - const variants = (rawVariants || []).map((variant) => EnumVariantDefinition.fromJSON(variant)); + const rawVariants = EnumType.assignMissingDiscriminants(json.variants || []); + const variants = rawVariants.map((variant) => EnumVariantDefinition.fromJSON(variant)); return new EnumType(json.name, variants); } From 61290348f74a936e0f00ad7e7227ec3c728ddc16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20=C4=86wirko?= Date: Sun, 31 Dec 2023 13:20:13 +0100 Subject: [PATCH 6/7] add address validator static method without throwing errors --- src/address.spec.ts | 6 ++++++ src/address.ts | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/address.spec.ts b/src/address.spec.ts index 26590d28..ca731f8e 100644 --- a/src/address.spec.ts +++ b/src/address.spec.ts @@ -44,4 +44,10 @@ describe("test address", () => { assert.throw(() => new Address("erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2"), errors.ErrAddressCannotCreate); assert.throw(() => new Address("xerd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"), errors.ErrAddressCannotCreate); }); + + it("should validate the address without throwing the error", () => { + assert.isTrue(Address.isValid(aliceBech32)); + assert.isFalse(Address.isValid('xerd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz')); + assert.isFalse(Address.isValid('erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2')) + }) }); diff --git a/src/address.ts b/src/address.ts index 1931d624..48bfdbaa 100644 --- a/src/address.ts +++ b/src/address.ts @@ -122,6 +122,23 @@ export class Address { return Address.fromValidHex(pubkey.toString("hex")); } + /** + * Performs address validation without throwing errors + */ + static isValid(value: string): boolean { + const decoded = bech32.decodeUnsafe(value); + const prefix = decoded?.prefix; + const pubkey = decoded + ? Buffer.from(bech32.fromWords(decoded.words)) + : undefined; + + if (prefix !== HRP || pubkey?.length !== PUBKEY_LENGTH) { + return false; + } + + return true; + } + /** * Returns the hex representation of the address (pubkey) */ From e93c5ea1eee75b6c648b11ce52425eb281685e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 9 Jan 2024 17:08:57 +0200 Subject: [PATCH 7/7] Reference newer Axios. Bump minor version. --- package-lock.json | 34 +++++++++++++++++----------------- package.json | 4 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3e310c85..6c217691 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@multiversx/sdk-core", - "version": "12.17.0", + "version": "12.18.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@multiversx/sdk-core", - "version": "12.17.0", + "version": "12.18.0", "license": "MIT", "dependencies": { "@multiversx/sdk-transaction-decoder": "1.0.2", @@ -27,7 +27,7 @@ "@types/mocha": "9.1.0", "@types/node": "13.13.2", "assert": "2.0.0", - "axios": "1.6.2", + "axios": "1.6.5", "browserify": "17.0.0", "chai": "4.2.0", "esmify": "2.1.1", @@ -842,12 +842,12 @@ } }, "node_modules/axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.5.tgz", + "integrity": "sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==", "dev": true, "dependencies": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.4", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -2106,9 +2106,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "dev": true, "funding": [ { @@ -5125,12 +5125,12 @@ "dev": true }, "axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.5.tgz", + "integrity": "sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==", "dev": true, "requires": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.4", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -6188,9 +6188,9 @@ "dev": true }, "follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "dev": true }, "for-each": { diff --git a/package.json b/package.json index 44773a09..b03755ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-core", - "version": "12.17.0", + "version": "12.18.0", "description": "MultiversX SDK for JavaScript and TypeScript", "main": "out/index.js", "types": "out/index.d.js", @@ -43,7 +43,7 @@ "@types/mocha": "9.1.0", "@types/node": "13.13.2", "assert": "2.0.0", - "axios": "1.6.2", + "axios": "1.6.5", "browserify": "17.0.0", "chai": "4.2.0", "esmify": "2.1.1",