From 2ce19d5e26ac1ba8de1c63d3494e4e7400f4a146 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 16 Dec 2024 16:04:30 +0200 Subject: [PATCH] Remove ITokenTransfer and ITransactionPayload --- src/abi/interaction.ts | 9 ++++----- src/address.ts | 9 ++------- src/interface.ts | 18 ------------------ src/testutils/dummyQuery.ts | 5 ++--- src/transactionBuilder.ts | 10 ++++------ src/transfers/transferTransactionsFactory.ts | 7 +++---- 6 files changed, 15 insertions(+), 43 deletions(-) diff --git a/src/abi/interaction.ts b/src/abi/interaction.ts index fa63b2a8..4f33f363 100644 --- a/src/abi/interaction.ts +++ b/src/abi/interaction.ts @@ -2,7 +2,6 @@ import { Account } from "../accounts"; import { Address } from "../address"; import { Compatibility } from "../compatibility"; import { TRANSACTION_VERSION_DEFAULT } from "../constants"; -import { ITokenTransfer } from "../interface"; import { SmartContractTransactionsFactory } from "../smartContracts"; import { TokenTransfer } from "../tokens"; import { Transaction } from "../transaction"; @@ -73,7 +72,7 @@ export class Interaction { return this.value; } - getTokenTransfers(): ITokenTransfer[] { + getTokenTransfers(): TokenTransfer[] { return this.tokenTransfers; } @@ -133,17 +132,17 @@ export class Interaction { return this; } - withSingleESDTTransfer(transfer: ITokenTransfer): Interaction { + withSingleESDTTransfer(transfer: TokenTransfer): Interaction { this.tokenTransfers = [transfer].map((transfer) => new TokenTransfer(transfer)); return this; } - withSingleESDTNFTTransfer(transfer: ITokenTransfer): Interaction { + withSingleESDTNFTTransfer(transfer: TokenTransfer): Interaction { this.tokenTransfers = [transfer].map((transfer) => new TokenTransfer(transfer)); return this; } - withMultiESDTNFTTransfer(transfers: ITokenTransfer[]): Interaction { + withMultiESDTNFTTransfer(transfers: TokenTransfer[]): Interaction { this.tokenTransfers = transfers.map((transfer) => new TokenTransfer(transfer)); return this; } diff --git a/src/address.ts b/src/address.ts index ec5fae2f..04686e77 100644 --- a/src/address.ts +++ b/src/address.ts @@ -13,11 +13,6 @@ const PUBKEY_LENGTH = 32; const SMART_CONTRACT_HEX_PUBKEY_PREFIX = "0".repeat(16); -interface IAddress { - getPublicKey(): Buffer; - getHrp(): string; -} - /** * An Address, as an immutable object. */ @@ -275,7 +270,7 @@ export class AddressComputer { this.numberOfShardsWithoutMeta = numberOfShardsWithoutMeta || CURRENT_NUMBER_OF_SHARDS_WITHOUT_META; } - computeContractAddress(deployer: IAddress, deploymentNonce: bigint): Address { + computeContractAddress(deployer: Address, deploymentNonce: bigint): Address { const initialPadding = Buffer.alloc(8, 0); const ownerPubkey = deployer.getPublicKey(); const shardSelector = ownerPubkey.slice(30); @@ -293,7 +288,7 @@ export class AddressComputer { return new Address(addressBytes); } - getShardOfAddress(address: IAddress): number { + getShardOfAddress(address: Address): number { return this.getShardOfPubkey(address.getPublicKey(), this.numberOfShardsWithoutMeta); } diff --git a/src/interface.ts b/src/interface.ts index 95252daa..d867b462 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -1,4 +1,3 @@ -import BigNumber from "bignumber.js"; import { TransactionOnNetwork } from "./transactionOnNetwork"; export interface ITransactionFetcher { @@ -27,20 +26,3 @@ export interface IPlainTransactionObject { guardianSignature?: string; relayerSignature?: string; } - -export interface ITransactionPayload { - length(): number; - encoded(): string; - toString(): string; - valueOf(): Buffer; -} - -/** - * Legacy interface. The class `TokenTransfer` can be used instead, where necessary. - */ -export interface ITokenTransfer { - readonly tokenIdentifier: string; - readonly nonce: number; - readonly amountAsBigInteger: BigNumber.Value; - valueOf(): BigNumber.Value; -} diff --git a/src/testutils/dummyQuery.ts b/src/testutils/dummyQuery.ts index 076369df..5be41fe6 100644 --- a/src/testutils/dummyQuery.ts +++ b/src/testutils/dummyQuery.ts @@ -1,10 +1,9 @@ import { Address } from "../address"; -import { IAddress } from "../interface"; import { IContractQuery } from "../networkProviders/interface"; export class MockQuery implements IContractQuery { - caller: IAddress = Address.empty(); - address: IAddress = Address.empty(); + caller = Address.empty(); + address = Address.empty(); func: string = ""; args: string[] = []; value: string = ""; diff --git a/src/transactionBuilder.ts b/src/transactionBuilder.ts index 2ef3b64b..d7e46d4b 100644 --- a/src/transactionBuilder.ts +++ b/src/transactionBuilder.ts @@ -1,8 +1,6 @@ import { Address } from "./address"; import { ARGUMENTS_SEPARATOR } from "./constants"; -import { ITransactionPayload } from "./interface"; import { Transaction } from "./transaction"; -import { TransactionPayload } from "./transactionPayload"; interface Config { chainID: string; @@ -40,19 +38,19 @@ export class TransactionBuilder { this.amount = options.amount; } - private computeGasLimit(payload: ITransactionPayload): bigint { + private computeGasLimit(payload: Uint8Array): bigint { if (!this.addDataMovementGas) { return this.providedGasLimit; } - const dataMovementGas = this.config.minGasLimit + this.config.gasLimitPerByte * BigInt(payload.length()); + const dataMovementGas = this.config.minGasLimit + this.config.gasLimitPerByte * BigInt(payload.length); const gasLimit = dataMovementGas + this.providedGasLimit; return gasLimit; } - private buildTransactionPayload(): TransactionPayload { + private buildTransactionPayload(): Uint8Array { const data = this.dataParts.join(ARGUMENTS_SEPARATOR); - return new TransactionPayload(data); + return Buffer.from(data); } build(): Transaction { diff --git a/src/transfers/transferTransactionsFactory.ts b/src/transfers/transferTransactionsFactory.ts index b2b69fd5..45b4fc73 100644 --- a/src/transfers/transferTransactionsFactory.ts +++ b/src/transfers/transferTransactionsFactory.ts @@ -2,7 +2,6 @@ import { AddressValue, ArgSerializer, BigUIntValue, BytesValue, TypedValue, U16V import { Address } from "../address"; import { EGLD_IDENTIFIER_FOR_MULTI_ESDTNFT_TRANSFER } from "../constants"; import { Err, ErrBadUsage } from "../errors"; -import { ITokenTransfer } from "../interface"; import { TokenComputer, TokenTransfer } from "../tokens"; import { TokenTransfersDataBuilder } from "../tokenTransfersDataBuilder"; import { Transaction } from "../transaction"; @@ -184,7 +183,7 @@ export class TransferTransactionsFactory { * Use {@link createTransactionForESDTTokenTransfer} instead. */ createESDTTransfer(args: { - tokenTransfer: ITokenTransfer; + tokenTransfer: TokenTransfer; nonce?: bigint; receiver: Address; sender: Address; @@ -226,7 +225,7 @@ export class TransferTransactionsFactory { * Use {@link createTransactionForESDTTokenTransfer} instead. */ createESDTNFTTransfer(args: { - tokenTransfer: ITokenTransfer; + tokenTransfer: TokenTransfer; nonce?: bigint; destination: Address; sender: Address; @@ -272,7 +271,7 @@ export class TransferTransactionsFactory { * Use {@link createTransactionForESDTTokenTransfer} instead. */ createMultiESDTNFTTransfer(args: { - tokenTransfers: ITokenTransfer[]; + tokenTransfers: TokenTransfer[]; nonce?: bigint; destination: Address; sender: Address;