diff --git a/src/abi/interaction.ts b/src/abi/interaction.ts index 1b25b1b2..b07b7267 100644 --- a/src/abi/interaction.ts +++ b/src/abi/interaction.ts @@ -3,9 +3,9 @@ import { Address } from "../address"; import { Compatibility } from "../compatibility"; import { TRANSACTION_VERSION_DEFAULT } from "../constants"; import { IAddress, IChainID, IGasLimit, IGasPrice, INonce, ITokenTransfer, ITransactionValue } from "../interface"; +import { SmartContractTransactionsFactory } from "../smartContracts"; import { TokenTransfer } from "../tokens"; import { Transaction } from "../transaction"; -import { SmartContractTransactionsFactory } from "../transactionsFactories"; import { TransactionsFactoryConfig } from "../transactionsFactoryConfig"; import { ContractFunction } from "./function"; import { InteractionChecker } from "./interactionChecker"; @@ -98,8 +98,7 @@ export class Interaction { config: factoryConfig, }); - const transaction = factory.createTransactionForExecute({ - sender: this.sender, + const transaction = factory.createTransactionForExecute(this.sender, { contract: this.contract.getAddress(), function: this.function.valueOf(), gasLimit: BigInt(this.gasLimit.valueOf()), diff --git a/src/abi/smartContract.ts b/src/abi/smartContract.ts index 419b2510..c0b899c0 100644 --- a/src/abi/smartContract.ts +++ b/src/abi/smartContract.ts @@ -141,11 +141,10 @@ export class SmartContract implements ISmartContract { const bytecode = Buffer.from(code.toString(), "hex"); const metadataAsJson = this.getMetadataPropertiesAsObject(codeMetadata); - const transaction = factory.createTransactionForDeploy({ - sender: deployer, + const transaction = factory.createTransactionForDeploy(deployer, { bytecode: bytecode, gasLimit: BigInt(gasLimit.valueOf()), - arguments: initArguments, + arguments: initArguments ?? [], isUpgradeable: metadataAsJson.upgradeable, isReadable: metadataAsJson.readable, isPayable: metadataAsJson.payable, @@ -211,12 +210,11 @@ export class SmartContract implements ISmartContract { const bytecode = Uint8Array.from(Buffer.from(code.toString(), "hex")); const metadataAsJson = this.getMetadataPropertiesAsObject(codeMetadata); - const transaction = factory.createTransactionForUpgrade({ - sender: caller, + const transaction = factory.createTransactionForUpgrade(caller, { contract: this.getAddress(), bytecode: bytecode, gasLimit: BigInt(gasLimit.valueOf()), - arguments: initArguments, + arguments: initArguments ?? [], isUpgradeable: metadataAsJson.upgradeable, isReadable: metadataAsJson.readable, isPayable: metadataAsJson.payable, @@ -251,8 +249,7 @@ export class SmartContract implements ISmartContract { args = args || []; value = value || 0; - const transaction = factory.createTransactionForExecute({ - sender: caller, + const transaction = factory.createTransactionForExecute(caller, { contract: receiver ? receiver : this.getAddress(), function: func.toString(), gasLimit: BigInt(gasLimit.valueOf()), diff --git a/src/delegation/delegationTransactionsFactory.spec.ts b/src/delegation/delegationTransactionsFactory.spec.ts index 92f58b1e..7378f78e 100644 --- a/src/delegation/delegationTransactionsFactory.spec.ts +++ b/src/delegation/delegationTransactionsFactory.spec.ts @@ -1,7 +1,7 @@ import { assert } from "chai"; import { Address } from "../address"; import { DELEGATION_MANAGER_SC_ADDRESS_HEX } from "../constants"; -import { TransactionsFactoryConfig } from "../transactionsFactories/transactionsFactoryConfig"; +import { TransactionsFactoryConfig } from "../transactionsFactoryConfig"; import { ValidatorPublicKey } from "../wallet"; import { DelegationTransactionsFactory } from "./delegationTransactionsFactory"; @@ -15,8 +15,7 @@ describe("test delegation transactions factory", function () { const serviceFee = 10n; const value = 1250000000000000000000n; - const transaction = delegationFactory.createTransactionForNewDelegationContract({ - sender: sender, + const transaction = delegationFactory.createTransactionForNewDelegationContract(sender, { totalDelegationCap: delagationCap, serviceFee: serviceFee, amount: value, @@ -52,8 +51,7 @@ describe("test delegation transactions factory", function () { ), }; - const transaction = delegationFactory.createTransactionForAddingNodes({ - sender: sender, + const transaction = delegationFactory.createTransactionForAddingNodes(sender, { delegationContract: delegationContract, publicKeys: [publicKey], signedMessages: [mockMessage.getSignature()], @@ -81,8 +79,7 @@ describe("test delegation transactions factory", function () { }, }; - const transaction = delegationFactory.createTransactionForRemovingNodes({ - sender: sender, + const transaction = delegationFactory.createTransactionForRemovingNodes(sender, { delegationContract: delegationContract, publicKeys: [publicKey], }); @@ -104,8 +101,7 @@ describe("test delegation transactions factory", function () { }, }; - const transaction = delegationFactory.createTransactionForStakingNodes({ - sender: sender, + const transaction = delegationFactory.createTransactionForStakingNodes(sender, { delegationContract: delegationContract, publicKeys: [publicKey], }); @@ -127,8 +123,7 @@ describe("test delegation transactions factory", function () { }, }; - const transaction = delegationFactory.createTransactionForUnbondingNodes({ - sender: sender, + const transaction = delegationFactory.createTransactionForUnbondingNodes(sender, { delegationContract: delegationContract, publicKeys: [publicKey], }); @@ -151,8 +146,7 @@ describe("test delegation transactions factory", function () { }, }; - const transaction = delegationFactory.createTransactionForUnstakingNodes({ - sender: sender, + const transaction = delegationFactory.createTransactionForUnstakingNodes(sender, { delegationContract: delegationContract, publicKeys: [publicKey], }); @@ -175,8 +169,7 @@ describe("test delegation transactions factory", function () { }, }; - const transaction = delegationFactory.createTransactionForUnjailingNodes({ - sender: sender, + const transaction = delegationFactory.createTransactionForUnjailingNodes(sender, { delegationContract: delegationContract, publicKeys: [publicKey], amount: 25000000000000000000n, @@ -194,8 +187,7 @@ describe("test delegation transactions factory", function () { const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"); const serviceFee = 10n; - const transaction = delegationFactory.createTransactionForChangingServiceFee({ - sender: sender, + const transaction = delegationFactory.createTransactionForChangingServiceFee(sender, { delegationContract: delegationContract, serviceFee: serviceFee, }); @@ -212,8 +204,7 @@ describe("test delegation transactions factory", function () { const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"); const delegationCap = 5000000000000000000000n; - const transaction = delegationFactory.createTransactionForModifyingDelegationCap({ - sender: sender, + const transaction = delegationFactory.createTransactionForModifyingDelegationCap(sender, { delegationContract: delegationContract, delegationCap: delegationCap, }); @@ -229,8 +220,7 @@ describe("test delegation transactions factory", function () { const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"); const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"); - const transaction = delegationFactory.createTransactionForSettingAutomaticActivation({ - sender: sender, + const transaction = delegationFactory.createTransactionForSettingAutomaticActivation(sender, { delegationContract: delegationContract, }); @@ -245,8 +235,7 @@ describe("test delegation transactions factory", function () { const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"); const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"); - const transaction = delegationFactory.createTransactionForUnsettingAutomaticActivation({ - sender: sender, + const transaction = delegationFactory.createTransactionForUnsettingAutomaticActivation(sender, { delegationContract: delegationContract, }); @@ -261,8 +250,7 @@ describe("test delegation transactions factory", function () { const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"); const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"); - const transaction = delegationFactory.createTransactionForSettingCapCheckOnRedelegateRewards({ - sender: sender, + const transaction = delegationFactory.createTransactionForSettingCapCheckOnRedelegateRewards(sender, { delegationContract: delegationContract, }); @@ -277,8 +265,7 @@ describe("test delegation transactions factory", function () { const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"); const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"); - const transaction = delegationFactory.createTransactionForUnsettingCapCheckOnRedelegateRewards({ - sender: sender, + const transaction = delegationFactory.createTransactionForUnsettingCapCheckOnRedelegateRewards(sender, { delegationContract: delegationContract, }); @@ -293,8 +280,7 @@ describe("test delegation transactions factory", function () { const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"); const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"); - const transaction = delegationFactory.createTransactionForSettingMetadata({ - sender: sender, + const transaction = delegationFactory.createTransactionForSettingMetadata(sender, { delegationContract: delegationContract, name: "name", website: "website", diff --git a/src/entrypoints/entrypoints.spec.ts b/src/entrypoints/entrypoints.spec.ts index 77d92dfe..b4d63672 100644 --- a/src/entrypoints/entrypoints.spec.ts +++ b/src/entrypoints/entrypoints.spec.ts @@ -1,6 +1,6 @@ import { assert } from "chai"; import { readFileSync } from "fs"; -import { Account } from "../account"; +import { Account } from "../accounts/account"; import { Address } from "../address"; import { loadAbiRegistry, loadTestWallet, TestWallet } from "../testutils"; import { TransactionComputer } from "../transactionComputer"; @@ -20,15 +20,18 @@ describe("TestEntrypoint", () => { it("native transfer", async () => { const controller = entrypoint.createTransfersController(); - const sender = Account.fromPem(alicePem.pemFileText); + const sender = Account.newFromPem(alicePem.pemFileText); sender.nonce = 77777; - const transaction = await controller.createTransactionForTransfer(sender, { - nonce: BigInt(sender.getNonceThenIncrement().valueOf()), - receiver: sender.address, - nativeTransferAmount: BigInt(0), - data: Buffer.from("hello"), - }); + const transaction = await controller.createTransactionForTransfer( + sender, + BigInt(sender.getNonceThenIncrement().valueOf()), + { + receiver: sender.address, + nativeAmount: BigInt(0), + data: Buffer.from("hello"), + }, + ); assert.equal( Buffer.from(transaction.signature).toString("hex"), "69bc7d1777edd0a901e6cf94830475716205c5efdf2fd44d4be31badead59fc8418b34f0aa3b2c80ba14aed5edd30031757d826af58a1abb690a0bee89ba9309", @@ -38,19 +41,22 @@ describe("TestEntrypoint", () => { it("contract flow", async function () { this.timeout(30000); const abi = await loadAbiRegistry("src/testdata/adder.abi.json"); - const sender = Account.fromPem(alicePem.pemFileText); + const sender = Account.newFromPem(alicePem.pemFileText); const accountAddress = new Address(sender.address.bech32()); sender.nonce = await entrypoint.recallAccountNonce(accountAddress); const controller = entrypoint.createSmartContractController(abi); const bytecode = readFileSync("src/testdata/adder.wasm"); - const transaction = await controller.createTransactionForDeploy(sender, { - nonce: BigInt(sender.getNonceThenIncrement().valueOf()), - bytecode, - gasLimit: BigInt(10_000_000), - arguments: [0], - }); + const transaction = await controller.createTransactionForDeploy( + sender, + BigInt(sender.getNonceThenIncrement().valueOf()), + { + bytecode, + gasLimit: BigInt(10_000_000), + arguments: [0], + }, + ); const txHash = await entrypoint.sendTransaction(transaction); const outcome = await controller.awaitCompletedDeploy(txHash); @@ -59,13 +65,16 @@ describe("TestEntrypoint", () => { const contractAddress = Address.fromBech32(outcome.contracts[0].address); - const executeTransaction = await controller.createTransactionForExecute(sender, { - nonce: BigInt(sender.getNonceThenIncrement().valueOf()), - contract: contractAddress, - gasLimit: BigInt(10_000_000), - function: "add", - arguments: [7], - }); + const executeTransaction = await controller.createTransactionForExecute( + sender, + BigInt(sender.getNonceThenIncrement().valueOf()), + { + contract: contractAddress, + gasLimit: BigInt(10_000_000), + function: "add", + arguments: [7], + }, + ); const txHashExecute = await entrypoint.sendTransaction(executeTransaction); await entrypoint.awaitCompletedTransaction(txHashExecute); @@ -77,28 +86,30 @@ describe("TestEntrypoint", () => { it("create relayed transaction", async function () { const transferController = entrypoint.createTransfersController(); - const sender = Account.fromPem(alicePem.pemFileText); + const sender = Account.newFromPem(alicePem.pemFileText); sender.nonce = 77777; - const relayer = Account.fromPem(bobPem.pemFileText); + const relayer = Account.newFromPem(bobPem.pemFileText); relayer.nonce = 7; - const transaction = await transferController.createTransactionForTransfer(sender, { - nonce: BigInt(sender.getNonceThenIncrement().valueOf()), - receiver: sender.address, - data: Buffer.from("hello"), - }); + const transaction = await transferController.createTransactionForTransfer( + sender, + BigInt(sender.getNonceThenIncrement().valueOf()), + { + receiver: sender.address, + data: Buffer.from("hello"), + }, + ); const innerTransactionGasLimit = transaction.gasLimit; transaction.gasLimit = BigInt(0); transaction.signature = await sender.sign(txComputer.computeBytesForSigning(transaction)); const relayedController = entrypoint.createRelayedController(); - const relayedTransaction = relayedController.createRelayedV2Transaction( - relayer, - BigInt(relayer.getNonceThenIncrement().valueOf()), - transaction, + const relayedTransaction = relayedController.createRelayedV2Transaction(relayer, { + nonce: BigInt(relayer.getNonceThenIncrement().valueOf()), + innerTransaction: transaction, innerTransactionGasLimit, - ); + }); assert.equal((await relayedTransaction).chainID, "D"); }); diff --git a/src/entrypoints/entrypoints.ts b/src/entrypoints/entrypoints.ts index d38816f5..94205f1e 100644 --- a/src/entrypoints/entrypoints.ts +++ b/src/entrypoints/entrypoints.ts @@ -1,14 +1,14 @@ import { AbiRegistry } from "../abi"; +import { AccountController } from "../accountManagment"; import { IAccount } from "../accounts/interfaces"; import { Address } from "../address"; -import { AccountController } from "../controllers/accountController"; -import { DelegationController } from "../controllers/delegationController"; -import { TokenManagementController } from "../controllers/tokenManagementController"; +import { DelegationController } from "../delegation"; import { ErrInvalidNetworkProviderKind } from "../errors"; import { Message, MessageComputer } from "../message"; import { ApiNetworkProvider, ProxyNetworkProvider, TransactionOnNetwork } from "../networkProviders"; import { RelayedController } from "../relayed/relayedController"; import { SmartContractController } from "../smartContracts/smartContractController"; +import { TokenManagementController } from "../tokenManagement"; import { Transaction } from "../transaction"; import { TransactionComputer } from "../transactionComputer"; import { TransactionWatcher } from "../transactionWatcher"; @@ -86,27 +86,27 @@ class NetworkEntrypoint { } createDelegationController(): DelegationController { - return new DelegationController(this.chainId, this.networkProvider); + return new DelegationController({ chainID: this.chainId, networkProvider: this.networkProvider }); } createAccountController(): AccountController { - return new AccountController(this.chainId); + return new AccountController({ chainID: this.chainId }); } createRelayedController(): RelayedController { - return new RelayedController(this.chainId); + return new RelayedController({ chainID: this.chainId }); } createSmartContractController(abi?: AbiRegistry): SmartContractController { - return new SmartContractController(this.chainId, this.networkProvider, abi); + return new SmartContractController({ chainID: this.chainId, networkProvider: this.networkProvider, abi }); } createTokenManagementController(): TokenManagementController { - return new TokenManagementController(this.chainId, this.networkProvider); + return new TokenManagementController({ chainID: this.chainId, networkProvider: this.networkProvider }); } createTransfersController(): TransfersController { - return new TransfersController(this.chainId); + return new TransfersController({ chainID: this.chainId }); } } diff --git a/src/smartContracts/smartContractController.ts b/src/smartContracts/smartContractController.ts index 64949b02..2abdb2a8 100644 --- a/src/smartContracts/smartContractController.ts +++ b/src/smartContracts/smartContractController.ts @@ -8,11 +8,11 @@ import { INetworkProvider } from "../networkProviders/interface"; import { SmartContractQueriesController } from "../smartContractQueriesController"; import { Transaction } from "../transaction"; import { TransactionComputer } from "../transactionComputer"; -import { SmartContractTransactionsFactory } from "../transactionsFactories"; import { TransactionsFactoryConfig } from "../transactionsFactoryConfig"; import { SmartContractTransactionsOutcomeParser } from "../transactionsOutcomeParsers"; import { TransactionWatcher } from "../transactionWatcher"; import * as resources from "./resources"; +import { SmartContractTransactionsFactory } from "./smartContractTransactionsFactory"; export class SmartContractController { private factory: SmartContractTransactionsFactory; diff --git a/src/testutils/utils.ts b/src/testutils/utils.ts index 0b19c55a..aed900ae 100644 --- a/src/testutils/utils.ts +++ b/src/testutils/utils.ts @@ -1,7 +1,8 @@ import BigNumber from "bignumber.js"; import * as fs from "fs"; import { PathLike } from "fs"; -import { AbiRegistry, Code, SmartContract, TypedValue } from "../abi"; +import { AbiRegistry, Code, SmartContract } from "../abi"; +import { TypedValue } from "../abi/typesystem/types"; import { IChainID, IGasLimit } from "../interface"; import { Transaction } from "../transaction"; import { TransactionWatcher } from "../transactionWatcher"; diff --git a/src/tokenManagement/tokenManagementController.ts b/src/tokenManagement/tokenManagementController.ts index 4f7836e0..7b8cb085 100644 --- a/src/tokenManagement/tokenManagementController.ts +++ b/src/tokenManagement/tokenManagementController.ts @@ -5,11 +5,11 @@ import { INetworkProvider } from "../networkProviders/interface"; import { IESDTIssueOutcome } from "../tokenOperations"; import { Transaction } from "../transaction"; import { TransactionComputer } from "../transactionComputer"; -import { TokenManagementTransactionsFactory } from "../transactionsFactories"; import { TransactionsFactoryConfig } from "../transactionsFactoryConfig"; import { TokenManagementTransactionsOutcomeParser } from "../transactionsOutcomeParsers"; import { TransactionWatcher } from "../transactionWatcher"; import * as resources from "./resources"; +import { TokenManagementTransactionsFactory } from "./tokenManagementTransactionsFactory"; export class TokenManagementController { private factory: TokenManagementTransactionsFactory; diff --git a/src/transactionBuilder.ts b/src/transactionBuilder.ts index 6c163e81..d4b684a6 100644 --- a/src/transactionBuilder.ts +++ b/src/transactionBuilder.ts @@ -1,7 +1,7 @@ -import { ARGUMENTS_SEPARATOR } from "../constants"; -import { IAddress, ITransactionPayload } from "../interface"; -import { Transaction } from "../transaction"; -import { TransactionPayload } from "../transactionPayload"; +import { ARGUMENTS_SEPARATOR } from "./constants"; +import { IAddress, ITransactionPayload } from "./interface"; +import { Transaction } from "./transaction"; +import { TransactionPayload } from "./transactionPayload"; interface Config { chainID: string; diff --git a/src/transferTransactionsFactory.spec.ts b/src/transferTransactionsFactory.spec.ts index 39e6f96d..b143afa1 100644 --- a/src/transferTransactionsFactory.spec.ts +++ b/src/transferTransactionsFactory.spec.ts @@ -3,7 +3,7 @@ import { Address } from "./address"; import { GasEstimator } from "./gasEstimator"; import { TokenTransfer } from "./tokens"; import { TransactionPayload } from "./transactionPayload"; -import { TransferTransactionsFactory } from "./transactionsFactories/transferTransactionsFactory"; +import { TransferTransactionsFactory } from "./transfers/transferTransactionsFactory"; describe("test transaction factory", () => { const factory = new TransferTransactionsFactory(new GasEstimator()); diff --git a/src/transfers/transferTransactionsFactory.spec.ts b/src/transfers/transferTransactionsFactory.spec.ts index 83714588..b4cda39f 100644 --- a/src/transfers/transferTransactionsFactory.spec.ts +++ b/src/transfers/transferTransactionsFactory.spec.ts @@ -96,8 +96,7 @@ describe("test transfer transactions factory", function () { const nft = new Token({ identifier: "t0-NFT-123456", nonce: 10n }); const transfer = new TokenTransfer({ token: nft, amount: 1n }); - const transaction = transferFactory.createTransactionForESDTTokenTransfer({ - sender: alice, + const transaction = transferFactory.createTransactionForESDTTokenTransfer(alice, { receiver: bob, tokenTransfers: [transfer], }); @@ -148,8 +147,7 @@ describe("test transfer transactions factory", function () { const secondNft = new Token({ identifier: "t0-TEST-987654", nonce: 1n }); const secondTransfer = new TokenTransfer({ token: secondNft, amount: 1n }); - const transaction = transferFactory.createTransactionForESDTTokenTransfer({ - sender: alice, + const transaction = transferFactory.createTransactionForESDTTokenTransfer(alice, { receiver: bob, tokenTransfers: [firstTransfer, secondTransfer], }); @@ -163,8 +161,7 @@ describe("test transfer transactions factory", function () { "MultiESDTNFTTransfer@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@02@74302d4e46542d313233343536@0a@01@74302d544553542d393837363534@01@01", ); - const secondTransaction = transferFactory.createTransactionForTransfer({ - sender: alice, + const secondTransaction = transferFactory.createTransactionForTransfer(alice, { receiver: bob, tokenTransfers: [firstTransfer, secondTransfer], }); @@ -253,8 +250,7 @@ describe("test transfer transactions factory", function () { const secondNft = new Token({ identifier: "t0-TEST-987654", nonce: 1n }); const secondTransfer = new TokenTransfer({ token: secondNft, amount: 1n }); - const transaction = transferFactory.createTransactionForTransfer({ - sender: alice, + const transaction = transferFactory.createTransactionForTransfer(alice, { receiver: bob, nativeAmount: 1000000000000000000n, tokenTransfers: [firstTransfer, secondTransfer], @@ -274,8 +270,7 @@ describe("test transfer transactions factory", function () { const firstNft = new Token({ identifier: EGLD_IDENTIFIER_FOR_MULTI_ESDTNFT_TRANSFER }); const firstTransfer = new TokenTransfer({ token: firstNft, amount: 1000000000000000000n }); - const transaction = transferFactory.createTransactionForESDTTokenTransfer({ - sender: alice, + const transaction = transferFactory.createTransactionForESDTTokenTransfer(alice, { receiver: bob, tokenTransfers: [firstTransfer], }); diff --git a/src/transfers/transferTransactionsFactory.ts b/src/transfers/transferTransactionsFactory.ts index d11f8cd9..852331e3 100644 --- a/src/transfers/transferTransactionsFactory.ts +++ b/src/transfers/transferTransactionsFactory.ts @@ -345,15 +345,10 @@ export class TransferTransactionsFactory { this.ensureConfigIsDefined(); const transfer = options.tokenTransfers[0]; - - if (this.tokenComputer!.isFungible(transfer.token)) { - dataParts = this.tokenTransfersDataBuilder!.buildDataPartsForESDTTransfer(transfer); - extraGasForTransfer = this.config!.gasLimitESDTTransfer + BigInt(ADDITIONAL_GAS_FOR_ESDT_TRANSFER); - } else { - dataParts = this.tokenTransfersDataBuilder!.buildDataPartsForSingleESDTNFTTransfer(transfer, receiver); - extraGasForTransfer = this.config!.gasLimitESDTNFTTransfer + BigInt(ADDITIONAL_GAS_FOR_ESDT_NFT_TRANSFER); - receiver = sender; - } + const { dataParts, extraGasForTransfer, receiver } = this.buildTransferData(transfer, { + sender, + receiver: options.receiver, + }); return new TransactionBuilder({ config: this.config!, diff --git a/src/transfers/transfersController.ts b/src/transfers/transfersController.ts index f335c093..1692a36a 100644 --- a/src/transfers/transfersController.ts +++ b/src/transfers/transfersController.ts @@ -1,9 +1,9 @@ import { IAccount } from "../accounts/interfaces"; import { Transaction } from "../transaction"; import { TransactionComputer } from "../transactionComputer"; -import { TransferTransactionsFactory } from "../transactionsFactories"; import { TransactionsFactoryConfig } from "../transactionsFactoryConfig"; import * as resources from "./resources"; +import { TransferTransactionsFactory } from "./transferTransactionsFactory"; export class TransfersController { private factory: TransferTransactionsFactory;