Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ITokenTransfer and ITransactionPayload #550

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -4,7 +4,7 @@
import { CURRENT_NUMBER_OF_SHARDS_WITHOUT_META, METACHAIN_ID, WasmVirtualMachine } from "./constants";
import * as errors from "./errors";
import { bigIntToBuffer } from "./tokenOperations/codec";
const createKeccakHash = require("keccak");

Check warning on line 7 in src/address.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Require statement not part of import statement

/**
* The length (in bytes) of a public key (from which a bech32 address can be obtained).
Expand All @@ -13,11 +13,6 @@

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 @@
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 @@
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
Loading