Skip to content

Use exact monetary arithmetic and preserve millisatoshi precision - #543

Merged
gcomte merged 6 commits into
fix/cli-input-validationfrom
fix/exact-monetary-rounding
Sep 7, 2026
Merged

Use exact monetary arithmetic and preserve millisatoshi precision#543
gcomte merged 6 commits into
fix/cli-input-validationfrom
fix/exact-monetary-rounding

Conversation

@gcomte

@gcomte gcomte commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Conversions previously used f64, losing decimal precision before rounding. For example, converting 1,500 MSAT to BTC produced 0.00000001 BTC. Preserve decimal values from CLI input, legacy YAML defaults, and ticker JSON, calculate exact rate ratios, and round only the final result with midpoint ties away from zero.

Bitcoin denominations now retain millisatoshi precision: BTC has up to 11 decimals, MBTC 8, BITS 5, SAT 3, and MSAT 0. For example, 1 MSAT becomes 0.00000000001 BTC, and 1,500 MSAT becomes 0.000000015 BTC. --integer continues to round to whole output units, while fiat output keeps its existing currency precision.

Bound numeric inputs and exponents, validate positive rates, and report missing rates or conversion overflow without partial stdout. The ticker response is bounded before arbitrary-precision parsing. YAML reading uses the existing parser backend directly to retain numeric text; existing numeric defaults remain compatible.

Validation:

  • 33 deterministic tests pass: 26 unit/property tests, 3 exact-conversion CLI tests, and 4 input-validation tests.
  • Coverage includes full-u64 millisatoshi round trips, signed midpoint boundaries, values above 2^53, exact YAML/JSON values, repeating fiat cross-rates, invalid rates, and overflow errors.
  • cargo fmt --all --check and cargo clippy --all-targets -- -D warnings pass.
  • Post-implementation security review found no actionable findings.
  • Existing live API tests remain enabled in GitHub CI.

Stacked on #542; review this diff against fix/cli-input-validation. Merge the input-validation PR first and retarget this PR to master if GitHub does not do so automatically.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 9cfcadf6-7bf4-44d5-85f5-f7954e46a9f8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gcomte
gcomte merged commit c5d2f64 into fix/cli-input-validation Sep 7, 2026
7 checks passed
@gcomte
gcomte deleted the fix/exact-monetary-rounding branch September 7, 2026 11:28
@gcomte gcomte mentioned this pull request Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant