From ce97b1076b7e4a53b84d3fd34bf2047580ddeb22 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 27 Apr 2017 04:06:48 +0200 Subject: fix signature checks, add wire fee --- src/wallet.ts | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/wallet.ts') 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 { @@ -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); } -- cgit v1.2.3