Skip to content

Commit

Permalink
Merge pull request #550 from multiversx/TOOL-404-remove-i-token-trans…
Browse files Browse the repository at this point in the history
…fer-and-i-transaction-payload

Remove ITokenTransfer and ITransactionPayload
  • Loading branch information
danielailie authored Dec 16, 2024
2 parents 500104d + 2ce19d5 commit df2420f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 43 deletions.
9 changes: 4 additions & 5 deletions src/abi/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -73,7 +72,7 @@ export class Interaction {
return this.value;
}

getTokenTransfers(): ITokenTransfer[] {
getTokenTransfers(): TokenTransfer[] {
return this.tokenTransfers;
}

Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 2 additions & 7 deletions src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
18 changes: 0 additions & 18 deletions src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import BigNumber from "bignumber.js";
import { TransactionOnNetwork } from "./transactionOnNetwork";

export interface ITransactionFetcher {
Expand Down Expand Up @@ -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;
}
5 changes: 2 additions & 3 deletions src/testutils/dummyQuery.ts
Original file line number Diff line number Diff line change
@@ -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 = "";
Expand Down
10 changes: 4 additions & 6 deletions src/transactionBuilder.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions src/transfers/transferTransactionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -184,7 +183,7 @@ export class TransferTransactionsFactory {
* Use {@link createTransactionForESDTTokenTransfer} instead.
*/
createESDTTransfer(args: {
tokenTransfer: ITokenTransfer;
tokenTransfer: TokenTransfer;
nonce?: bigint;
receiver: Address;
sender: Address;
Expand Down Expand Up @@ -226,7 +225,7 @@ export class TransferTransactionsFactory {
* Use {@link createTransactionForESDTTokenTransfer} instead.
*/
createESDTNFTTransfer(args: {
tokenTransfer: ITokenTransfer;
tokenTransfer: TokenTransfer;
nonce?: bigint;
destination: Address;
sender: Address;
Expand Down Expand Up @@ -272,7 +271,7 @@ export class TransferTransactionsFactory {
* Use {@link createTransactionForESDTTokenTransfer} instead.
*/
createMultiESDTNFTTransfer(args: {
tokenTransfers: ITokenTransfer[];
tokenTransfers: TokenTransfer[];
nonce?: bigint;
destination: Address;
sender: Address;
Expand Down

0 comments on commit df2420f

Please sign in to comment.