Page MenuHomePhabricator

[Cashtab] Integer validation for satoshi amounts
ClosedPublic

Authored by bytesofman on Dec 20 2023, 18:17.

Details

Reviewers
emack
Group Reviewers
Restricted Project
Commits
rABC49db8e565759: [Cashtab] Integer validation for satoshi amounts
Summary

Confirm that only integer values for satoshis are sent to the node for broadcasting txs

Test Plan

npm test

Diff Detail

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

Event Timeline

This revision is now accepted and ready to land.Dec 20 2023, 20:34
Fabien added inline comments.
cashtab/src/utils/cashMethods.js
562 ↗(On Diff #43699)

Can rounding cause error like insufficient balance ? shouldn't you use floor instead ?

cashtab/src/utils/cashMethods.js
562 ↗(On Diff #43699)

What we really want is to get the value right. If the user has insufficient balance -- we want to know this and show this error.

151.52 * 100 = 15152.000000000002

but also,

4444.44 * 100 = 444443.99999999994 -->here, Math.floor will give us the wrong value (by 1 satoshi).

At the very high end, we get weirder cases, like

20999999999999.01*100 = 2099999999999901.2

The nearest integer is always the right value though.

An alt approach would be "pure string" manipulation. Will probably end up using this for eToken amounts (and perhaps then generalizing that approach to cover all tx building).