aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-18 00:09:43 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-18 00:09:43 +0100
commit8db3e7360689a789b154e2e8a093f466a08b2185 (patch)
treed750649d3027ee7df415047001e3f196f4ae5888 /src
parent834b89547bfcfa597db71c63925136236cf147aa (diff)
fix coin selection issue
Diffstat (limited to 'src')
-rw-r--r--src/wallet.ts19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/wallet.ts b/src/wallet.ts
index 8f6346c77..902599beb 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -246,10 +246,16 @@ export function selectCoins(cds: CoinWithDenom[], paymentAmount: AmountJson,
let coversAmountWithFee = false;
for (let i = 0; i < cds.length; i++) {
let {coin, denom} = cds[i];
- cdsResult.push(cds[i]);
+ if (coin.suspended) {
+ continue;
+ }
+ if (coin.dirty) {
+ continue;
+ }
if (Amounts.cmp(denom.feeDeposit, coin.currentAmount) >= 0) {
continue;
}
+ cdsResult.push(cds[i]);
accFee = Amounts.add(denom.feeDeposit, accFee).amount;
accAmount = Amounts.add(coin.currentAmount, accAmount).amount;
coversAmount = Amounts.cmp(accAmount, paymentAmount) >= 0;
@@ -518,6 +524,12 @@ export class Wallet {
if (coin.suspended) {
continue;
}
+ if (coin.dirty) {
+ continue;
+ }
+ if (coin.transactionPending) {
+ continue;
+ }
cds.push({coin, denom});
}
@@ -933,6 +945,7 @@ export class Wallet {
*/
private async depleteReserve(reserve: ReserveRecord,
exchange: ExchangeRecord): Promise<number> {
+ console.log("depleting reserve");
if (!reserve.current_amount) {
throw Error("can't withdraw when amount is unknown");
}
@@ -943,6 +956,8 @@ export class Wallet {
let denomsForWithdraw = await this.getVerifiedWithdrawDenomList(exchange.baseUrl,
currentAmount);
+ console.log(`withdrawing ${denomsForWithdraw.length} coins`);
+
let ps = denomsForWithdraw.map(async(denom) => {
function mutateReserve(r: ReserveRecord): ReserveRecord {
let currentAmount = r.current_amount;
@@ -1343,8 +1358,6 @@ export class Wallet {
(x) => x.baseUrl)
.reduce(collectSmallestWithdraw, {}));
- console.log("smallest withdraws", smallestWithdraw);
-
let tx = this.q();
tx.iter(Stores.coins)
.reduce(collectBalances, balance);