From e8aa3e2f55994db4c85ab74fbe416b1aa29bf404 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 9 Dec 2024 16:08:09 +0200 Subject: [PATCH] Remove deprecated code --- src/abi/index.ts | 2 - src/abi/interaction.spec.ts | 31 ++- src/abi/interaction.ts | 9 - src/abi/interactionChecker.spec.ts | 85 ------ src/abi/interactionChecker.ts | 59 ---- src/abi/transactionPayloadBuilders.spec.ts | 47 ---- src/abi/transactionPayloadBuilders.ts | 174 ------------ src/accounts/account.ts | 22 +- src/address.ts | 21 -- src/constants.ts | 25 -- src/gasEstimator.spec.ts | 42 --- src/gasEstimator.ts | 74 ----- src/index.ts | 4 - src/interface.ts | 5 - src/networkProviders/apiNetworkProvider.ts | 9 +- src/networkProviders/interface.ts | 15 +- .../providers.dev.net.spec.ts | 104 +++---- src/networkProviders/proxyNetworkProvider.ts | 9 +- src/relayedTransactionV1Builder.spec.ts | 260 ------------------ src/relayedTransactionV1Builder.ts | 173 ------------ src/relayedTransactionV2Builder.spec.ts | 94 ------- src/relayedTransactionV2Builder.ts | 122 -------- src/signableMessage.spec.ts | 34 --- src/signableMessage.ts | 81 ------ src/testutils/mockNetworkProvider.ts | 5 +- src/testutils/wallets.ts | 2 +- src/tokenTransferBuilders.spec.ts | 57 ---- src/tokenTransferBuilders.ts | 109 -------- src/tokens.ts | 14 - src/transactionOnNetwork.ts | 8 +- 30 files changed, 80 insertions(+), 1616 deletions(-) delete mode 100644 src/abi/interactionChecker.spec.ts delete mode 100644 src/abi/interactionChecker.ts delete mode 100644 src/abi/transactionPayloadBuilders.spec.ts delete mode 100644 src/abi/transactionPayloadBuilders.ts delete mode 100644 src/gasEstimator.spec.ts delete mode 100644 src/gasEstimator.ts delete mode 100644 src/relayedTransactionV1Builder.spec.ts delete mode 100644 src/relayedTransactionV1Builder.ts delete mode 100644 src/relayedTransactionV2Builder.spec.ts delete mode 100644 src/relayedTransactionV2Builder.ts delete mode 100644 src/signableMessage.spec.ts delete mode 100644 src/signableMessage.ts delete mode 100644 src/tokenTransferBuilders.spec.ts delete mode 100644 src/tokenTransferBuilders.ts diff --git a/src/abi/index.ts b/src/abi/index.ts index 58a6a1f79..c07177226 100644 --- a/src/abi/index.ts +++ b/src/abi/index.ts @@ -4,11 +4,9 @@ export * from "./codec"; export * from "./codeMetadata"; export * from "./function"; export * from "./interaction"; -export * from "./interactionChecker"; export * from "./interface"; export * from "./nativeSerializer"; export * from "./query"; export * from "./returnCode"; export * from "./smartContract"; -export * from "./transactionPayloadBuilders"; export * from "./typesystem"; diff --git a/src/abi/interaction.spec.ts b/src/abi/interaction.spec.ts index 468d078a9..75418b317 100644 --- a/src/abi/interaction.spec.ts +++ b/src/abi/interaction.spec.ts @@ -282,7 +282,7 @@ describe("test smart contract interactor", function () { let contract = new SmartContract({ address: dummyAddress, abi: abi }); let controller = new SmartContractController({ chainID: "D", networkProvider: provider, abi: abi }); - let getInteraction = contract.methodsExplicit.get().check(); + let getInteraction = contract.methodsExplicit.get(); let incrementInteraction = (contract.methods.increment()).withGasLimit(543210); let decrementInteraction = (contract.methods.decrement()).withGasLimit(987654); @@ -353,20 +353,21 @@ describe("test smart contract interactor", function () { let contract = new SmartContract({ address: dummyAddress, abi: abiRegistry }); let controller = new SmartContractController({ chainID: "D", networkProvider: provider, abi: abiRegistry }); - let startInteraction = contract.methodsExplicit - .start([ - BytesValue.fromUTF8("lucky"), - new TokenIdentifierValue("lucky-token"), - new BigUIntValue(1), - OptionValue.newMissing(), - OptionValue.newMissing(), - OptionValue.newProvided(new U32Value(1)), - OptionValue.newMissing(), - OptionValue.newMissing(), - OptionalValue.newMissing(), - ]) - .withGasLimit(5000000) - .check(); + let startInteraction = ( + contract.methodsExplicit + .start([ + BytesValue.fromUTF8("lucky"), + new TokenIdentifierValue("lucky-token"), + new BigUIntValue(1), + OptionValue.newMissing(), + OptionValue.newMissing(), + OptionValue.newProvided(new U32Value(1)), + OptionValue.newMissing(), + OptionValue.newMissing(), + OptionalValue.newMissing(), + ]) + .withGasLimit(5000000) + ); let statusInteraction = contract.methods.status(["lucky"]).withGasLimit(5000000); diff --git a/src/abi/interaction.ts b/src/abi/interaction.ts index d11edf864..2726cb3c1 100644 --- a/src/abi/interaction.ts +++ b/src/abi/interaction.ts @@ -8,7 +8,6 @@ import { TokenTransfer } from "../tokens"; import { Transaction } from "../transaction"; import { TransactionsFactoryConfig } from "../transactionsFactoryConfig"; import { ContractFunction } from "./function"; -import { InteractionChecker } from "./interactionChecker"; import { CallArguments } from "./interface"; import { Query } from "./query"; import { EndpointDefinition, TypedValue } from "./typesystem"; @@ -195,12 +194,4 @@ export class Interaction { this.explicitReceiver = receiver; return this; } - - /** - * To perform custom checking, extend {@link Interaction} and override this method. - */ - check(): Interaction { - new InteractionChecker().checkInteraction(this, this.getEndpoint()); - return this; - } } diff --git a/src/abi/interactionChecker.spec.ts b/src/abi/interactionChecker.spec.ts deleted file mode 100644 index caabab429..000000000 --- a/src/abi/interactionChecker.spec.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { assert } from "chai"; -import { Address } from "../address"; -import * as errors from "../errors"; -import { loadAbiRegistry } from "../testutils"; -import { TokenTransfer } from "../tokens"; -import { Interaction } from "./interaction"; -import { InteractionChecker } from "./interactionChecker"; -import { SmartContract } from "./smartContract"; -import { - BigUIntType, - BigUIntValue, - BytesValue, - OptionalType, - OptionalValue, - OptionValue, - TokenIdentifierValue, - U32Value, -} from "./typesystem"; - -describe("integration tests: test checker within interactor", function () { - let dummyAddress = new Address("erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3"); - let checker = new InteractionChecker(); - - it("should detect errors for 'ultimate answer'", async function () { - let abiRegistry = await loadAbiRegistry("src/testdata/answer.abi.json"); - let contract = new SmartContract({ address: dummyAddress, abi: abiRegistry }); - let endpoint = abiRegistry.getEndpoint("getUltimateAnswer"); - - // Send value to non-payable - assert.throw( - () => { - let interaction = (contract.methods.getUltimateAnswer()).withValue( - TokenTransfer.egldFromAmount(1), - ); - checker.checkInteraction(interaction, endpoint); - }, - errors.ErrContractInteraction, - "cannot send EGLD value to non-payable", - ); - - // Bad arguments - assert.throw( - () => { - contract.methods.getUltimateAnswer(["abba"]); - }, - Error, - "Wrong number of arguments for endpoint getUltimateAnswer: expected between 0 and 0 arguments, have 1", - ); - }); - - it("should detect errors for 'lottery'", async function () { - let abiRegistry = await loadAbiRegistry("src/testdata/lottery-esdt.abi.json"); - let contract = new SmartContract({ address: dummyAddress, abi: abiRegistry }); - let endpoint = abiRegistry.getEndpoint("start"); - - // Bad number of arguments - assert.throw( - () => { - contract.methods.start(["lucky", TokenTransfer.egldFromAmount(1)]); - }, - Error, - "Wrong number of arguments for endpoint start: expected between 8 and 9 arguments, have 2", - ); - - // Bad types (U64 instead of U32) - assert.throw( - () => { - let interaction = contract.methodsExplicit.start([ - BytesValue.fromUTF8("lucky"), - new TokenIdentifierValue("lucky-token"), - new BigUIntValue(1), - OptionValue.newMissing(), - OptionValue.newProvided(new U32Value(1)), - OptionValue.newProvided(new U32Value(1)), - OptionValue.newMissing(), - OptionValue.newMissing(), - new OptionalValue(new OptionalType(new BigUIntType())), - ]); - checker.checkInteraction(interaction, endpoint); - }, - errors.ErrContractInteraction, - "type mismatch at index 4, expected: Option, got: Option", - ); - }); -}); diff --git a/src/abi/interactionChecker.ts b/src/abi/interactionChecker.ts deleted file mode 100644 index 744525f56..000000000 --- a/src/abi/interactionChecker.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as errors from "../errors"; -import { EndpointDefinition } from "./typesystem"; -import { Interaction } from "./interaction"; -import BigNumber from "bignumber.js"; - -/** - * An interaction checker that aims to be as strict as possible. - * It is designed to catch programmer errors such as: - * - incorrect types of contract call arguments - * - errors related to calling "non-payable" functions with some value provided - * - gas estimation errors (not yet implemented) - */ -/** - * @deprecated The Interaction checker is deprecated due to lack of use. - */ -export class InteractionChecker { - checkInteraction(interaction: Interaction, definition: EndpointDefinition): void { - this.checkPayable(interaction, definition); - this.checkArguments(interaction, definition); - } - - private checkPayable(interaction: Interaction, definition: EndpointDefinition) { - let hasValue = !new BigNumber(interaction.getValue().toString()).isZero(); - let isPayableInEGLD = definition.modifiers.isPayableInEGLD(); - - if (hasValue && !isPayableInEGLD) { - throw new errors.ErrContractInteraction("cannot send EGLD value to non-payable"); - } - } - - private checkArguments(interaction: Interaction, definition: EndpointDefinition) { - let formalArguments = definition.input; - let actualArguments = interaction.getArguments(); - let numFormalArguments = formalArguments.length; - let numActualArguments = actualArguments.length; - - if (numFormalArguments != numActualArguments) { - throw new errors.ErrContractInteraction( - `bad arguments, expected: ${numFormalArguments}, got: ${numActualArguments}`, - ); - } - - // TODO: discuss again, possibly redesign the handling of covariance / contravariance. - - for (let i = 0; i < numFormalArguments; i++) { - let expectedType = formalArguments[i].type; - let argument = actualArguments[i]; - let actualType = argument.getType(); - // isAssignableFrom() is responsible to handle covariance and contravariance (depending on the class that overrides it). - let ok = expectedType.isAssignableFrom(actualType); - - if (!ok) { - throw new errors.ErrContractInteraction( - `type mismatch at index ${i}, expected: ${expectedType}, got: ${actualType}`, - ); - } - } - } -} diff --git a/src/abi/transactionPayloadBuilders.spec.ts b/src/abi/transactionPayloadBuilders.spec.ts deleted file mode 100644 index 884c48b06..000000000 --- a/src/abi/transactionPayloadBuilders.spec.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { assert } from "chai"; -import { Address } from "../address"; -import { ContractFunction } from "./function"; -import { Code } from "./code"; -import { CodeMetadata } from "./codeMetadata"; -import { AddressValue, U32Value } from "./typesystem"; -import { - ContractCallPayloadBuilder, - ContractDeployPayloadBuilder, - ContractUpgradePayloadBuilder, -} from "./transactionPayloadBuilders"; - -describe("test contract payload builders", () => { - it("should prepare deploy correctly", async () => { - let payload = new ContractDeployPayloadBuilder() - .setCode(Code.fromBuffer(Buffer.from([1, 2, 3, 4]))) - .setCodeMetadata(new CodeMetadata(true, false, true)) - .addInitArg(new U32Value(1024)) - .build(); - - assert.equal(payload.valueOf().toString(), "01020304@0500@0102@0400"); - }); - - it("should prepare upgrade correctly", async () => { - let payload = new ContractUpgradePayloadBuilder() - .setCode(Code.fromBuffer(Buffer.from([1, 2, 3, 4]))) - .setCodeMetadata(new CodeMetadata(true, false, true)) - .addInitArg(new U32Value(1024)) - .build(); - - assert.equal(payload.valueOf().toString(), "upgradeContract@01020304@0102@0400"); - }); - - it("should prepare call correctly", async () => { - let alice = new Address("erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"); - let payload = new ContractCallPayloadBuilder() - .setFunction(new ContractFunction("transferToken")) - .addArg(new AddressValue(alice)) - .addArg(new U32Value(1024)) - .build(); - - assert.equal( - payload.valueOf().toString(), - "transferToken@fd691bb5e85d102687d81079dffce842d4dc328276d2d4c60d8fd1c3433c3293@0400", - ); - }); -}); diff --git a/src/abi/transactionPayloadBuilders.ts b/src/abi/transactionPayloadBuilders.ts deleted file mode 100644 index 215b9e729..000000000 --- a/src/abi/transactionPayloadBuilders.ts +++ /dev/null @@ -1,174 +0,0 @@ -import { WasmVirtualMachine } from "../constants"; -import { TransactionPayload } from "../transactionPayload"; -import { guardValueIsSet } from "../utils"; -import { ArgSerializer } from "./argSerializer"; -import { ICode, ICodeMetadata, IContractFunction } from "./interface"; -import { TypedValue } from "./typesystem"; - -/** - * @deprecated Use {@link SmartContractTransactionsFactory} instead. - * - * A builder for {@link TransactionPayload} objects, to be used for Smart Contract deployment transactions. - */ -export class ContractDeployPayloadBuilder { - private code: ICode | null = null; - private codeMetadata: ICodeMetadata = ""; - private arguments: TypedValue[] = []; - - /** - * Sets the code of the Smart Contract. - */ - setCode(code: ICode): ContractDeployPayloadBuilder { - this.code = code; - return this; - } - - /** - * Sets the code metadata of the Smart Contract. - */ - setCodeMetadata(codeMetadata: ICodeMetadata): ContractDeployPayloadBuilder { - this.codeMetadata = codeMetadata; - return this; - } - - /** - * Adds constructor (`init`) arguments. - */ - addInitArg(arg: TypedValue): ContractDeployPayloadBuilder { - this.arguments.push(arg); - return this; - } - - /** - * Sets constructor (`init`) arguments. - */ - setInitArgs(args: TypedValue[]): ContractDeployPayloadBuilder { - this.arguments = args; - return this; - } - - /** - * Builds the {@link TransactionPayload}. - */ - build(): TransactionPayload { - guardValueIsSet("code", this.code); - - let code = this.code!.toString(); - let codeMetadata = this.codeMetadata.toString(); - let data = `${code}@${WasmVirtualMachine}@${codeMetadata}`; - data = appendArgumentsToString(data, this.arguments); - - return new TransactionPayload(data); - } -} - -/** - * @deprecated Use {@link SmartContractTransactionsFactory} instead. - * - * A builder for {@link TransactionPayload} objects, to be used for Smart Contract upgrade transactions. - */ -export class ContractUpgradePayloadBuilder { - private code: ICode | null = null; - private codeMetadata: ICodeMetadata = ""; - private arguments: TypedValue[] = []; - - /** - * Sets the code of the Smart Contract. - */ - setCode(code: ICode): ContractUpgradePayloadBuilder { - this.code = code; - return this; - } - - /** - * Sets the code metadata of the Smart Contract. - */ - setCodeMetadata(codeMetadata: ICodeMetadata): ContractUpgradePayloadBuilder { - this.codeMetadata = codeMetadata; - return this; - } - - /** - * Adds upgrade (`init`) arguments. - */ - addInitArg(arg: TypedValue): ContractUpgradePayloadBuilder { - this.arguments.push(arg); - return this; - } - - /** - * Sets upgrade (`init`) arguments. - */ - setInitArgs(args: TypedValue[]): ContractUpgradePayloadBuilder { - this.arguments = args; - return this; - } - - /** - * Builds the {@link TransactionPayload}. - */ - build(): TransactionPayload { - guardValueIsSet("code", this.code); - - let code = this.code!.toString(); - let codeMetadata = this.codeMetadata.toString(); - let data = `upgradeContract@${code}@${codeMetadata}`; - data = appendArgumentsToString(data, this.arguments); - - return new TransactionPayload(data); - } -} - -/** - * @deprecated Use {@link SmartContractTransactionsFactory} instead. - * - * A builder for {@link TransactionPayload} objects, to be used for Smart Contract execution transactions. - */ -export class ContractCallPayloadBuilder { - private contractFunction: IContractFunction | null = null; - private arguments: TypedValue[] = []; - - /** - * Sets the function to be called (executed). - */ - setFunction(contractFunction: IContractFunction): ContractCallPayloadBuilder { - this.contractFunction = contractFunction; - return this; - } - - /** - * Adds a function argument. - */ - addArg(arg: TypedValue): ContractCallPayloadBuilder { - this.arguments.push(arg); - return this; - } - - /** - * Sets the function arguments. - */ - setArgs(args: TypedValue[]): ContractCallPayloadBuilder { - this.arguments = args; - return this; - } - - /** - * Builds the {@link TransactionPayload}. - */ - build(): TransactionPayload { - guardValueIsSet("calledFunction", this.contractFunction); - - let data = this.contractFunction!.toString(); - data = appendArgumentsToString(data, this.arguments); - - return new TransactionPayload(data); - } -} - -function appendArgumentsToString(to: string, values: TypedValue[]) { - let { argumentsString, count } = new ArgSerializer().valuesToString(values); - if (count == 0) { - return to; - } - return `${to}@${argumentsString}`; -} diff --git a/src/accounts/account.ts b/src/accounts/account.ts index e164a34b2..126e194d3 100644 --- a/src/accounts/account.ts +++ b/src/accounts/account.ts @@ -1,6 +1,6 @@ import { Address } from "../address"; import { LibraryConfig } from "../config"; -import { IAccountBalance, INonce } from "../interface"; +import { INonce } from "../interface"; import { Mnemonic, UserSigner, UserWallet } from "../wallet"; import { IAccount } from "./interfaces"; @@ -18,14 +18,6 @@ export class Account implements IAccount { */ nonce: INonce = 0; - /** - * @deprecated This will be remove with the next release as not needed anymore. - */ - /** - * The balance of the account. - */ - balance: IAccountBalance = "0"; - /** * The signer of the account. */ @@ -39,17 +31,6 @@ export class Account implements IAccount { this.signer = signer; } - /** - * @deprecated This will be remove with the next release as not needed anymore. - */ - /** - * Updates account properties (such as nonce, balance). - */ - update(obj: { nonce: INonce; balance: IAccountBalance }) { - this.nonce = obj.nonce; - this.balance = obj.balance; - } - /** * Increments (locally) the nonce (the account sequence number). */ @@ -73,7 +54,6 @@ export class Account implements IAccount { return { address: this.address.bech32(), nonce: this.nonce.valueOf(), - balance: this.balance.toString(), }; } diff --git a/src/address.ts b/src/address.ts index 00241fee8..ec5fae2f7 100644 --- a/src/address.ts +++ b/src/address.ts @@ -124,27 +124,6 @@ export class Address { return Address.newFromHex(value, hrp); } - /** - * @deprecated Constructing an address object from another object is deprecated. - */ - static fromAddress(address: Address): Address { - return new Address(address); - } - - /** - * @deprecated Use the constructor, instead. - */ - static fromBuffer(buffer: Buffer, hrp?: string): Address { - return new Address(buffer, hrp); - } - - /** - * @deprecated Use {@link newFromBech32} or {@link newFromHex}. - */ - static fromString(value: string, hrp?: string): Address { - return new Address(value, hrp); - } - private static isValidHex(value: string) { return Buffer.from(value, "hex").length == PUBKEY_LENGTH; } diff --git a/src/constants.ts b/src/constants.ts index 9300d9780..d62de0fa7 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -26,28 +26,3 @@ export const SDK_JS_SIGNER = "sdk-js"; export const UNKNOWN_SIGNER = "unknown"; export const EGLD_IDENTIFIER_FOR_MULTI_ESDTNFT_TRANSFER = "EGLD-000000"; - -/** - * @deprecated - */ -export const DEFAULT_HRP = "erd"; - -/** - * @deprecated - */ -export const BECH32_ADDRESS_LENGTH = 62; - -/** - * @deprecated Use {@link CONTRACT_DEPLOY_ADDRESS_HEX} instead. - */ -export const CONTRACT_DEPLOY_ADDRESS = "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu"; - -/** - * @deprecated Use {@link DELEGATION_MANAGER_SC_ADDRESS_HEX} instead. - */ -export const DELEGATION_MANAGER_SC_ADDRESS = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"; - -/** - * @deprecated Use {@link 000000000000000000010000000000000000000000000000000000000002ffff} instead. - */ -export const ESDT_CONTRACT_ADDRESS = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"; diff --git a/src/gasEstimator.spec.ts b/src/gasEstimator.spec.ts deleted file mode 100644 index e1394717f..000000000 --- a/src/gasEstimator.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { assert } from "chai"; -import { GasEstimator } from "./gasEstimator"; - -describe("test gas estimator", () => { - it("should estimate gas limit (default gas configuration)", () => { - const estimator = new GasEstimator(); - - assert.equal(estimator.forEGLDTransfer(0), 50000); - assert.equal(estimator.forEGLDTransfer(3), 50000 + 3 * 1500); - - assert.equal(estimator.forESDTTransfer(80), 50000 + 80 * 1500 + 200000 + 100000); - assert.equal(estimator.forESDTTransfer(100), 50000 + 100 * 1500 + 200000 + 100000); - - assert.equal(estimator.forESDTNFTTransfer(80), 50000 + 80 * 1500 + 200000 + 800000); - assert.equal(estimator.forESDTNFTTransfer(100), 50000 + 100 * 1500 + 200000 + 800000); - - assert.equal(estimator.forMultiESDTNFTTransfer(80, 1), 50000 + 80 * 1500 + (200000 + 800000) * 1); - assert.equal(estimator.forMultiESDTNFTTransfer(80, 3), 50000 + 80 * 1500 + (200000 + 800000) * 3); - }); - - it("should estimate gas limit (custom gas configuration)", () => { - const estimator = new GasEstimator({ - minGasLimit: 10000, - gasPerDataByte: 3000, - gasCostESDTTransfer: 200000, - gasCostESDTNFTTransfer: 300000, - gasCostESDTNFTMultiTransfer: 400000, - }); - - assert.equal(estimator.forEGLDTransfer(0), 10000); - assert.equal(estimator.forEGLDTransfer(3), 10000 + 3 * 3000); - - assert.equal(estimator.forESDTTransfer(80), 10000 + 80 * 3000 + 200000 + 100000); - assert.equal(estimator.forESDTTransfer(100), 10000 + 100 * 3000 + 200000 + 100000); - - assert.equal(estimator.forESDTNFTTransfer(80), 10000 + 80 * 3000 + 300000 + 800000); - assert.equal(estimator.forESDTNFTTransfer(100), 10000 + 100 * 3000 + 300000 + 800000); - - assert.equal(estimator.forMultiESDTNFTTransfer(80, 1), 10000 + 80 * 3000 + (400000 + 800000) * 1); - assert.equal(estimator.forMultiESDTNFTTransfer(80, 3), 10000 + 80 * 3000 + (400000 + 800000) * 3); - }); -}); diff --git a/src/gasEstimator.ts b/src/gasEstimator.ts deleted file mode 100644 index 716ddb27f..000000000 --- a/src/gasEstimator.ts +++ /dev/null @@ -1,74 +0,0 @@ -interface IGasConfiguration { - readonly minGasLimit: number; - readonly gasPerDataByte: number; - readonly gasCostESDTTransfer: number; - readonly gasCostESDTNFTTransfer: number; - readonly gasCostESDTNFTMultiTransfer: number; -} - -/** - * This is mirroring (on a best efforts basis) the network's gas configuration & gas schedule: - * - https://gateway.multiversx.com/network/config - * - https://github.com/multiversx/mx-chain-mainnet-config/tree/master/gasSchedules - * - https://github.com/multiversx/mx-chain-mainnet-config/blob/master/enableEpochs.toml#L200 - */ -export const DefaultGasConfiguration: IGasConfiguration = { - minGasLimit: 50000, - gasPerDataByte: 1500, - gasCostESDTTransfer: 200000, - gasCostESDTNFTTransfer: 200000, - gasCostESDTNFTMultiTransfer: 200000, -}; - -// Additional gas to account for eventual increases in gas requirements (thus avoid fast-breaking changes in clients of the library). -const ADDITIONAL_GAS_FOR_ESDT_TRANSFER = 100000; - -// Additional gas to account for extra blockchain operations (e.g. data movement (between accounts) for NFTs), -// and for eventual increases in gas requirements (thus avoid fast-breaking changes in clients of the library). -const ADDITIONAL_GAS_FOR_ESDT_NFT_TRANSFER = 800000; - -/** - * @deprecated This will be remove with the next release as the only place where it is used is a deprecated constructor. - */ -export class GasEstimator { - private readonly gasConfiguration: IGasConfiguration; - - constructor(gasConfiguration?: IGasConfiguration) { - this.gasConfiguration = gasConfiguration || DefaultGasConfiguration; - } - - forEGLDTransfer(dataLength: number) { - const gasLimit = this.gasConfiguration.minGasLimit + this.gasConfiguration.gasPerDataByte * dataLength; - - return gasLimit; - } - - forESDTTransfer(dataLength: number) { - const gasLimit = - this.gasConfiguration.minGasLimit + - this.gasConfiguration.gasCostESDTTransfer + - this.gasConfiguration.gasPerDataByte * dataLength + - ADDITIONAL_GAS_FOR_ESDT_TRANSFER; - - return gasLimit; - } - - forESDTNFTTransfer(dataLength: number) { - const gasLimit = - this.gasConfiguration.minGasLimit + - this.gasConfiguration.gasCostESDTNFTTransfer + - this.gasConfiguration.gasPerDataByte * dataLength + - ADDITIONAL_GAS_FOR_ESDT_NFT_TRANSFER; - - return gasLimit; - } - - forMultiESDTNFTTransfer(dataLength: number, numTransfers: number) { - const gasLimit = - this.gasConfiguration.minGasLimit + - (this.gasConfiguration.gasCostESDTNFTMultiTransfer + ADDITIONAL_GAS_FOR_ESDT_NFT_TRANSFER) * numTransfers + - this.gasConfiguration.gasPerDataByte * dataLength; - - return gasLimit; - } -} diff --git a/src/index.ts b/src/index.ts index 1816c81e1..9917a1971 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,6 @@ export * from "./converters"; export * from "./delegation"; export * from "./entrypoints"; export * from "./errors"; -export * from "./gasEstimator"; export * from "./interface"; export * from "./interfaceOfNetwork"; export * from "./logger"; @@ -24,9 +23,6 @@ export * from "./message"; export * from "./networkParams"; export * from "./networkProviders"; export * from "./relayed"; -export * from "./relayedTransactionV1Builder"; -export * from "./relayedTransactionV2Builder"; -export * from "./signableMessage"; export * from "./tokenManagement"; export * from "./tokens"; export * from "./transaction"; diff --git a/src/interface.ts b/src/interface.ts index a1e7fe422..a3fb3b2c2 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -83,11 +83,6 @@ export interface ITokenTransfer { valueOf(): BigNumber.Value; } -/** - * @deprecated Use {@link ITokenTransfer} instead. - */ -export type ITokenPayment = ITokenTransfer; - export interface ITransaction { sender: string; receiver: string; diff --git a/src/networkProviders/apiNetworkProvider.ts b/src/networkProviders/apiNetworkProvider.ts index 3891ca47a..d6445a096 100644 --- a/src/networkProviders/apiNetworkProvider.ts +++ b/src/networkProviders/apiNetworkProvider.ts @@ -1,4 +1,5 @@ import { ErrContractQuery, ErrNetworkProvider } from "../errors"; +import { ITransaction } from "../interface"; import { SmartContractQuery, SmartContractQueryResponse } from "../smartContractQuery"; import { TransactionOnNetwork, prepareTransactionForBroadcasting } from "../transactionOnNetwork"; import { TransactionStatus } from "../transactionStatus"; @@ -8,7 +9,7 @@ import { AccountOnNetwork, GuardianData } from "./accounts"; import { defaultAxiosConfig, defaultPagination } from "./config"; import { BaseUserAgent } from "./constants"; import { ContractQueryRequest } from "./contractQueryRequest"; -import { IAddress, INetworkProvider, IPagination, ITransaction, ITransactionNext } from "./interface"; +import { IAddress, INetworkProvider, IPagination } from "./interface"; import { NetworkConfig } from "./networkConfig"; import { NetworkGeneralStatistics } from "./networkGeneralStatistics"; import { NetworkProviderConfig } from "./networkProviderConfig"; @@ -146,17 +147,17 @@ export class ApiNetworkProvider implements INetworkProvider { return status; } - async sendTransaction(tx: ITransaction | ITransactionNext): Promise { + async sendTransaction(tx: ITransaction): Promise { const transaction = prepareTransactionForBroadcasting(tx); const response = await this.doPostGeneric("transactions", transaction); return response.txHash; } - async sendTransactions(txs: (ITransaction | ITransactionNext)[]): Promise { + async sendTransactions(txs: ITransaction[]): Promise { return await this.backingProxyNetworkProvider.sendTransactions(txs); } - async simulateTransaction(tx: ITransaction | ITransactionNext): Promise { + async simulateTransaction(tx: ITransaction): Promise { return await this.backingProxyNetworkProvider.simulateTransaction(tx); } diff --git a/src/networkProviders/interface.ts b/src/networkProviders/interface.ts index f1f3a1cf4..675f27db2 100644 --- a/src/networkProviders/interface.ts +++ b/src/networkProviders/interface.ts @@ -1,4 +1,4 @@ -import { ITransaction as ITransactionAsInSpecs } from "../interface"; +import { ITransaction } from "../interface"; import { SmartContractQuery, SmartContractQueryResponse } from "../smartContractQuery"; import { TransactionOnNetwork } from "../transactionOnNetwork"; import { TransactionStatus } from "../transactionStatus"; @@ -79,12 +79,12 @@ export interface INetworkProvider { /** * Broadcasts an already-signed transaction. */ - sendTransaction(tx: ITransaction | ITransactionNext): Promise; + sendTransaction(tx: ITransaction): Promise; /** * Broadcasts a list of already-signed transactions. */ - sendTransactions(txs: (ITransaction | ITransactionNext)[]): Promise; + sendTransactions(txs: ITransaction[]): Promise; /** * Simulates the processing of an already-signed transaction. @@ -136,15 +136,6 @@ export interface IPagination { size: number; } -export interface ITransaction { - toSendable(): any; -} - export interface IAddress { bech32(): string; } - -/** - * @deprecated This will be removed with the next release (replaced by the `ITransaction` interface from "src/interface.ts"). - */ -export type ITransactionNext = ITransactionAsInSpecs; diff --git a/src/networkProviders/providers.dev.net.spec.ts b/src/networkProviders/providers.dev.net.spec.ts index d1c121e2a..1b79d9d4e 100644 --- a/src/networkProviders/providers.dev.net.spec.ts +++ b/src/networkProviders/providers.dev.net.spec.ts @@ -1,10 +1,11 @@ import { AxiosHeaders } from "axios"; import { assert } from "chai"; import { Address } from "../address"; +import { ITransaction } from "../interface"; import { SmartContractQuery } from "../smartContractQuery"; import { TransactionOnNetwork } from "../transactionOnNetwork"; import { ApiNetworkProvider } from "./apiNetworkProvider"; -import { INetworkProvider, ITransactionNext } from "./interface"; +import { INetworkProvider } from "./interface"; import { ProxyNetworkProvider } from "./proxyNetworkProvider"; import { NonFungibleTokenOfAccountOnNetwork } from "./tokens"; @@ -196,43 +197,46 @@ describe("test network providers on devnet: Proxy and API", function () { const txs = [ { - toSendable: function () { - return { - nonce: 42, - value: "1", - receiver: "erd1testnlersh4z0wsv8kjx39me4rmnvjkwu8dsaea7ukdvvc9z396qykv7z7", - sender: "erd15x2panzqvfxul2lvstfrmdcl5t4frnsylfrhng8uunwdssxw4y9succ9sq", - gasPrice: 1000000000, - gasLimit: 50000, - chainID: "D", - version: 1, - signature: - "c8eb539e486db7d703d8c70cab3b7679113f77c4685d8fcc94db027ceacc6b8605115034355386dffd7aa12e63dbefa03251a2f1b1d971f52250187298d12900", - }; - }, + nonce: 42n, + value: 1n, + receiver: "erd1testnlersh4z0wsv8kjx39me4rmnvjkwu8dsaea7ukdvvc9z396qykv7z7", + sender: "erd15x2panzqvfxul2lvstfrmdcl5t4frnsylfrhng8uunwdssxw4y9succ9sq", + data: new Uint8Array(Buffer.from("test")), + gasPrice: 1000000000n, + gasLimit: 50000n, + chainID: "D", + version: 1, + signature: new Uint8Array( + Buffer.from( + "c8eb539e486db7d703d8c70cab3b7679113f77c4685d8fcc94db027ceacc6b8605115034355386dffd7aa12e63dbefa03251a2f1b1d971f52250187298d12900", + ), + ), + senderUsername: "", + receiverUsername: "", + guardian: "", + guardianSignature: new Uint8Array(), + options: 0, }, { - toSendable: function () { - return { - nonce: 43, - value: "1", - receiver: "erd1testnlersh4z0wsv8kjx39me4rmnvjkwu8dsaea7ukdvvc9z396qykv7z7", - sender: "erd15x2panzqvfxul2lvstfrmdcl5t4frnsylfrhng8uunwdssxw4y9succ9sq", - gasPrice: 1000000000, - gasLimit: 50000, - chainID: "D", - version: 1, - signature: - "9c4c22d0ae1b5a10c39583a5ab9020b00b27aa69d4ac8ab4922620dbf0df4036ed890f9946d38a9d0c85d6ac485c0d9b2eac0005e752f249fd0ad863b0471d02", - }; - }, - }, - { - toSendable: function () { - return { - nonce: 44, - }; - }, + nonce: 43n, + value: 1n, + receiver: "erd1testnlersh4z0wsv8kjx39me4rmnvjkwu8dsaea7ukdvvc9z396qykv7z7", + sender: "erd15x2panzqvfxul2lvstfrmdcl5t4frnsylfrhng8uunwdssxw4y9succ9sq", + gasPrice: 1000000000n, + gasLimit: 50000n, + chainID: "D", + version: 1, + signature: new Uint8Array( + Buffer.from( + "9c4c22d0ae1b5a10c39583a5ab9020b00b27aa69d4ac8ab4922620dbf0df4036ed890f9946d38a9d0c85d6ac485c0d9b2eac0005e752f249fd0ad863b0471d02", + ), + ), + senderUsername: "", + receiverUsername: "", + guardian: "", + guardianSignature: new Uint8Array(), + options: 0, + data: new Uint8Array(), }, ]; @@ -408,27 +412,10 @@ describe("test network providers on devnet: Proxy and API", function () { assert.deepEqual(proxyResponse.logs.events[0].additionalData, [Buffer.from("dGVzdA==", "base64")]); }); - it("should send both `Transaction` and `TransactionNext`", async function () { + it("should send both `Transaction` ", async function () { this.timeout(50000); - const transaction = { - toSendable: function () { - return { - nonce: 7, - value: "0", - receiver: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - sender: "erd1zztjf9fhwvuvquzsllknq4qcmffwad6n0hjtn5dyzytr5tgz7uas0mkgrq", - gasPrice: 1000000000, - gasLimit: 50000, - chainID: "D", - version: 2, - signature: - "149f1d8296efcb9489c5b3142ae659aacfa3a7daef3645f1d3747a96dc9cee377070dd8b83b322997c15ba3c305ac18daaee0fd25760eba334b14a9272b34802", - }; - }, - }; - - const transactionNext: ITransactionNext = { + const transaction: ITransaction = { nonce: BigInt(8), value: BigInt(0), receiver: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", @@ -449,13 +436,10 @@ describe("test network providers on devnet: Proxy and API", function () { options: 0, }; - const apiLegacyTxHash = await apiProvider.sendTransaction(transaction); - const apiTxNextHash = await apiProvider.sendTransaction(transactionNext); + const apiTxNextHash = await apiProvider.sendTransaction(transaction); - const proxyLegacyTxHash = await proxyProvider.sendTransaction(transaction); - const proxyTxNextHash = await proxyProvider.sendTransaction(transactionNext); + const proxyTxNextHash = await proxyProvider.sendTransaction(transaction); - assert.equal(apiLegacyTxHash, proxyLegacyTxHash); assert.equal(apiTxNextHash, proxyTxNextHash); }); }); diff --git a/src/networkProviders/proxyNetworkProvider.ts b/src/networkProviders/proxyNetworkProvider.ts index 1c2cbedef..855f391ff 100644 --- a/src/networkProviders/proxyNetworkProvider.ts +++ b/src/networkProviders/proxyNetworkProvider.ts @@ -1,4 +1,5 @@ import { ErrContractQuery, ErrNetworkProvider } from "../errors"; +import { ITransaction } from "../interface"; import { SmartContractQuery, SmartContractQueryResponse } from "../smartContractQuery"; import { TransactionOnNetwork, prepareTransactionForBroadcasting } from "../transactionOnNetwork"; import { TransactionStatus } from "../transactionStatus"; @@ -7,7 +8,7 @@ import { AccountOnNetwork, GuardianData } from "./accounts"; import { defaultAxiosConfig } from "./config"; import { BaseUserAgent, EsdtContractAddress } from "./constants"; import { ContractQueryRequest } from "./contractQueryRequest"; -import { IAddress, INetworkProvider, IPagination, ITransaction, ITransactionNext } from "./interface"; +import { IAddress, INetworkProvider, IPagination } from "./interface"; import { NetworkConfig } from "./networkConfig"; import { NetworkGeneralStatistics } from "./networkGeneralStatistics"; import { NetworkProviderConfig } from "./networkProviderConfig"; @@ -134,13 +135,13 @@ export class ProxyNetworkProvider implements INetworkProvider { return status; } - async sendTransaction(tx: ITransaction | ITransactionNext): Promise { + async sendTransaction(tx: ITransaction): Promise { const transaction = prepareTransactionForBroadcasting(tx); const response = await this.doPostGeneric("transaction/send", transaction); return response.txHash; } - async sendTransactions(txs: (ITransaction | ITransactionNext)[]): Promise { + async sendTransactions(txs: ITransaction[]): Promise { const data = txs.map((tx) => prepareTransactionForBroadcasting(tx)); const response = await this.doPostGeneric("transaction/send-multiple", data); @@ -153,7 +154,7 @@ export class ProxyNetworkProvider implements INetworkProvider { return hashes; } - async simulateTransaction(tx: ITransaction | ITransactionNext): Promise { + async simulateTransaction(tx: ITransaction): Promise { const transaction = prepareTransactionForBroadcasting(tx); const response = await this.doPostGeneric("transaction/simulate", transaction); return response; diff --git a/src/relayedTransactionV1Builder.spec.ts b/src/relayedTransactionV1Builder.spec.ts deleted file mode 100644 index 018ba6b04..000000000 --- a/src/relayedTransactionV1Builder.spec.ts +++ /dev/null @@ -1,260 +0,0 @@ -import { assert } from "chai"; -import { Address } from "./address"; -import * as errors from "./errors"; -import { TransactionOptions, TransactionVersion } from "./networkParams"; -import { RelayedTransactionV1Builder } from "./relayedTransactionV1Builder"; -import { TestWallet, loadTestWallets } from "./testutils"; -import { TokenTransfer } from "./tokens"; -import { Transaction } from "./transaction"; -import { TransactionPayload } from "./transactionPayload"; - -describe("test relayed v1 transaction builder", function () { - let alice: TestWallet, bob: TestWallet, carol: TestWallet, grace: TestWallet, frank: TestWallet; - - before(async function () { - ({ alice, bob, carol, grace, frank } = await loadTestWallets()); - }); - - it("should throw exception if args were not set", async function () { - const builder = new RelayedTransactionV1Builder(); - assert.throw(() => builder.build(), errors.ErrInvalidRelayedV1BuilderArguments); - - const innerTx = new Transaction({ - nonce: 15, - sender: alice.address, - receiver: Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"), - gasLimit: 10000000, - chainID: "1", - data: new TransactionPayload("getContractConfig"), - }); - builder.setInnerTransaction(innerTx); - assert.throw(() => builder.build(), errors.ErrInvalidRelayedV1BuilderArguments); - - const networkConfig = { - MinGasLimit: 50_000, - GasPerDataByte: 1_500, - GasPriceModifier: 0.01, - ChainID: "T", - }; - builder.setNetworkConfig(networkConfig); - assert.throw(() => builder.build(), errors.ErrInvalidRelayedV1BuilderArguments); - - builder.setRelayerAddress(alice.getAddress()); - assert.doesNotThrow(() => builder.build()); - }); - - it("should compute relayed v1 transaction", async function () { - const networkConfig = { - MinGasLimit: 50_000, - GasPerDataByte: 1_500, - GasPriceModifier: 0.01, - ChainID: "T", - }; - - const innerTx = new Transaction({ - nonce: 198, - sender: bob.address, - receiver: Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"), - gasLimit: 60000000, - chainID: networkConfig.ChainID, - data: new TransactionPayload("getContractConfig"), - }); - - innerTx.applySignature(await bob.signer.sign(innerTx.serializeForSigning())); - - const builder = new RelayedTransactionV1Builder(); - const relayedTxV1 = builder - .setInnerTransaction(innerTx) - .setRelayerNonce(2627) - .setNetworkConfig(networkConfig) - .setRelayerAddress(alice.address) - .build(); - - relayedTxV1.applySignature(await alice.signer.sign(relayedTxV1.serializeForSigning())); - - assert.equal(relayedTxV1.getNonce().valueOf(), 2627); - assert.equal( - relayedTxV1.getData().toString(), - "relayedTx@7b226e6f6e6365223a3139382c2273656e646572223a2267456e574f65576d6d413063306a6b71764d354241707a61644b46574e534f69417643575163776d4750673d222c227265636569766572223a22414141414141414141414141415141414141414141414141414141414141414141414141414141432f2f383d222c2276616c7565223a302c226761735072696365223a313030303030303030302c226761734c696d6974223a36303030303030302c2264617461223a225a3256305132397564484a68593352446232356d6157633d222c227369676e6174757265223a2272525455544858677a4273496e4f6e454b6b7869642b354e66524d486e33534948314673746f577352434c434b3258514c41614f4e704449346531476173624c5150616130566f364144516d4f2b52446b6f364a43413d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a327d", - ); - assert.equal( - relayedTxV1.getSignature().toString("hex"), - "128e7cdc14c2b9beee2f3ff7a7fa5d1f5ef31a654a0c92e223c90ab28265fa277d306f23a06536248cf9573e828017004fb639617fade4d68a37524aafca710d", - ); - }); - - it("should compute relayed v1 transaction (with usernames)", async function () { - const networkConfig = { - MinGasLimit: 50_000, - GasPerDataByte: 1_500, - GasPriceModifier: 0.01, - ChainID: "T", - }; - - const innerTx = new Transaction({ - nonce: 208, - value: TokenTransfer.egldFromAmount(1), - sender: carol.address, - receiver: alice.address, - senderUsername: "carol", - receiverUsername: "alice", - gasLimit: 50000, - chainID: networkConfig.ChainID, - }); - - innerTx.applySignature(await carol.signer.sign(innerTx.serializeForSigning())); - - const builder = new RelayedTransactionV1Builder(); - const relayedTxV1 = builder - .setInnerTransaction(innerTx) - .setRelayerNonce(715) - .setNetworkConfig(networkConfig) - .setRelayerAddress(frank.address) - .build(); - - relayedTxV1.applySignature(await frank.signer.sign(relayedTxV1.serializeForSigning())); - - assert.equal(relayedTxV1.getNonce().valueOf(), 715); - assert.equal( - relayedTxV1.getData().toString(), - "relayedTx@7b226e6f6e6365223a3230382c2273656e646572223a227371455656633553486b6c45344a717864556e59573068397a536249533141586f3534786f32634969626f3d222c227265636569766572223a2241546c484c76396f686e63616d433877673970645168386b77704742356a6949496f3349484b594e6165453d222c2276616c7565223a313030303030303030303030303030303030302c226761735072696365223a313030303030303030302c226761734c696d6974223a35303030302c2264617461223a22222c227369676e6174757265223a226a33427a6469554144325963517473576c65707663664a6f75657a48573063316b735a424a4d6339573167435450512b6870636759457858326f6f367a4b5654347464314b4b6f79783841526a346e336474576c44413d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c22736e64557365724e616d65223a22593246796232773d222c22726376557365724e616d65223a22595778705932553d227d", - ); - assert.equal( - relayedTxV1.getSignature().toString("hex"), - "3787d640e5a579e7977a4a1bcdd435ad11855632fa4a414a06fbf8355692d1a58d76ef0adbdd6ccd6bd3c329f36bd53c180d4873ec1a6c558e659aeb9ab92d00", - ); - }); - - it("should compute relayed v1 transaction with big value", async function () { - const networkConfig = { - MinGasLimit: 50_000, - GasPerDataByte: 1_500, - GasPriceModifier: 0.01, - ChainID: "T", - }; - - const innerTx = new Transaction({ - nonce: 208, - value: TokenTransfer.egldFromAmount(1999999), - sender: carol.address, - receiver: alice.address, - senderUsername: "carol", - receiverUsername: "alice", - gasLimit: 50000, - chainID: networkConfig.ChainID, - }); - - innerTx.applySignature(await carol.signer.sign(innerTx.serializeForSigning())); - - const builder = new RelayedTransactionV1Builder(); - const relayedTxV1 = builder - .setInnerTransaction(innerTx) - .setRelayerNonce(715) - .setNetworkConfig(networkConfig) - .setRelayerAddress(frank.address) - .build(); - - relayedTxV1.applySignature(await frank.signer.sign(relayedTxV1.serializeForSigning())); - - assert.equal(relayedTxV1.getNonce().valueOf(), 715); - assert.equal( - relayedTxV1.getData().toString(), - "relayedTx@7b226e6f6e6365223a3230382c2273656e646572223a227371455656633553486b6c45344a717864556e59573068397a536249533141586f3534786f32634969626f3d222c227265636569766572223a2241546c484c76396f686e63616d433877673970645168386b77704742356a6949496f3349484b594e6165453d222c2276616c7565223a313939393939393030303030303030303030303030303030302c226761735072696365223a313030303030303030302c226761734c696d6974223a35303030302c2264617461223a22222c227369676e6174757265223a22594661677972512f726d614c7333766e7159307657553858415a7939354b4e31725738347a4f764b62376c7a3773576e2f566a546d68704378774d682b7261314e444832574d6f3965507648304f79427453776a44773d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c22736e64557365724e616d65223a22593246796232773d222c22726376557365724e616d65223a22595778705932553d227d", - ); - assert.equal( - relayedTxV1.getSignature().toString("hex"), - "c0fb5cf8c0a413d6988ba35dc279c63f8849572c5f23b1cab36dcc50952dc3ed9da01068d6ac0cbde7e14167bfc2eca5164d5c2154c89eb313c9c596e3f8b801", - ); - }); - - it("should compute guarded inner Tx - relayed v1 transaction", async function () { - const networkConfig = { - MinGasLimit: 50_000, - GasPerDataByte: 1_500, - GasPriceModifier: 0.01, - ChainID: "T", - }; - - const innerTx = new Transaction({ - nonce: 198, - sender: bob.address, - receiver: Address.fromBech32("erd1qqqqqqqqqqqqqpgq54tsxmej537z9leghvp69hfu4f8gg5eu396q83gnnz"), - gasLimit: 60000000, - chainID: networkConfig.ChainID, - data: new TransactionPayload("getContractConfig"), - guardian: grace.address, - version: TransactionVersion.withTxOptions(), - options: TransactionOptions.withOptions({ guarded: true }), - }); - - innerTx.applySignature(await bob.signer.sign(innerTx.serializeForSigning())); - innerTx.applyGuardianSignature(await grace.signer.sign(innerTx.serializeForSigning())); - - const builder = new RelayedTransactionV1Builder(); - const relayedTxV1 = builder - .setInnerTransaction(innerTx) - .setRelayerNonce(2627) - .setNetworkConfig(networkConfig) - .setRelayerAddress(alice.address) - .build(); - - relayedTxV1.applySignature(await alice.signer.sign(relayedTxV1.serializeForSigning())); - - assert.equal(relayedTxV1.getNonce().valueOf(), 2627); - assert.equal( - relayedTxV1.getData().toString(), - "relayedTx@7b226e6f6e6365223a3139382c2273656e646572223a2267456e574f65576d6d413063306a6b71764d354241707a61644b46574e534f69417643575163776d4750673d222c227265636569766572223a22414141414141414141414146414b565841323879704877692f79693741364c64504b704f68464d386958513d222c2276616c7565223a302c226761735072696365223a313030303030303030302c226761734c696d6974223a36303030303030302c2264617461223a225a3256305132397564484a68593352446232356d6157633d222c227369676e6174757265223a224b4b78324f33383655725135416b4f465258307578327933446a384853334b373038487174344668377161557669424550716c45614e746e6158706a6f2f333651476d4a456934784435457a6c6f4f677a634d4442773d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c226f7074696f6e73223a322c22677561726469616e223a22486f714c61306e655733766843716f56696c70715372744c5673774939535337586d7a563868477450684d3d222c22677561726469616e5369676e6174757265223a222b5431526f4833625a792f54423177342b6a365155477258645637457577553073753948646551626453515269463953757a686d634b705463526d58595252366c534c6652394931624d7134674730436538363741513d3d227d", - ); - assert.equal( - relayedTxV1.getSignature().toString("hex"), - "39cff9d5100e290fbc7361cb6e2402261caf864257b4116f150e0c61e7869155dff8361fa5449431eb7a8ed847c01ba9b3b5ebafe5fac1a3d40c64829d827e00", - ); - }); - - it("should compute guarded inner tx and guarded relayed v1 transaction", async function () { - const networkConfig = { - MinGasLimit: 50_000, - GasPerDataByte: 1_500, - GasPriceModifier: 0.01, - ChainID: "T", - }; - - const innerTx = new Transaction({ - nonce: 198, - sender: bob.address, - receiver: Address.fromBech32("erd1qqqqqqqqqqqqqpgq54tsxmej537z9leghvp69hfu4f8gg5eu396q83gnnz"), - gasLimit: 60000000, - chainID: networkConfig.ChainID, - data: new TransactionPayload("addNumber"), - guardian: grace.address, - version: TransactionVersion.withTxOptions(), - options: TransactionOptions.withOptions({ guarded: true }), - }); - - innerTx.applySignature(await bob.signer.sign(innerTx.serializeForSigning())); - innerTx.applyGuardianSignature(await grace.signer.sign(innerTx.serializeForSigning())); - const builder = new RelayedTransactionV1Builder(); - const relayedTxV1 = builder - .setInnerTransaction(innerTx) - .setRelayerNonce(2627) - .setNetworkConfig(networkConfig) - .setRelayerAddress(alice.address) - .setRelayedTransactionVersion(TransactionVersion.withTxOptions()) - .setRelayedTransactionOptions(TransactionOptions.withOptions({ guarded: true })) - .setRelayedTransactionGuardian(frank.address) - .build(); - - relayedTxV1.applySignature(await alice.signer.sign(relayedTxV1.serializeForSigning())); - relayedTxV1.applyGuardianSignature(await frank.signer.sign(relayedTxV1.serializeForSigning())); - - assert.equal(relayedTxV1.getNonce().valueOf(), 2627); - assert.equal( - relayedTxV1.getData().toString(), - "relayedTx@7b226e6f6e6365223a3139382c2273656e646572223a2267456e574f65576d6d413063306a6b71764d354241707a61644b46574e534f69417643575163776d4750673d222c227265636569766572223a22414141414141414141414146414b565841323879704877692f79693741364c64504b704f68464d386958513d222c2276616c7565223a302c226761735072696365223a313030303030303030302c226761734c696d6974223a36303030303030302c2264617461223a225957526b546e5674596d5679222c227369676e6174757265223a223469724d4b4a656d724d375174344e7635487633544c44683775654779487045564c4371674a3677652f7a662b746a4933354975573452633458543451533433475333356158386c6a533834324a38426854645043673d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c226f7074696f6e73223a322c22677561726469616e223a22486f714c61306e655733766843716f56696c70715372744c5673774939535337586d7a563868477450684d3d222c22677561726469616e5369676e6174757265223a2270424754394e674a78307539624c56796b654d78786a454865374269696c37764932324a46676f32787a6e2f496e3032463769546563356b44395045324f747065386c475335412b532f4a36417762576834446744673d3d227d", - ); - assert.equal( - relayedTxV1.getSignature().toString("hex"), - "8ede1bbeed96b102344dffeac12c2592c62b7313cdeb132e8c8bf11d2b1d3bb8189d257a6dbcc99e222393d9b9ec77656c349dae97a32e68bdebd636066bf706", - ); - }); -}); diff --git a/src/relayedTransactionV1Builder.ts b/src/relayedTransactionV1Builder.ts deleted file mode 100644 index 52a48262d..000000000 --- a/src/relayedTransactionV1Builder.ts +++ /dev/null @@ -1,173 +0,0 @@ -import { Address } from "./address"; -import { ErrInvalidRelayedV1BuilderArguments } from "./errors"; -import { IAddress, INonce } from "./interface"; -import { INetworkConfig } from "./interfaceOfNetwork"; -import { TransactionOptions, TransactionVersion } from "./networkParams"; -import { Transaction } from "./transaction"; -import { TransactionPayload } from "./transactionPayload"; - -const JSONbig = require("json-bigint"); - -/** - * @deprecated Use {@link RelayedTransactionsFactory} instead. - */ -export class RelayedTransactionV1Builder { - innerTransaction: Transaction | undefined; - relayerAddress: IAddress | undefined; - relayerNonce: INonce | undefined; - netConfig: INetworkConfig | undefined; - relayedTransactionOptions: TransactionOptions | undefined; - relayedTransactionVersion: TransactionVersion | undefined; - relayedTransactionGuardian: IAddress | undefined; - - /** - * Sets the inner transaction to be used. It has to be already signed. - * - * @param {Transaction} transaction The inner transaction to be used - */ - setInnerTransaction(transaction: Transaction): RelayedTransactionV1Builder { - this.innerTransaction = transaction; - return this; - } - - /** - * Sets the network config to be used for building the relayed v1 transaction - * - * @param {INetworkConfig} netConfig The network configuration to be used - */ - setNetworkConfig(netConfig: INetworkConfig): RelayedTransactionV1Builder { - this.netConfig = netConfig; - return this; - } - - /** - * Sets the address of the relayer (the one that will actually pay the fee) - * - * @param relayerAddress - */ - setRelayerAddress(relayerAddress: IAddress): RelayedTransactionV1Builder { - this.relayerAddress = relayerAddress; - return this; - } - - /** - * (optional) Sets the nonce of the relayer - * - * @param relayerNonce - */ - setRelayerNonce(relayerNonce: INonce): RelayedTransactionV1Builder { - this.relayerNonce = relayerNonce; - return this; - } - - /** - * (optional) Sets the version of the relayed transaction - * - * @param relayedTxVersion - */ - setRelayedTransactionVersion(relayedTxVersion: TransactionVersion): RelayedTransactionV1Builder { - this.relayedTransactionVersion = relayedTxVersion; - return this; - } - - /** - * (optional) Sets the options of the relayed transaction - * - * @param relayedTxOptions - */ - setRelayedTransactionOptions(relayedTxOptions: TransactionOptions): RelayedTransactionV1Builder { - this.relayedTransactionOptions = relayedTxOptions; - return this; - } - - /** - * (optional) Sets the guardian of the relayed transaction - * - * @param relayedTxGuardian - */ - setRelayedTransactionGuardian(relayedTxGuardian: IAddress): RelayedTransactionV1Builder { - this.relayedTransactionGuardian = relayedTxGuardian; - return this; - } - - /** - * Tries to build the relayed v1 transaction based on the previously set fields - * - * @throws ErrInvalidRelayedV1BuilderArguments - * @return Transaction - */ - build(): Transaction { - if ( - !this.innerTransaction || - !this.netConfig || - !this.relayerAddress || - !this.innerTransaction.getSignature() - ) { - throw new ErrInvalidRelayedV1BuilderArguments(); - } - - const serializedTransaction = this.prepareInnerTransaction(); - const data = `relayedTx@${Buffer.from(serializedTransaction).toString("hex")}`; - const payload = new TransactionPayload(data); - - const gasLimit = - this.netConfig.MinGasLimit + - this.netConfig.GasPerDataByte * payload.length() + - this.innerTransaction.getGasLimit().valueOf(); - let relayedTransaction = new Transaction({ - nonce: this.relayerNonce, - sender: this.relayerAddress, - receiver: this.innerTransaction.getSender(), - value: 0, - gasLimit: gasLimit, - data: payload, - chainID: this.netConfig.ChainID, - version: this.relayedTransactionVersion, - options: this.relayedTransactionOptions, - guardian: this.relayedTransactionGuardian, - }); - - if (this.relayerNonce) { - relayedTransaction.setNonce(this.relayerNonce); - } - - return relayedTransaction; - } - - private prepareInnerTransaction(): string { - if (!this.innerTransaction) { - return ""; - } - - const txObject = { - nonce: this.innerTransaction.getNonce().valueOf(), - sender: new Address(this.innerTransaction.getSender().bech32()).pubkey().toString("base64"), - receiver: new Address(this.innerTransaction.getReceiver().bech32()).pubkey().toString("base64"), - value: BigInt(this.innerTransaction.getValue().toString()), - gasPrice: this.innerTransaction.getGasPrice().valueOf(), - gasLimit: this.innerTransaction.getGasLimit().valueOf(), - data: this.innerTransaction.getData().valueOf().toString("base64"), - signature: this.innerTransaction.getSignature().toString("base64"), - chainID: Buffer.from(this.innerTransaction.getChainID().valueOf()).toString("base64"), - version: this.innerTransaction.getVersion().valueOf(), - options: - this.innerTransaction.getOptions().valueOf() == 0 - ? undefined - : this.innerTransaction.getOptions().valueOf(), - guardian: this.innerTransaction.getGuardian().bech32() - ? new Address(this.innerTransaction.getGuardian().bech32()).pubkey().toString("base64") - : undefined, - guardianSignature: this.innerTransaction.getGuardianSignature().toString("hex") - ? this.innerTransaction.getGuardianSignature().toString("base64") - : undefined, - sndUserName: this.innerTransaction.getSenderUsername() - ? Buffer.from(this.innerTransaction.getSenderUsername()).toString("base64") - : undefined, - rcvUserName: this.innerTransaction.getReceiverUsername() - ? Buffer.from(this.innerTransaction.getReceiverUsername()).toString("base64") - : undefined, - }; - - return JSONbig.stringify(txObject); - } -} diff --git a/src/relayedTransactionV2Builder.spec.ts b/src/relayedTransactionV2Builder.spec.ts deleted file mode 100644 index cb4cd530c..000000000 --- a/src/relayedTransactionV2Builder.spec.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { loadTestWallets, TestWallet } from "./testutils"; -import { RelayedTransactionV2Builder } from "./relayedTransactionV2Builder"; -import { Address } from "./address"; -import { TransactionPayload } from "./transactionPayload"; -import { assert } from "chai"; -import { Transaction } from "./transaction"; -import * as errors from "./errors"; - -describe("test relayed v2 transaction builder", function () { - let alice: TestWallet, bob: TestWallet; - - before(async function () { - ({ alice, bob } = await loadTestWallets()); - }); - - it("should throw exception if args were not set", async function () { - const builder = new RelayedTransactionV2Builder(); - assert.throw(() => builder.build(), errors.ErrInvalidRelayedV2BuilderArguments); - }); - - it("should throw exception if gas limit of the inner tx is not 0", async function () { - let builder = new RelayedTransactionV2Builder(); - - let networkConfig = { - MinGasLimit: 50_000, - GasPerDataByte: 1_500, - GasPriceModifier: 0.01, - ChainID: "T", - }; - - const innerTx = new Transaction({ - nonce: 15, - sender: alice.address, - receiver: Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"), - gasLimit: 10, - chainID: networkConfig.ChainID, - data: new TransactionPayload("getContractConfig"), - }); - builder = builder - .setNetworkConfig(networkConfig) - .setInnerTransactionGasLimit(10) - .setInnerTransaction(innerTx) - .setRelayerAddress(alice.address); - assert.throw(() => builder.build(), errors.ErrGasLimitShouldBe0ForInnerTransaction); - - innerTx.setGasLimit({ - valueOf: function () { - return 10; - }, - }); - builder = builder.setNetworkConfig(networkConfig).setInnerTransactionGasLimit(10).setInnerTransaction(innerTx); - assert.throw(() => builder.build(), errors.ErrGasLimitShouldBe0ForInnerTransaction); - }); - - it("should compute relayed v2 tx", async function () { - let networkConfig = { - MinGasLimit: 50_000, - GasPerDataByte: 1_500, - GasPriceModifier: 0.01, - ChainID: "T", - }; - - const innerTx = new Transaction({ - nonce: 15, - sender: bob.address, - receiver: Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"), - gasLimit: 0, - chainID: networkConfig.ChainID, - data: new TransactionPayload("getContractConfig"), - version: 2, - }); - - innerTx.applySignature(await bob.signer.sign(innerTx.serializeForSigning())); - - const builder = new RelayedTransactionV2Builder(); - const relayedTxV2 = builder - .setInnerTransaction(innerTx) - .setInnerTransactionGasLimit(60_000_000) - .setRelayerNonce(37) - .setNetworkConfig(networkConfig) - .setRelayerAddress(alice.getAddress()) - .build(); - - relayedTxV2.setSender(alice.address); - relayedTxV2.applySignature(await alice.signer.sign(relayedTxV2.serializeForSigning())); - - assert.equal(relayedTxV2.getNonce().valueOf(), 37); - assert.equal(relayedTxV2.getVersion().valueOf(), 2); - assert.equal( - relayedTxV2.getData().toString(), - "relayedTxV2@000000000000000000010000000000000000000000000000000000000002ffff@0f@676574436f6e7472616374436f6e666967@fc3ed87a51ee659f937c1a1ed11c1ae677e99629fae9cc289461f033e6514d1a8cfad1144ae9c1b70f28554d196bd6ba1604240c1c1dc19c959e96c1c3b62d0c", - ); - }); -}); diff --git a/src/relayedTransactionV2Builder.ts b/src/relayedTransactionV2Builder.ts deleted file mode 100644 index 54d1595b7..000000000 --- a/src/relayedTransactionV2Builder.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { AddressValue, ArgSerializer, BytesValue, U64Value } from "./abi"; -import { ErrGasLimitShouldBe0ForInnerTransaction, ErrInvalidRelayedV2BuilderArguments } from "./errors"; -import { IAddress, IGasLimit, INonce } from "./interface"; -import { INetworkConfig } from "./interfaceOfNetwork"; -import { Transaction } from "./transaction"; -import { TransactionPayload } from "./transactionPayload"; - -/** - * @deprecated Use {@link RelayedTransactionsFactory} instead. - */ -export class RelayedTransactionV2Builder { - innerTransaction: Transaction | undefined; - innerTransactionGasLimit: IGasLimit | undefined; - relayerAddress: IAddress | undefined; - relayerNonce: INonce | undefined; - netConfig: INetworkConfig | undefined; - - /** - * Sets the inner transaction to be used. It has to be already signed and with gasLimit set to 0. These checks - * are performed on the build() method - * - * @param {Transaction} transaction The inner transaction to be used - */ - setInnerTransaction(transaction: Transaction): RelayedTransactionV2Builder { - this.innerTransaction = transaction; - return this; - } - - /** - * Sets the gas limit to be used for the SC Call inside the inner transaction - * - * @param {IGasLimit} gasLimit The gas limit to be used. The inner transaction needs to have the gas limit set to 0, - * so this field will specify the gas to be used for the SC call of the inner transaction - */ - setInnerTransactionGasLimit(gasLimit: IGasLimit): RelayedTransactionV2Builder { - this.innerTransactionGasLimit = gasLimit; - return this; - } - - /** - * Sets the network config to be used for building the relayed v2 transaction - * - * @param {INetworkConfig} netConfig The network configuration to be used - */ - setNetworkConfig(netConfig: INetworkConfig): RelayedTransactionV2Builder { - this.netConfig = netConfig; - return this; - } - - /** - * Sets the address of the relayer (the one that will actually pay the fee) - * - * @param relayerAddress - */ - setRelayerAddress(relayerAddress: IAddress): RelayedTransactionV2Builder { - this.relayerAddress = relayerAddress; - return this; - } - - /** - * (optional) Sets the nonce of the relayer - * - * @param relayerNonce - */ - setRelayerNonce(relayerNonce: INonce): RelayedTransactionV2Builder { - this.relayerNonce = relayerNonce; - return this; - } - - /** - * Tries to build the relayed v2 transaction based on the previously set fields. - * It returns a transaction that isn't signed - * - * @throws ErrInvalidRelayedV2BuilderArguments - * @throws ErrGasLimitShouldBe0ForInnerTransaction - * @return Transaction - */ - build(): Transaction { - if ( - !this.innerTransaction || - !this.innerTransactionGasLimit || - !this.relayerAddress || - !this.netConfig || - !this.innerTransaction.getSignature() - ) { - throw new ErrInvalidRelayedV2BuilderArguments(); - } - if (this.innerTransaction.getGasLimit() != 0) { - throw new ErrGasLimitShouldBe0ForInnerTransaction(); - } - - const { argumentsString } = new ArgSerializer().valuesToString([ - new AddressValue(this.innerTransaction.getReceiver()), - new U64Value(this.innerTransaction.getNonce().valueOf()), - new BytesValue(this.innerTransaction.getData().valueOf()), - new BytesValue(this.innerTransaction.getSignature()), - ]); - - const data = `relayedTxV2@${argumentsString}`; - const payload = new TransactionPayload(data); - - let relayedTransaction = new Transaction({ - sender: this.relayerAddress, - receiver: this.innerTransaction.getSender(), - value: 0, - gasLimit: - this.innerTransactionGasLimit.valueOf() + - this.netConfig.MinGasLimit + - this.netConfig.GasPerDataByte * payload.length(), - data: payload, - chainID: this.netConfig.ChainID, - version: this.innerTransaction.getVersion(), - options: this.innerTransaction.getOptions(), - }); - - if (this.relayerNonce) { - relayedTransaction.setNonce(this.relayerNonce); - } - - return relayedTransaction; - } -} diff --git a/src/signableMessage.spec.ts b/src/signableMessage.spec.ts deleted file mode 100644 index 4480b66dc..000000000 --- a/src/signableMessage.spec.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { assert } from "chai"; -import { SignableMessage } from "./signableMessage"; -import { loadTestWallets, TestWallet } from "./testutils"; - -describe("test signable message", () => { - let alice: TestWallet; - before(async function () { - ({ alice } = await loadTestWallets()); - }); - it("should create signableMessage", async () => { - const sm = new SignableMessage({ - address: alice.address, - message: Buffer.from("test message", "ascii"), - signature: Buffer.from("a".repeat(128), "hex"), - signer: "ElrondWallet", - }); - - const jsonSM = sm.toJSON(); - - // We just test that the returned object contains what was passed and the hex values are prefixed with 0x - assert.deepEqual( - jsonSM, - { - address: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", - message: "0x74657374206d657373616765", - signature: - "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - version: 1, - signer: "ElrondWallet", - }, - "invalid signable message returned", - ); - }); -}); diff --git a/src/signableMessage.ts b/src/signableMessage.ts deleted file mode 100644 index 872407cf0..000000000 --- a/src/signableMessage.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { Address } from "./address"; -import { ISignature } from "./interface"; -import { interpretSignatureAsBuffer } from "./signature"; -import { MESSAGE_PREFIX } from "./constants"; -const createKeccakHash = require("keccak"); - -/** - * @deprecated Use {@link Message} instead. - */ -export class SignableMessage { - /** - * Actual message being signed. - */ - message: Buffer; - /** - * Signature obtained by a signer of type @param signer . - */ - signature: Buffer; - - /** - * Address of the wallet that performed the signing operation - */ - address: Address; - - /** - * Text representing the identifer for the application that signed the message - */ - signer: string; - - /** - * Number representing the signable message version - */ - version: number; - - public constructor(init?: Partial) { - this.message = Buffer.from([]); - this.signature = Buffer.from([]); - this.version = 1; - this.signer = "ErdJS"; - this.address = Address.empty(); - - Object.assign(this, init); - } - - serializeForSigning(): Buffer { - const messageSize = Buffer.from(this.message.length.toString()); - const signableMessage = Buffer.concat([messageSize, this.message]); - let bytesToHash = Buffer.concat([Buffer.from(MESSAGE_PREFIX), signableMessage]); - - return createKeccakHash("keccak256").update(bytesToHash).digest(); - } - - serializeForSigningRaw(): Buffer { - return Buffer.concat([this.getMessageSize(), this.message]); - } - - getSignature(): Buffer { - return this.signature; - } - - applySignature(signature: ISignature | Uint8Array) { - this.signature = interpretSignatureAsBuffer(signature); - } - - getMessageSize(): Buffer { - const messageSize = Buffer.alloc(4); - messageSize.writeUInt32BE(this.message.length, 0); - - return messageSize; - } - - toJSON(): object { - return { - address: this.address.bech32(), - message: "0x" + this.message.toString("hex"), - signature: "0x" + this.signature.toString("hex"), - version: this.version, - signer: this.signer, - }; - } -} diff --git a/src/testutils/mockNetworkProvider.ts b/src/testutils/mockNetworkProvider.ts index 1f4dc2281..b73f48d53 100644 --- a/src/testutils/mockNetworkProvider.ts +++ b/src/testutils/mockNetworkProvider.ts @@ -2,6 +2,7 @@ import { Address } from "../address"; import { AsyncTimer } from "../asyncTimer"; import * as errors from "../errors"; import { ErrMock } from "../errors"; +import { ITransaction } from "../interface"; import { IAccountOnNetwork } from "../interfaceOfNetwork"; import { AccountOnNetwork, @@ -14,7 +15,7 @@ import { NetworkStatus, NonFungibleTokenOfAccountOnNetwork, } from "../networkProviders"; -import { IAddress, INetworkProvider, IPagination, ITransaction, ITransactionNext } from "../networkProviders/interface"; +import { IAddress, INetworkProvider, IPagination } from "../networkProviders/interface"; import { SmartContractQuery, SmartContractQueryResponse } from "../smartContractQuery"; import { Transaction, TransactionHash } from "../transaction"; import { TransactionOnNetwork } from "../transactionOnNetwork"; @@ -87,7 +88,7 @@ export class MockNetworkProvider implements INetworkProvider { ): Promise { throw new Error("Method not implemented."); } - sendTransactions(_txs: (ITransaction | ITransactionNext)[]): Promise { + sendTransactions(_txs: ITransaction[]): Promise { throw new Error("Method not implemented."); } getDefinitionOfFungibleToken(_tokenIdentifier: string): Promise { diff --git a/src/testutils/wallets.ts b/src/testutils/wallets.ts index c5e77ccb8..0dac24a84 100644 --- a/src/testutils/wallets.ts +++ b/src/testutils/wallets.ts @@ -113,7 +113,7 @@ export class TestWallet { async sync(provider: IAccountFetcher) { let accountOnNetwork = await provider.getAccount(this.address); - this.account.update(accountOnNetwork); + this.account.nonce = accountOnNetwork.nonce; return this; } } diff --git a/src/tokenTransferBuilders.spec.ts b/src/tokenTransferBuilders.spec.ts deleted file mode 100644 index e3fd02add..000000000 --- a/src/tokenTransferBuilders.spec.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { assert } from "chai"; -import { Address } from "./address"; -import { TokenTransfer } from "./tokens"; -import { - ESDTNFTTransferPayloadBuilder, - ESDTTransferPayloadBuilder, - MultiESDTNFTTransferPayloadBuilder, -} from "./tokenTransferBuilders"; - -describe("test token transfer builders", () => { - it("should work with ESDT transfers", () => { - const transfer = TokenTransfer.fungibleFromAmount("COUNTER-8b028f", "100.00", 0); - const payload = new ESDTTransferPayloadBuilder().setPayment(transfer).build(); - assert.equal(payload.toString(), "ESDTTransfer@434f554e5445522d386230323866@64"); - }); - - it("should work with ESDTNFT transfers (NFT)", () => { - const transfer = TokenTransfer.nonFungible("ERDJS-38f249", 1); - const payload = new ESDTNFTTransferPayloadBuilder() - .setPayment(transfer) - .setDestination(new Address("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx")) - .build(); - - assert.equal( - payload.toString(), - "ESDTNFTTransfer@4552444a532d333866323439@01@01@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8", - ); - }); - - it("should work with ESDTNFT transfers (SFT)", () => { - const transfer = TokenTransfer.semiFungible("SEMI-9efd0f", 1, 5); - - const payload = new ESDTNFTTransferPayloadBuilder() - .setPayment(transfer) - .setDestination(new Address("erd1testnlersh4z0wsv8kjx39me4rmnvjkwu8dsaea7ukdvvc9z396qykv7z7")) - .build(); - - assert.equal( - payload.toString(), - "ESDTNFTTransfer@53454d492d396566643066@01@05@5e60b9ff2385ea27ba0c3da4689779a8f7364acee1db0ee7bee59ac660a28974", - ); - }); - - it("should work with Multi ESDTNFT transfers", () => { - const transferOne = TokenTransfer.nonFungible("ERDJS-38f249", 1); - const transferTwo = TokenTransfer.fungibleFromAmount("BAR-c80d29", "10.00", 18); - const payload = new MultiESDTNFTTransferPayloadBuilder() - .setPayments([transferOne, transferTwo]) - .setDestination(new Address("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th")) - .build(); - - assert.equal( - payload.toString(), - "MultiESDTNFTTransfer@0139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1@02@4552444a532d333866323439@01@01@4241522d633830643239@@8ac7230489e80000", - ); - }); -}); diff --git a/src/tokenTransferBuilders.ts b/src/tokenTransferBuilders.ts deleted file mode 100644 index d4b6d37ad..000000000 --- a/src/tokenTransferBuilders.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { AddressValue, ArgSerializer, BigUIntValue, BytesValue, TypedValue, U16Value, U64Value } from "./abi"; -import { Address } from "./address"; -import { IAddress, ITokenTransfer } from "./interface"; -import { TokenTransfer } from "./tokens"; -import { TransactionPayload } from "./transactionPayload"; - -/** - * @deprecated Use {@link TransferTransactionsFactory} instead. - */ -export class ESDTTransferPayloadBuilder { - payment: ITokenTransfer = TokenTransfer.fungibleFromAmount("", "0", 0); - - setPayment(payment: ITokenTransfer): ESDTTransferPayloadBuilder { - this.payment = payment; - return this; - } - - build(): TransactionPayload { - let args: TypedValue[] = [ - // The token identifier - BytesValue.fromUTF8(this.payment.tokenIdentifier), - // The transfered amount - new BigUIntValue(this.payment.valueOf()), - ]; - - let { argumentsString } = new ArgSerializer().valuesToString(args); - let data = `ESDTTransfer@${argumentsString}`; - return new TransactionPayload(data); - } -} - -/** - * @deprecated Use {@link TransferTransactionsFactory} instead. - */ -export class ESDTNFTTransferPayloadBuilder { - payment: ITokenTransfer = TokenTransfer.nonFungible("", 0); - destination: IAddress = Address.empty(); - - setPayment(payment: ITokenTransfer): ESDTNFTTransferPayloadBuilder { - this.payment = payment; - return this; - } - - setDestination(destination: IAddress): ESDTNFTTransferPayloadBuilder { - this.destination = destination; - return this; - } - - build(): TransactionPayload { - let args: TypedValue[] = [ - // The token identifier - BytesValue.fromUTF8(this.payment.tokenIdentifier), - // The nonce of the token - new U64Value(this.payment.nonce), - // The transferred quantity - new BigUIntValue(this.payment.valueOf()), - // The destination address - new AddressValue(this.destination), - ]; - - let { argumentsString } = new ArgSerializer().valuesToString(args); - let data = `ESDTNFTTransfer@${argumentsString}`; - return new TransactionPayload(data); - } -} - -/** - * @deprecated Use {@link TransferTransactionsFactory} instead. - */ -export class MultiESDTNFTTransferPayloadBuilder { - payments: ITokenTransfer[] = []; - destination: IAddress = Address.empty(); - - setPayments(payments: ITokenTransfer[]): MultiESDTNFTTransferPayloadBuilder { - this.payments = payments; - return this; - } - - setDestination(destination: IAddress): MultiESDTNFTTransferPayloadBuilder { - this.destination = destination; - return this; - } - - build(): TransactionPayload { - let args: TypedValue[] = [ - // The destination address - new AddressValue(this.destination), - // Number of tokens - new U16Value(this.payments.length), - ]; - - for (const payment of this.payments) { - args.push( - ...[ - // The token identifier - BytesValue.fromUTF8(payment.tokenIdentifier), - // The nonce of the token - new U64Value(payment.nonce), - // The transfered quantity - new BigUIntValue(payment.valueOf()), - ], - ); - } - - let { argumentsString } = new ArgSerializer().valuesToString(args); - let data = `MultiESDTNFTTransfer@${argumentsString}`; - return new TransactionPayload(data); - } -} diff --git a/src/tokens.ts b/src/tokens.ts index b01c5edfc..f8c4a364f 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -339,17 +339,3 @@ export class TokenComputer { function decodeUnsignedNumber(arg: Buffer): number { return arg.readUIntBE(0, arg.length); } - -/** - * @deprecated use {@link TokenTransfer} instead. - */ -export class TokenPayment extends TokenTransfer { - constructor(tokenIdentifier: string, nonce: number, amountAsBigInteger: BigNumber.Value, numDecimals: number) { - super({ - tokenIdentifier, - nonce, - amountAsBigInteger, - numDecimals, - }); - } -} diff --git a/src/transactionOnNetwork.ts b/src/transactionOnNetwork.ts index 10adef8c0..2a8ccbd5d 100644 --- a/src/transactionOnNetwork.ts +++ b/src/transactionOnNetwork.ts @@ -1,14 +1,10 @@ import { Address } from "./address"; -import { ITransaction, ITransactionNext } from "./networkProviders/interface"; +import { ITransaction } from "./interface"; import { TransactionLogs } from "./transactionLogs"; import { SmartContractResult } from "./transactionsOutcomeParsers"; import { TransactionStatus } from "./transactionStatus"; -export function prepareTransactionForBroadcasting(transaction: ITransaction | ITransactionNext): any { - if ("toSendable" in transaction) { - return transaction.toSendable(); - } - +export function prepareTransactionForBroadcasting(transaction: ITransaction): any { return { nonce: Number(transaction.nonce), value: transaction.value.toString(),