aboutsummaryrefslogtreecommitdiff
path: root/src/operations/withdraw.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-07-16 17:22:03 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-07-16 17:22:03 +0530
commit34cfa9276775d8e037a2a91d5034bdbd2187da03 (patch)
tree62455d8299846723a1ec79584e9f3eeaf1baa3ee /src/operations/withdraw.ts
parented447ad534d52ef0be569ab0cbbea1198f45420b (diff)
test cases
Diffstat (limited to 'src/operations/withdraw.ts')
-rw-r--r--src/operations/withdraw.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/operations/withdraw.ts b/src/operations/withdraw.ts
index 41b77da8f..d55198e69 100644
--- a/src/operations/withdraw.ts
+++ b/src/operations/withdraw.ts
@@ -78,6 +78,11 @@ export function getWithdrawDenomList(
amountAvailable: AmountJson,
denoms: DenominationRecord[],
): DenominationSelectionInfo {
+
+ console.log("calling getWithdrawDenomList with");
+ console.log(JSON.stringify(amountAvailable, undefined, 2));
+ console.log(JSON.stringify(denoms, undefined, 2));
+
let remaining = Amounts.copy(amountAvailable);
const selectedDenoms: {
@@ -91,16 +96,21 @@ export function getWithdrawDenomList(
denoms = denoms.filter(isWithdrawableDenom);
denoms.sort((d1, d2) => Amounts.cmp(d2.value, d1.value));
+ console.log("start remaining is", Amounts.stringify(remaining));
+
for (const d of denoms) {
let count = 0;
const cost = Amounts.add(d.value, d.feeWithdraw).amount;
+ console.log("cost is", Amounts.stringify(cost));
for (;;) {
if (Amounts.cmp(remaining, cost) < 0) {
break;
}
remaining = Amounts.sub(remaining, cost).amount;
+ console.log("remaining is", Amounts.stringify(remaining));
count++;
}
+ console.log("count is", count);
if (count > 0) {
totalCoinValue = Amounts.add(
totalCoinValue,
@@ -114,6 +124,7 @@ export function getWithdrawDenomList(
count,
denom: d,
});
+ console.log("total cost is", Amounts.stringify(totalWithdrawCost));
}
if (Amounts.isZero(remaining)) {
@@ -490,6 +501,11 @@ export async function selectWithdrawalDenoms(
}
} while (selectedDenoms.selectedDenoms.length > 0 && !allValid);
+
+ if (Amounts.cmp(selectedDenoms.totalWithdrawCost, amount) > 0) {
+ throw Error("Bug: withdrawal coin selection is wrong");
+ }
+
return selectedDenoms;
}