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

Replaced BigNumber with BigInt #384

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export class Transaction {
const tx = new Transaction({
sender: Address.fromBech32(transaction.sender),
receiver: Address.fromBech32(transaction.receiver),
gasLimit: new BigNumber(transaction.gasLimit.toString()).toNumber(),
gasLimit: Number(transaction.gasLimit),
chainID: transaction.chainID,
value: new BigNumber(transaction.value.toString()).toFixed(0),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is OK.

data: new TransactionPayload(Buffer.from(transaction.data)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("test token management transactions factory", () => {
assert.deepEqual(
next.data,
Buffer.from(
"issue@4652414e4b@4652414e4b@64@@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365",
"issue@4652414e4b@4652414e4b@64@00@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be fine 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

confirmed on testnet 👍

),
);
assert.equal(next.sender, frank.address.toString());
Expand Down
29 changes: 14 additions & 15 deletions src/transactionsFactories/tokenManagementTransactionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { Address } from "../address";
import { ESDT_CONTRACT_ADDRESS } from "../constants";
import { IAddress } from "../interface";
import { Logger } from "../logger";
import { addressToHex, bigIntToHex, byteArrayToHex, utf8ToHex } from "../utils.codec";
import { addressToHex, byteArrayToHex, utf8ToHex, numberToPaddedHex } from "../utils.codec";
import { TransactionNextBuilder } from "./transactionNextBuilder";
import { TransactionNext } from "../transaction";
import BigNumber from "bignumber.js";

interface Config {
chainID: string;
Expand Down Expand Up @@ -59,8 +58,8 @@ export class TokenManagementTransactionsFactory {
"issue",
utf8ToHex(options.tokenName),
utf8ToHex(options.tokenTicker),
bigIntToHex(new BigNumber(options.initialSupply.toString())),
bigIntToHex(new BigNumber(options.numDecimals.toString())),
numberToPaddedHex(options.initialSupply),
numberToPaddedHex(options.numDecimals),
utf8ToHex("canFreeze"),
options.canFreeze ? this.trueAsHex : this.falseAsHex,
utf8ToHex("canWipe"),
Expand Down Expand Up @@ -195,7 +194,7 @@ export class TokenManagementTransactionsFactory {
"registerMetaESDT",
utf8ToHex(options.tokenName),
utf8ToHex(options.tokenTicker),
bigIntToHex(new BigNumber(options.numDecimals.toString())),
numberToPaddedHex(options.numDecimals),
utf8ToHex("canFreeze"),
options.canFreeze ? this.trueAsHex : this.falseAsHex,
utf8ToHex("canWipe"),
Expand Down Expand Up @@ -237,7 +236,7 @@ export class TokenManagementTransactionsFactory {
utf8ToHex(options.tokenName),
utf8ToHex(options.tokenTicker),
utf8ToHex(options.tokenType),
bigIntToHex(new BigNumber(options.numDecimals.toString())),
numberToPaddedHex(options.numDecimals),
];

return new TransactionNextBuilder({
Expand Down Expand Up @@ -393,9 +392,9 @@ export class TokenManagementTransactionsFactory {
const dataParts = [
"ESDTNFTCreate",
utf8ToHex(options.tokenIdentifier),
bigIntToHex(new BigNumber(options.initialQuantity.toString())),
numberToPaddedHex(options.initialQuantity),
utf8ToHex(options.name),
bigIntToHex(options.royalties),
numberToPaddedHex(options.royalties),
utf8ToHex(options.hash),
byteArrayToHex(options.attributes),
...options.uris.map(utf8ToHex),
Expand Down Expand Up @@ -500,7 +499,7 @@ export class TokenManagementTransactionsFactory {
const dataParts = [
"ESDTLocalMint",
utf8ToHex(options.tokenIdentifier),
bigIntToHex(new BigNumber(options.supplyToMint.toString())),
numberToPaddedHex(options.supplyToMint),
];

return new TransactionNextBuilder({
Expand All @@ -521,7 +520,7 @@ export class TokenManagementTransactionsFactory {
const dataParts = [
"ESDTLocalBurn",
utf8ToHex(options.tokenIdentifier),
bigIntToHex(new BigNumber(options.supplyToBurn.toString())),
numberToPaddedHex(options.supplyToBurn),
];

return new TransactionNextBuilder({
Expand All @@ -543,7 +542,7 @@ export class TokenManagementTransactionsFactory {
const dataParts = [
"ESDTNFTUpdateAttributes",
utf8ToHex(options.tokenIdentifier),
bigIntToHex(new BigNumber(options.tokenNonce.toString())),
numberToPaddedHex(options.tokenNonce),
byteArrayToHex(options.attributes),
];

Expand All @@ -566,8 +565,8 @@ export class TokenManagementTransactionsFactory {
const dataParts = [
"ESDTNFTAddQuantity",
utf8ToHex(options.tokenIdentifier),
bigIntToHex(new BigNumber(options.tokenNonce.toString())),
bigIntToHex(new BigNumber(options.quantityToAdd.toString())),
numberToPaddedHex(options.tokenNonce),
numberToPaddedHex(options.quantityToAdd),
];

return new TransactionNextBuilder({
Expand All @@ -589,8 +588,8 @@ export class TokenManagementTransactionsFactory {
const dataParts = [
"ESDTNFTBurn",
utf8ToHex(options.tokenIdentifier),
bigIntToHex(new BigNumber(options.tokenNonce.toString())),
bigIntToHex(new BigNumber(options.quantityToBurn.toString())),
numberToPaddedHex(options.tokenNonce),
numberToPaddedHex(options.quantityToBurn),
];

return new TransactionNextBuilder({
Expand Down
3 changes: 3 additions & 0 deletions src/utils.codec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { byteArrayToHex, isPaddedHex, numberToPaddedHex, utf8ToHex, zeroPadStrin

describe("test codec utils", () => {
it("should convert numberToPaddedHex", () => {
assert.equal(numberToPaddedHex(0), "00");
assert.equal(numberToPaddedHex(1), "01");
assert.equal(numberToPaddedHex(10), "0a");
assert.equal(numberToPaddedHex(256), "0100");

assert.equal(numberToPaddedHex(0n), "00");
assert.equal(numberToPaddedHex(1n), "01");
assert.equal(numberToPaddedHex(10n), "0a");
assert.equal(numberToPaddedHex(256n), "0100");

assert.equal(numberToPaddedHex("0"), "00");
assert.equal(numberToPaddedHex("1"), "01");
assert.equal(numberToPaddedHex("10"), "0a");
assert.equal(numberToPaddedHex("256"), "0100");
Expand Down
Loading