gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-wallet-webex] 01/02: use full amount with wire fees


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] 01/02: use full amount with wire fees when creating deposit permission
Date: Thu, 18 Jan 2018 01:37:43 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-webex.

commit d4c2f6f6f992c36609c4a029afcb378a7f839ddf
Author: Florian Dold <address@hidden>
AuthorDate: Wed Jan 17 05:33:06 2018 +0100

    use full amount with wire fees when creating deposit permission
---
 src/crypto/cryptoApi.ts    |  5 +++--
 src/crypto/cryptoWorker.ts |  5 +++--
 src/wallet.ts              | 21 +++++++++++++++------
 src/walletTypes.ts         |  4 ++++
 4 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/crypto/cryptoApi.ts b/src/crypto/cryptoApi.ts
index 1f45ba8e..c1f3f424 100644
--- a/src/crypto/cryptoApi.ts
+++ b/src/crypto/cryptoApi.ts
@@ -293,8 +293,9 @@ export class CryptoApi {
   }
 
   signDeposit(contractTerms: ContractTerms,
-              cds: CoinWithDenom[]): Promise<PayCoinInfo> {
-    return this.doRpc<PayCoinInfo>("signDeposit", 3, contractTerms, cds);
+              cds: CoinWithDenom[],
+              totalAmount: AmountJson): Promise<PayCoinInfo> {
+    return this.doRpc<PayCoinInfo>("signDeposit", 3, contractTerms, cds, 
totalAmount);
   }
 
   createEddsaKeypair(): Promise<{priv: string, pub: string}> {
diff --git a/src/crypto/cryptoWorker.ts b/src/crypto/cryptoWorker.ts
index b7c8e933..6b82f6bc 100644
--- a/src/crypto/cryptoWorker.ts
+++ b/src/crypto/cryptoWorker.ts
@@ -269,7 +269,8 @@ namespace RpcFunctions {
    * and deposit permissions for each given coin.
    */
   export function signDeposit(contractTerms: ContractTerms,
-                              cds: CoinWithDenom[]): PayCoinInfo {
+                              cds: CoinWithDenom[],
+                              totalAmount: AmountJson): PayCoinInfo {
     const ret: PayCoinInfo = {
       originalCoins: [],
       sigs: [],
@@ -282,7 +283,7 @@ namespace RpcFunctions {
     let fees = Amounts.add(Amounts.getZero(feeList[0].currency), 
...feeList).amount;
     // okay if saturates
     fees = Amounts.sub(fees, contractTerms.max_fee).amount;
-    const total = Amounts.add(fees, contractTerms.amount).amount;
+    const total = Amounts.add(fees, totalAmount).amount;
 
     const amountSpent = 
native.Amount.getZero(cds[0].coin.currentAmount.currency);
     const amountRemaining = new native.Amount(total);
diff --git a/src/wallet.ts b/src/wallet.ts
index 24fab9f8..91da5873 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -593,15 +593,23 @@ export class Wallet {
         continue;
       }
 
+      console.log("payment coins: wireFeeLimit", wireFeeLimit);
+      console.log("payment coins: wireFeeAmortization", wireFeeAmortization);
+      console.log("payment coins: fees", fees);
+      console.log("payment coins: wireMethod", wireMethod);
+      console.log("payment coins: wireFeeTime", wireFeeTime);
+
       let totalFees = Amounts.getZero(currency);
       let wireFee: AmountJson|undefined;
       for (const fee of (fees.feesForType[wireMethod] || [])) {
-        if (fee.startStamp >= wireFeeTime && fee.endStamp <= wireFeeTime) {
+        if (fee.startStamp <= wireFeeTime && fee.endStamp >= wireFeeTime) {
           wireFee = fee.wireFee;
           break;
         }
       }
 
+      console.log("payment coins: current wire fees", wireFee);
+
       if (wireFee) {
         const amortizedWireFee = Amounts.divide(wireFee, wireFeeAmortization);
         if (Amounts.cmp(wireFeeLimit, amortizedWireFee) < 0) {
@@ -616,6 +624,7 @@ export class Wallet {
         return {
           cds: res.cds,
           exchangeUrl: exchange.baseUrl,
+          totalAmount: remainingAmount,
           totalFees,
         };
       }
@@ -766,8 +775,8 @@ export class Wallet {
 
     const sd = await this.getSpeculativePayData(proposalId);
     if (!sd) {
-      const { exchangeUrl, cds } = res;
-      const payCoinInfo = await 
this.cryptoApi.signDeposit(proposal.contractTerms, cds);
+      const { exchangeUrl, cds, totalAmount } = res;
+      const payCoinInfo = await 
this.cryptoApi.signDeposit(proposal.contractTerms, cds, totalAmount);
       purchase = await this.recordConfirmPay(proposal, payCoinInfo, 
exchangeUrl);
     } else {
       purchase = await this.recordConfirmPay(sd.proposal, sd.payCoinInfo, 
sd.exchangeUrl);
@@ -844,8 +853,8 @@ export class Wallet {
 
     // Only create speculative signature if we don't already have one for this 
proposal
     if ((!this.speculativePayData) || (this.speculativePayData && 
this.speculativePayData.proposalId !== proposalId)) {
-      const { exchangeUrl, cds } = res;
-      const payCoinInfo = await 
this.cryptoApi.signDeposit(proposal.contractTerms, cds);
+      const { exchangeUrl, cds, totalAmount } = res;
+      const payCoinInfo = await 
this.cryptoApi.signDeposit(proposal.contractTerms, cds, totalAmount);
       this.speculativePayData = {
         exchangeUrl,
         payCoinInfo,
@@ -2456,7 +2465,7 @@ export class Wallet {
 
     const contractTermsHash = await 
this.cryptoApi.hashString(canonicalJson(contractTerms));
 
-    const payCoinInfo = await this.cryptoApi.signDeposit(contractTerms, cds);
+    const payCoinInfo = await this.cryptoApi.signDeposit(contractTerms, cds, 
contractTerms.amount);
 
     console.log("pci", payCoinInfo);
 
diff --git a/src/walletTypes.ts b/src/walletTypes.ts
index d1a4f874..45a79587 100644
--- a/src/walletTypes.ts
+++ b/src/walletTypes.ts
@@ -415,6 +415,10 @@ export interface CoinSelectionResult {
   exchangeUrl: string;
   cds: CoinWithDenom[];
   totalFees: AmountJson;
+  /**
+   * Total amount, including wire fees payed by the customer.
+   */
+  totalAmount: AmountJson;
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]