kaspanet / kaspad

Kaspad was the reference full node Kaspa implementation written in Go (golang), now rewritten in Rust: https://github.com/kaspanet/rusty-kaspa
ISC License
447 stars 228 forks source link

Fix off by small amounts in sent amount kaspa #2220

Closed coderofstuff closed 11 months ago

coderofstuff commented 11 months ago

Problem: Floating point math causes inconsistencies when converting kas to sompi.

Solution: Use a method that parses the amount as a string, the converts it to sompi string then parse to uint64

Motivation: Someone (some 3rd party integrating with kaspa) sent 33184.1489732 via kaspawallet and the other party got 33184.14897319 because the kaspawallet send command loses some precision when converting kas to sompi (floating point math kinda stuff), which is off by 0.00000001. Small difference but irreconcilable to accounting.

tmrlvi commented 11 months ago

Seems good. I think you should fix the regex to raise parsing error earlier with a clearer description.

The other two comments are not material, just for cleaner code

codecov[bot] commented 11 months ago

Codecov Report

Patch coverage: 57.57% and project coverage change: -0.02% :warning:

Comparison is base (c417c8b) 58.86% compared to head (98366b7) 58.84%.

:exclamation: Current head 98366b7 differs from pull request most recent head b724d7c. Consider uploading reports for the commit b724d7c to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #2220 +/- ## ========================================== - Coverage 58.86% 58.84% -0.02% ========================================== Files 679 679 Lines 33122 33149 +27 ========================================== + Hits 19497 19508 +11 - Misses 10784 10795 +11 - Partials 2841 2846 +5 ``` | [Files Changed](https://app.codecov.io/gh/kaspanet/kaspad/pull/2220?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet) | Coverage Δ | | |---|---|---| | [cmd/kaspawallet/config.go](https://app.codecov.io/gh/kaspanet/kaspad/pull/2220?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-Y21kL2thc3Bhd2FsbGV0L2NvbmZpZy5nbw==) | `0.00% <0.00%> (ø)` | | | [cmd/kaspawallet/create\_unsigned\_tx.go](https://app.codecov.io/gh/kaspanet/kaspad/pull/2220?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-Y21kL2thc3Bhd2FsbGV0L2NyZWF0ZV91bnNpZ25lZF90eC5nbw==) | `0.00% <0.00%> (ø)` | | | [cmd/kaspawallet/send.go](https://app.codecov.io/gh/kaspanet/kaspad/pull/2220?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-Y21kL2thc3Bhd2FsbGV0L3NlbmQuZ28=) | `0.00% <0.00%> (ø)` | | | [cmd/kaspawallet/utils/format\_kas.go](https://app.codecov.io/gh/kaspanet/kaspad/pull/2220?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet#diff-Y21kL2thc3Bhd2FsbGV0L3V0aWxzL2Zvcm1hdF9rYXMuZ28=) | `67.85% <82.60%> (+67.85%)` | :arrow_up: | ... and [7 files with indirect coverage changes](https://app.codecov.io/gh/kaspanet/kaspad/pull/2220/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kaspanet)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.