Skip to content

Commit

Permalink
feat: fix validateOutputAmount API for BigNumber
Browse files Browse the repository at this point in the history
fix: preserve backward compatibility
  • Loading branch information
Shadouts committed Dec 15, 2023
1 parent db5b56c commit fc03111
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function validateOutput(network, output, inputsTotalSats?) {
/**
* Lowest acceptable output amount in Satoshis.
*/
const DUST_LIMIT_SATS = new BigNumber(546);
const DUST_LIMIT_SATS = "546";

/**
* Validate the given output amount (in Satoshis).
Expand All @@ -74,11 +74,15 @@ const DUST_LIMIT_SATS = new BigNumber(546);
*
* - Cannot exceed the total input amount (this check is only run if
* `inputsTotalSats` is passed.
*
* TODO: minSats accepting a BigNumber is only to maintain some backward
* compatibility. Ideally, the arg would not expose this lib's dependencies to
* the caller. It should be made to only accept number or string.
*/
export function validateOutputAmount(
amountSats,
maxSats?,
minSats = DUST_LIMIT_SATS
maxSats?: number | string,
minSats: number | string | BigNumber = DUST_LIMIT_SATS
) {
let a, its;
try {
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export function satoshisToBitcoins(satoshis: string | number) {
* - Rounds down output value to the nearest Satoshi.
*/
export function bitcoinsToSatoshis(btc: string | number) {
const btcAmount = new BigNumber(btc);

return new BigNumber(btc)
.shiftedBy(8)
.integerValue(BigNumber.ROUND_DOWN)
Expand Down

0 comments on commit fc03111

Please sign in to comment.