fix: Handle number inputs correctly in computeRoundingModulus#225
Merged
Conversation
ac7b571 to
6e7ea27
Compare
- convert number inputs to satoshis (multiply by 1e8) - preserve existing behavior for Value objects and BigInt inputs - add comprehensive test coverage for all input types - update existing tests to use BigInt for raw satoshi values Previously, number inputs were incorrectly treated as raw satoshi values instead of bitcoin amounts, leading to incorrect calculations.
6e7ea27 to
e5c362b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug in the
computeRoundingModulusfunction where number inputs were incorrectly treated as raw satoshi values instead of bitcoin amounts.Problem
The
computeRoundingModulusfunction accepts three types of inputs:Valueobjects (which have a.satsproperty)BigIntvalues (raw satoshi amounts)numbervalues (intended to represent bitcoin amounts)However, the function was treating number inputs as raw satoshi values, which caused incorrect calculations when users passed bitcoin amounts like
0.001or1.5.Solution
1e8and rounding.satsproperty)Changes Made
computeRoundingModulusto use proper type checking and conversionBigIntfor raw satoshi valuesBackward Compatibility
Valueobjects orBigIntvalues is unaffectedExample Usage
This fix ensures that the function behaves intuitively when working with bitcoin amounts while maintaining full compatibility with existing code that uses proper types.