aboutsummaryrefslogtreecommitdiff
path: root/extension/background/wallet.js
diff options
context:
space:
mode:
Diffstat (limited to 'extension/background/wallet.js')
-rw-r--r--extension/background/wallet.js23
1 files changed, 14 insertions, 9 deletions
diff --git a/extension/background/wallet.js b/extension/background/wallet.js
index 905febf09..f1711b435 100644
--- a/extension/background/wallet.js
+++ b/extension/background/wallet.js
@@ -34,21 +34,24 @@ function signDeposit(db, offer, cds) {
}
amountSpent.add(coinSpend);
amountRemaining.sub(coinSpend);
- let d = new DepositRequestPS({
+ let newAmount = new Amount(cd.coin.currentAmount);
+ newAmount.sub(coinSpend);
+ cd.coin.currentAmount = newAmount.toJson();
+ let args = {
h_contract: HashCode.fromCrock(offer.H_contract),
h_wire: HashCode.fromCrock(offer.contract.H_wire),
- amount_with_fee: new Amount(cd.coin.currentAmount).toNbo(),
+ amount_with_fee: coinSpend.toNbo(),
coin_pub: EddsaPublicKey.fromCrock(cd.coin.coinPub),
deposit_fee: new Amount(cd.denom.fee_deposit).toNbo(),
merchant: EddsaPublicKey.fromCrock(offer.contract.merchant_pub),
refund_deadline: AbsoluteTimeNbo.fromTalerString(offer.contract.refund_deadline),
timestamp: AbsoluteTimeNbo.fromTalerString(offer.contract.timestamp),
transaction_id: UInt64.fromNumber(offer.contract.transaction_id),
- });
- let newAmount = new Amount(cd.coin.currentAmount);
- newAmount.sub(coinSpend);
- cd.coin.currentAmount = newAmount.toJson();
- console.log("DepositRequestPS: ", d.toPurpose().hexdump());
+ };
+ let d = new DepositRequestPS(args);
+ console.log("Deposit request #" + ret.length);
+ console.log("DepositRequestPS: \n", d.toJson());
+ console.log("DepositRequestPS sig: \n", d.toPurpose().hexdump());
let coinSig = eddsaSign(d.toPurpose(), EddsaPrivateKey.fromCrock(cd.coin.coinPriv))
.toCrock();
let s = {
@@ -56,7 +59,7 @@ function signDeposit(db, offer, cds) {
coin_pub: cd.coin.coinPub,
ub_sig: cd.coin.denomSig,
denom_pub: cd.coin.denomPub,
- f: amountSpent.toJson(),
+ f: coinSpend.toJson(),
};
ret.push({ sig: s, updatedCoin: cd.coin });
}
@@ -126,6 +129,7 @@ function getPossibleMintCoins(db, paymentAmount, depositFeeLimit, allowedMints)
let minAmount = new Amount(paymentAmount);
let accFee = new Amount(coins[0].c.denom.fee_deposit);
let accAmount = Amount.getZero(coins[0].c.coin.currentAmount.currency);
+ let usableCoins = [];
nextCoin: for (let i = 0; i < coins.length; i++) {
let coinAmount = new Amount(coins[i].c.coin.currentAmount);
let coinFee = coins[i].a;
@@ -138,8 +142,9 @@ function getPossibleMintCoins(db, paymentAmount, depositFeeLimit, allowedMints)
console.log("too much fees");
continue nextMint;
}
+ usableCoins.push(coins[i].c);
if (accAmount.cmp(minAmount) >= 0) {
- ret[key] = m[key];
+ ret[key] = usableCoins;
continue nextMint;
}
}