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

Smart Contract transfer and execute #340

Merged
merged 10 commits into from
Oct 26, 2023
16 changes: 7 additions & 9 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ export class Token {
}
}

export namespace NewTokenTransfer {
export class TokenTransfer {
token: Token;
amount: BigNumber.Value;

constructor(token: Token, amount: BigNumber.Value) {
this.token = token;
this.amount = amount;
}
export class NextTokenTransfer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

token: Token;
amount: BigNumber.Value;

constructor(token: Token, amount: BigNumber.Value) {
this.token = token;
this.amount = amount;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { loadContractCode, loadAbiRegistry } from "../testutils/utils";
import { Err } from "../errors";
import { TransactionsFactoryConfig } from "./transactionsFactoryConfig";
import BigNumber from "bignumber.js";
import { Token, NewTokenTransfer, TokenComputer } from "../tokens";
import { Token, NextTokenTransfer, TokenComputer } from "../tokens";

describe("test smart contract transactions factory", function () {
const config = new TransactionsFactoryConfig("D");
Expand Down Expand Up @@ -150,7 +150,7 @@ describe("test smart contract transactions factory", function () {
const gasLimit = 6000000;
const args = [new U32Value(7)];
const token = new Token("FOO-6ce17b", 0);
const transfer = new NewTokenTransfer.TokenTransfer(token, 10);
const transfer = new NextTokenTransfer(token, 10);

const executeDraft = factory.createTransactionForExecute({
sender: sender,
Expand Down Expand Up @@ -186,9 +186,9 @@ describe("test smart contract transactions factory", function () {
const args = [new U32Value(7)];

const fooToken = new Token("FOO-6ce17b", 0);
const fooTransfer = new NewTokenTransfer.TokenTransfer(fooToken, 10);
const fooTransfer = new NextTokenTransfer(fooToken, 10);
const barToken = new Token("BAR-5bc08f", 0);
const barTransfer = new NewTokenTransfer.TokenTransfer(barToken, 3140);
const barTransfer = new NextTokenTransfer(barToken, 3140);

const executeDraft = factory.createTransactionForExecute({
sender: sender,
Expand Down Expand Up @@ -229,7 +229,7 @@ describe("test smart contract transactions factory", function () {
const args = [new U32Value(7)];

const token = new Token("NFT-123456", 1);
const transfer = new NewTokenTransfer.TokenTransfer(token, 1);
const transfer = new NextTokenTransfer(token, 1);

const executeDraft = factory.createTransactionForExecute({
sender: sender,
Expand Down Expand Up @@ -270,9 +270,9 @@ describe("test smart contract transactions factory", function () {
const args = [new U32Value(7)];

const firstToken = new Token("NFT-123456", 1);
const firstTransfer = new NewTokenTransfer.TokenTransfer(firstToken, 1);
const firstTransfer = new NextTokenTransfer(firstToken, 1);
const secondToken = new Token("NFT-123456", 42);
const secondTransfer = new NewTokenTransfer.TokenTransfer(secondToken, 1);
const secondTransfer = new NextTokenTransfer(secondToken, 1);

const executeDraft = factory.createTransactionForExecute({
sender: sender,
Expand Down
4 changes: 2 additions & 2 deletions src/transactionsFactories/smartContractTransactionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NativeSerializer } from "../smartcontracts/nativeSerializer";
import { Err, ErrBadUsage } from "../errors";
import { Address } from "../address";
import { DraftTransactionBuilder } from "./draftTransactionBuilder";
import { Token, NewTokenTransfer } from "../tokens";
import { Token, NextTokenTransfer } from "../tokens";
import { TokenTransfersDataBuilder } from "./tokenTransfersDataBuilder";

interface Config {
Expand Down Expand Up @@ -84,7 +84,7 @@ export class SmartContractTransactionsFactory {
gasLimit: BigNumber.Value;
args?: any[];
nativeTransferAmount?: BigNumber.Value;
tokenTransfers?: NewTokenTransfer.TokenTransfer[];
tokenTransfers?: NextTokenTransfer[];
}): DraftTransaction {
const args = options.args || [];
const tokenTransfer = options.tokenTransfers || [];
Expand Down
8 changes: 4 additions & 4 deletions src/transactionsFactories/tokenTransfersDataBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IAddress } from "../interface";
import { NewTokenTransfer, TokenComputer } from "../tokens";
import { NextTokenTransfer, TokenComputer } from "../tokens";
import { numberToPaddedHex, utf8ToHex, addressToHex } from "../utils.codec";

export class TokenTransfersDataBuilder {
andreibancioiu marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -9,13 +9,13 @@ export class TokenTransfersDataBuilder {
this.tokenComputer = new TokenComputer();
}

buildArgsForESDTTransfer(transfer: NewTokenTransfer.TokenTransfer): string[] {
buildArgsForESDTTransfer(transfer: NextTokenTransfer): string[] {
let args = ["ESDTTransfer"];
args.push(...[utf8ToHex(transfer.token.identifier), numberToPaddedHex(transfer.amount)]);
return args;
}

buildArgsForSingleESDTNFTTransfer(transfer: NewTokenTransfer.TokenTransfer, receiver: IAddress) {
buildArgsForSingleESDTNFTTransfer(transfer: NextTokenTransfer, receiver: IAddress) {
let args = ["ESDTNFTTransfer"];

const token = transfer.token;
Expand All @@ -32,7 +32,7 @@ export class TokenTransfersDataBuilder {
return args;
}

buildArgsForMultiESDTNFTTransfer(receiver: IAddress, transfers: NewTokenTransfer.TokenTransfer[]) {
buildArgsForMultiESDTNFTTransfer(receiver: IAddress, transfers: NextTokenTransfer[]) {
let args = ["MultiESDTNFTTransfer", addressToHex(receiver), numberToPaddedHex(transfers.length)];

for (let transfer of transfers) {
Expand Down
Loading