HomePhabricator

[Cashtab] Use BigInt for utxo value calculations

Description

[Cashtab] Use BigInt for utxo value calculations

Summary:
ecash-lib supports utxo satoshi values of Number or BigInt type. Because of the supply cap on ecash, Number is adequate (and this is how Cashtab has always done this math).

However, Number and BigInt types do not always mix well (you may get errors if you add them).

Issue has come up in developing NFT trading on Cashtab, as ecash-agora creates enforcedOutputs with the satoshi amount stored as a BigInt. This is due to ecash-lib defaulting to BigInt in the TxOutput write method. I do not think we should change ecash-lib to only write Number instead of BigInt...BigInt does "feel" safer and, if either can be used, it is probably the better option.

However Cashtab stores utxo values as Number. So, when we build and broadcast a Buy or Cancel tx, we will have some outputs with BigInt, and others with Number.

Best solution is to refactor sendXec so it just converts everything to BigInt. In this way, it can accept mixed inputs.

Note that we will not see test txs for this specific case yet, as we have not yet installed ecash-agora. But we will see these when the NFT diff is up for review. Tests now confirm that this approach does not break existing tx building.

Test Plan: npm test

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D16469

Details

Provenance
bytesofmanAuthored on Jul 15 2024, 18:11
bytesofmanPushed on Jul 16 2024, 11:39
Reviewer
Restricted Project
Differential Revision
D16469: [Cashtab] Use BigInt for utxo value calculations
Parents
rABC80a959a40033: [Cashtab] Patch token qty rendering error on NFT collection genesis
Branches
Unknown
Tags
Unknown