Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validateOutputAmount API for BigNumber #106

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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