aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-04-27 04:06:48 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-04-27 04:06:48 +0200
commitce97b1076b7e4a53b84d3fd34bf2047580ddeb22 (patch)
treebe365d6cf69b9c6a9b7841869727e57c1a152ad3 /src/wallet.ts
parent82b5754e157a1a3b22afe48c8366c76525eb91e3 (diff)
fix signature checks, add wire fee
Diffstat (limited to 'src/wallet.ts')
-rw-r--r--src/wallet.ts36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/wallet.ts b/src/wallet.ts
index 8b220ec4f..982801f43 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -601,7 +601,11 @@ export class Wallet {
* but only if the sum the coins' remaining value exceeds the payment amount.
*/
private async getCoinsForPayment(paymentAmount: AmountJson,
+ wireMethod: string,
+ wireFeeTime: number,
depositFeeLimit: AmountJson,
+ wireFeeLimit: AmountJson,
+ wireFeeAmortization: number,
allowedExchanges: ExchangeHandle[],
allowedAuditors: Auditor[]): Promise<CoinSelectionResult> {
@@ -610,7 +614,6 @@ export class Wallet {
for (let exchange of exchanges) {
let isOkay: boolean = false;
-
// is the exchange explicitly allowed?
for (let allowedExchange of allowedExchanges) {
if (allowedExchange.master_pub == exchange.masterPublicKey) {
@@ -677,6 +680,27 @@ export class Wallet {
cds.push({coin, denom});
}
+ let fees = await this.q().get(Stores.exchangeWireFees, exchange.baseUrl);
+ if (!fees) {
+ console.error("no fees found for exchange", exchange);
+ continue;
+ }
+
+ let wireFee: AmountJson|undefined = undefined;
+ for (let fee of (fees.feesForType[wireMethod] || [])) {
+ if (fee.startStamp >= wireFeeTime && fee.endStamp <= wireFeeTime) {
+ wireFee = fee.wireFee;
+ break;
+ }
+ }
+
+ if (wireFee) {
+ let amortizedWireFee = Amounts.divide(wireFee, wireFeeAmortization);
+ if (Amounts.cmp(wireFeeLimit, amortizedWireFee) < 0) {
+ paymentAmount = Amounts.add(amortizedWireFee, paymentAmount).amount;
+ }
+ }
+
let res = selectCoins(cds, paymentAmount, depositFeeLimit);
if (res) {
return {
@@ -766,7 +790,11 @@ export class Wallet {
}
let res = await this.getCoinsForPayment(offer.contract.amount,
+ offer.contract.wire_method,
+ getTalerStampSec(offer.contract.timestamp) || 0,
offer.contract.max_fee,
+ offer.contract.max_wire_fee || Amounts.getZero(offer.contract.amount.currency),
+ offer.contract.wire_fee_amortization || 1,
offer.contract.exchanges,
offer.contract.auditors);
@@ -802,7 +830,11 @@ export class Wallet {
// If not already payed, check if we could pay for it.
let res = await this.getCoinsForPayment(offer.contract.amount,
+ offer.contract.wire_method,
+ getTalerStampSec(offer.contract.timestamp) || 0,
offer.contract.max_fee,
+ offer.contract.max_wire_fee || Amounts.getZero(offer.contract.amount.currency),
+ offer.contract.wire_fee_amortization || 1,
offer.contract.exchanges,
offer.contract.auditors);
@@ -1427,7 +1459,7 @@ export class Wallet {
let valid: boolean = await this.cryptoApi.isValidWireFee(detail.type, wf, exchangeInfo.masterPublicKey);
if (!valid) {
console.error("fee signature invalid", fee);
- continue;
+ throw Error("fee signature invalid");
}
fees.push(wf);
}