gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-wallet-webex] branch master updated (665e88c7 -> 435


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] branch master updated (665e88c7 -> 43575b59)
Date: Sun, 27 Aug 2017 06:48:02 +0200

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

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

    from 665e88c7 node_modules
     new ccc6d822 canonicalize account info JSON when collecting them
     new 63914ab5 make sure that refreshing works after refund
     new b47522c1 proper rounding for amount operations
     new 43575b59 show error in create reserve dialog

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/query.ts                               | 18 +++++++++++--
 src/types.ts                               |  9 +++++--
 src/wallet.ts                              | 43 ++++++++++++++++++------------
 src/webex/pages/confirm-create-reserve.tsx | 11 +++-----
 src/webex/wxBackend.ts                     |  2 +-
 5 files changed, 54 insertions(+), 29 deletions(-)

diff --git a/src/query.ts b/src/query.ts
index ee1ac260..d7689f2b 100644
--- a/src/query.ts
+++ b/src/query.ts
@@ -547,9 +547,18 @@ export class QueryRoot {
 
   private finished: boolean = false;
 
+  private keys: { [keyName: string]: IDBValidKey } = {};
+
   constructor(public db: IDBDatabase) {
   }
 
+  /**
+   * Get a named key that was created during the query.
+   */
+  key(keyName: string): IDBValidKey|undefined {
+    return this.keys[keyName];
+  }
+
   private checkFinished() {
     if (this.finished) {
       throw Error("Can't add work to query after it was started");
@@ -627,10 +636,15 @@ export class QueryRoot {
    * Overrides if an existing object with the same key exists
    * in the store.
    */
-  put<T>(store: Store<T>, val: T): QueryRoot {
+  put<T>(store: Store<T>, val: T, keyName?: string): QueryRoot {
     this.checkFinished();
     const doPut = (tx: IDBTransaction) => {
-      tx.objectStore(store.name).put(val);
+      const req = tx.objectStore(store.name).put(val);
+      if (keyName) {
+        req.onsuccess = () => {
+            this.keys[keyName] = req.result;
+        };
+      }
     };
     this.scheduleFinish();
     this.addWork(doPut, store.name, true);
diff --git a/src/types.ts b/src/types.ts
index aabf4ffc..d016b7fe 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -759,6 +759,11 @@ export interface RefreshSessionRecord {
    * Is this session finished?
    */
   finished: boolean;
+
+  /**
+   * Record ID when retrieved from the DB.
+   */
+  id?: number;
 }
 
 
@@ -1307,7 +1312,7 @@ export namespace Amounts {
       }
 
       value = value + x.value + Math.floor((fraction + x.fraction) / 
fractionalBase);
-      fraction = (fraction + x.fraction) % fractionalBase;
+      fraction = Math.floor((fraction + x.fraction) % fractionalBase);
       if (value > Number.MAX_SAFE_INTEGER) {
         return { amount: getMaxAmount(currency), saturated: true };
       }
@@ -1435,7 +1440,7 @@ export namespace Amounts {
   export function fromFloat(floatVal: number, currency: string) {
     return {
       currency,
-      fraction: (floatVal - Math.floor(floatVal)) * fractionalBase,
+      fraction: Math.floor((floatVal - Math.floor(floatVal)) * fractionalBase),
       value: Math.floor(floatVal),
     };
   }
diff --git a/src/wallet.ts b/src/wallet.ts
index b892e2e4..3d095fc0 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -413,6 +413,8 @@ export function selectPayCoins(cds: CoinWithDenom[], 
paymentAmount: AmountJson,
                                                   denom.feeDeposit).amount) >= 
0;
     isBelowFee = Amounts.cmp(accFee, depositFeeLimit) <= 0;
 
+    console.log("coin selection", { coversAmount, isBelowFee, accFee, 
accAmount, paymentAmount });
+
     if ((coversAmount && isBelowFee) || coversAmountWithFee) {
       return cdsResult;
     }
@@ -555,7 +557,7 @@ export namespace Stores {
   export const nonces = new NonceStore();
   export const precoins = new Store<PreCoinRecord>("precoins", {keyPath: 
"coinPub"});
   export const proposals = new ProposalsStore();
-  export const refresh = new Store<RefreshSessionRecord>("refresh", {keyPath: 
"meltCoinPub"});
+  export const refresh = new Store<RefreshSessionRecord>("refresh", {keyPath: 
"id", autoIncrement: true});
   export const reserves = new Store<ReserveRecord>("reserves", {keyPath: 
"reserve_pub"});
   export const purchases = new PurchasesStore();
 }
@@ -759,6 +761,8 @@ export class Wallet {
       cds.push({coin, denom});
     }
 
+    console.log("coin return:  selecting from possible coins", { cds, amount } 
);
+
     return selectPayCoins(cds, amount, amount);
   }
 
@@ -1836,7 +1840,7 @@ export class Wallet {
       if (c.suspended) {
         return balance;
       }
-      if (!(c.status === CoinStatus.Dirty || c.status === CoinStatus.Fresh)) {
+      if (!(c.status === CoinStatus.Fresh)) {
         return balance;
       }
       console.log("collecting balance");
@@ -1999,25 +2003,30 @@ export class Wallet {
 
     // Store refresh session and subtract refreshed amount from
     // coin in the same transaction.
-    await this.q()
-              .put(Stores.refresh, refreshSession)
-              .mutate(Stores.coins, coin.coinPub, mutateCoin)
-              .finish();
+    const query = this.q();
+    query.put(Stores.refresh, refreshSession, "refreshKey")
+         .mutate(Stores.coins, coin.coinPub, mutateCoin);
+    await query.finish();
+
+    const key = query.key("refreshKey");
+    if (!key || typeof key !== "number") {
+      throw Error("insert failed");
+    }
+
+    refreshSession.id = key;
 
     return refreshSession;
   }
 
 
   async refresh(oldCoinPub: string): Promise<void> {
-    let refreshSession: RefreshSessionRecord|undefined;
-    const oldSession = await this.q().get(Stores.refresh, oldCoinPub);
-    if (oldSession) {
-      console.log("got old session for", oldCoinPub);
-      console.log(oldSession);
-      refreshSession = oldSession;
-    } else {
-      refreshSession = await this.createRefreshSession(oldCoinPub);
+
+    const oldRefreshSessions = await this.q().iter(Stores.refresh).toArray();
+    for (const session of oldRefreshSessions) {
+      console.log("got old session for", oldCoinPub, session);
+      this.continueRefreshSession(session);
     }
+    let refreshSession = await this.createRefreshSession(oldCoinPub);
     if (!refreshSession) {
       // refreshing not necessary
       console.log("not refreshing", oldCoinPub);
@@ -2031,9 +2040,8 @@ export class Wallet {
       return;
     }
     if (typeof refreshSession.norevealIndex !== "number") {
-      const coinPub = refreshSession.meltCoinPub;
       await this.refreshMelt(refreshSession);
-      const r = await this.q().get<RefreshSessionRecord>(Stores.refresh, 
coinPub);
+      const r = await this.q().get<RefreshSessionRecord>(Stores.refresh, 
refreshSession.id);
       if (!r) {
         throw Error("refresh session does not exist anymore");
       }
@@ -2413,7 +2421,7 @@ export class Wallet {
     const senderWiresSet = new Set();
     await this.q().iter(Stores.reserves).map((x) => {
       if (x.senderWire) {
-        senderWiresSet.add(JSON.stringify(x.senderWire));
+        senderWiresSet.add(canonicalJson(x.senderWire));
       }
     }).run();
     const senderWires = Array.from(senderWiresSet).map((x) => JSON.parse(x));
@@ -2441,6 +2449,7 @@ export class Wallet {
       console.error(`Exchange ${req.exchange} not known to the wallet`);
       return;
     }
+    console.log("selecting coins for return:", req);
     const cds = await this.getCoinsForReturn(req.exchange, req.amount);
     console.log(cds);
 
diff --git a/src/webex/pages/confirm-create-reserve.tsx 
b/src/webex/pages/confirm-create-reserve.tsx
index f957364c..7d543860 100644
--- a/src/webex/pages/confirm-create-reserve.tsx
+++ b/src/webex/pages/confirm-create-reserve.tsx
@@ -371,7 +371,7 @@ class ExchangeSelection extends 
ImplicitStateComponent<ExchangeSelectionProps> {
     if (this.statusString()) {
       return (
         <p>
-          <strong style={{color: "red"}}>{i18n.str`A problem occured, see 
below. ${this.statusString()}`}</strong>
+          <strong style={{color: "red"}}>{this.statusString()}</strong>
         </p>
       );
     }
@@ -515,12 +515,9 @@ class ExchangeSelection extends 
ImplicitStateComponent<ExchangeSelectionProps> {
       console.dir(r);
     } catch (e) {
       console.log("get exchange info rejected", e);
-      if (e.hasOwnProperty("httpStatus")) {
-        this.statusString(`Error: request failed with status ${e.httpStatus}`);
-      } else if (e.hasOwnProperty("errorResponse")) {
-        const resp = e.errorResponse;
-        this.statusString(`Error: ${resp.error} (${resp.hint})`);
-      }
+      this.statusString(`Error: ${e.message}`);
+      // Re-try every 5 seconds as long as there is a problem
+      setTimeout(() => this.statusString() ? this.forceReserveUpdate() : 
undefined, 5000);
     }
   }
 
diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts
index 0d1c2d8c..2f249af4 100644
--- a/src/webex/wxBackend.ts
+++ b/src/webex/wxBackend.ts
@@ -352,7 +352,7 @@ async function dispatch(req: any, sender: any, 
sendResponse: any): Promise<void>
     try {
       sendResponse({
         error: "exception",
-        hint: e.message,
+        message: e.message,
         stack,
       });
     } catch (e) {

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



reply via email to

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