Skip to content

[fix] avoid float math for utxo sats

akrokr requested to merge akh/unspent_floats into develop

Fixes #1817 (closed)

btcd returns utxo amounts as float64. Floating point arithmetic can result in precision errors. Instead of adding the floats and converting the sum to int64, safely convert each value to int64 and add those instead.

Unit test demonstrates the issue/fix using the values from the linked ticket. It does not test the function which was actually changed because there appear to be no tests at all for this code unless they're hiding somewhere that I missed. Depending on when we want to get this in, we can merge as-is or write a proper test suite first.

Edited by akrokr

Merge request reports