Page MenuHomePhabricator

[Cashtab] Use BigInt for utxo value calculations
ClosedPublic

Authored by bytesofman on Jul 15 2024, 18:15.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCec58af68807d: [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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable