Page MenuHomePhabricator

[ecash-coinselect] Export new function getMaxSendAmountSatoshis
ClosedPublic

Authored by bytesofman on Feb 26 2024, 18:21.

Details

Summary

Export a new function to get the max amount of satoshis that can be sent from a given set of utxos at a given fee and including any miscellaneous target outputs.

Initially I was going to implement this function in Cashtab, but it requires bytecount methods in this lib and I believe it is a common enough thing for a utxo-chain dev to need that it should be in a lib. I considered modifying the coinSelect function to simply sendMax -- however this would make it difficult for Cashtab's needed use case (displaying the value before the user decides to send it) -- which is also a common one for app developers. An app developer can easily enough still use coinSelect when building the actual broadcasting function.

Test Plan

npm test

See D15553 for how this will be implemented in Cashtab

Diff Detail

Repository
rABC Bitcoin ABC
Branch
ecash-coinselect-getmax
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 27436
Build 54435: Build Diffecash-coinselect
Build 54434: arc lint + arc unit

Event Timeline

improve comments and line breaks

PiRK requested changes to this revision.Feb 26 2024, 19:19
PiRK added a subscriber: PiRK.
PiRK added inline comments.
modules/ecash-coinselect/src/coinSelect.js
98

The doc could mention that token utxos are excluded, just to be explicit. "spendable utxos" is a bit ambiguous, and AFAIK there is nothing in the SLP spec preventing token UTXOs from also holding significant XEC amounts.

134

Would that work? It is computed above for the dust check.

modules/ecash-coinselect/test/coinSelect.test.js
457–458

It would be good to have a test checking on both sides of the boundary, the max fee threshold at which a transaction succeeds.
If my calculations are correct that should be around 11.176... sats/byte ((6000-546)/488)

This revision now requires changes to proceed.Feb 26 2024, 19:19
bytesofman marked 3 inline comments as done.

clean up functions, add tests at boundary

modules/ecash-coinselect/src/coinSelect.js
134

good catch much better. Originally the function did not have a dust check until I saw negative values in unit testing.

This revision is now accepted and ready to land.Feb 26 2024, 23:58