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

Conversation

popenta
Copy link
Contributor

@popenta popenta commented Feb 16, 2024

For the new v13 release, the functionality added will use bigint instead of BigNumber.

@popenta popenta self-assigned this Feb 16, 2024
@@ -59,13 +59,13 @@ export type ITokenPayment = ITokenTransfer;
export interface ITransactionNext {
sender: string;
receiver: string;
gasLimit: BigNumber.Value;
gasLimit: bigint;
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -130,7 +130,7 @@ export class SmartContract implements ISmartContract {
const nextTx = scNextTransactionFactory.createTransactionForDeploy({
sender: deployer,
bytecode: bytecode,
gasLimit: gasLimit.valueOf(),
gasLimit: BigInt(gasLimit.valueOf()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Upcasting, because before we had gasLimit as number. This is fine (it's the only good option) 👍

@@ -32,8 +32,8 @@ describe("test transaction construction", async () => {
const transaction = Transaction.fromTransactionNext(nextTransaction);
assert.deepEqual(transaction.getSender(), Address.fromBech32(plainTransactionNextObject.sender));
assert.deepEqual(transaction.getReceiver(), Address.fromBech32(plainTransactionNextObject.receiver));
assert.equal(transaction.getGasLimit().valueOf(), plainTransactionNextObject.gasLimit);
assert.equal(transaction.getValue().toString(), plainTransactionNextObject.value);
assert.equal(transaction.getGasLimit().valueOf().toFixed(0), plainTransactionNextObject.gasLimit.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure why does this work, since transaction.getGasLimit().valueOf() returns a number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

toString() works fine as well.

@@ -428,9 +428,9 @@ export class Transaction {
const tx = new Transaction({
sender: Address.fromBech32(transaction.sender),
receiver: Address.fromBech32(transaction.receiver),
gasLimit: new BigNumber(transaction.gasLimit).toNumber(),
gasLimit: new BigNumber(transaction.gasLimit.toString()).toNumber(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here we should do as follows:

https://stackoverflow.com/a/53970656/1475331

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

chainID: transaction.chainID,
value: new BigNumber(transaction.value).toFixed(0),
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.

Comment on lines 592 to 593
bigIntToHex(new BigNumber(options.tokenNonce.toString())),
bigIntToHex(new BigNumber(options.quantityToBurn.toString())),
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps use numberToPaddedHex (which handles bigint). If necessary, maybe handle 0 differently in numberToPaddedHex.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced with numberToPaddedHex.

andreibancioiu
andreibancioiu previously approved these changes Feb 16, 2024
@@ -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 👍

@bogdan-rosianu bogdan-rosianu self-requested a review February 20, 2024 08:10
new BigNumber(networkConfig.GasPriceModifier)
);
const processingFee = diff.multipliedBy(modifiedGasPrice);
const diff = transaction.gasLimit- moveBalanceGas;
Copy link
Contributor

Choose a reason for hiding this comment

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

transaction.gasLimit- moveBalanceGas;
=>
transaction.gasLimit - moveBalanceGas;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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

confirmed on testnet 👍

@popenta popenta merged commit 2647a16 into feat/next Feb 20, 2024
1 check passed
@popenta popenta deleted the replace-bignumber-with-bigint branch February 20, 2024 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants