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: simplify coin status, don't sho


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] 01/02: simplify coin status, don't show refreshed coins in balance
Date: Thu, 13 Apr 2017 16:14:51 +0200

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

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

commit 75cf7ac3c3a00b29fab15b1fe3696617918fc643
Author: Florian Dold <address@hidden>
AuthorDate: Thu Apr 13 16:08:41 2017 +0200

    simplify coin status, don't show refreshed coins in balance
---
 src/cryptoLib.ts   |  5 ++---
 src/pages/tree.tsx |  5 ++---
 src/types.ts       | 18 ++++++++----------
 src/wallet.ts      | 22 +++++++++++-----------
 src/wxBackend.ts   |  2 +-
 5 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/src/cryptoLib.ts b/src/cryptoLib.ts
index 7a363e6..717a681 100644
--- a/src/cryptoLib.ts
+++ b/src/cryptoLib.ts
@@ -24,7 +24,7 @@
 import * as native from "./emscriptif";
 import {
   PreCoinRecord, PayCoinInfo, AmountJson,
-  RefreshSessionRecord, RefreshPreCoinRecord, ReserveRecord
+  RefreshSessionRecord, RefreshPreCoinRecord, ReserveRecord, CoinStatus,
 } from "./types";
 import create = chrome.alarms.create;
 import {OfferRecord} from "./wallet";
@@ -210,8 +210,7 @@ namespace RpcFunctions {
       let newAmount = new native.Amount(cd.coin.currentAmount);
       newAmount.sub(coinSpend);
       cd.coin.currentAmount = newAmount.toJson();
-      cd.coin.dirty = true;
-      cd.coin.transactionPending = true;
+      cd.coin.status = CoinStatus.TransactionPending;
 
       let d = new native.DepositRequestPS({
         h_contract: native.HashCode.fromCrock(offer.H_contract),
diff --git a/src/pages/tree.tsx b/src/pages/tree.tsx
index dab6371..4909c18 100644
--- a/src/pages/tree.tsx
+++ b/src/pages/tree.tsx
@@ -21,7 +21,7 @@
  */
 
 
-import {ExchangeRecord, DenominationRecord} from "src/types";
+import {ExchangeRecord, DenominationRecord, CoinStatus} from "src/types";
 import { ReserveRecord, CoinRecord, PreCoinRecord, Denomination } from 
"src/types";
 import { ImplicitStateComponent, StateHolder } from "src/components";
 import {
@@ -124,8 +124,7 @@ class CoinView extends React.Component<CoinViewProps, void> 
{
           <li>Current amount: {prettyAmount(c.currentAmount)}</li>
           <li>Denomination: <ExpanderText text={c.denomPub} /></li>
           <li>Suspended: {(c.suspended || false).toString()}</li>
-          <li>Dirty: {(c.dirty || false).toString()}</li>
-          <li>Transaction Pending: {(c.transactionPending || 
false).toString()}</li>
+          <li>Status: {CoinStatus[c.status]}</li>
           <li><RefreshDialog coin={c} /></li>
         </ul>
       </div>
diff --git a/src/types.ts b/src/types.ts
index 5b2fa28..87b77b8 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -347,6 +347,12 @@ export interface CoinPaySig {
   f: AmountJson;
 }
 
+
+export enum CoinStatus {
+  Fresh, TransactionPending, Dirty, Refreshed,
+}
+
+
 /**
  * CoinRecord as stored in the "coins" data store
  * of the wallet database.
@@ -391,17 +397,9 @@ export interface CoinRecord {
   suspended?: boolean;
 
   /**
-   * Was the coin revealed in a transaction?
-   */
-  dirty: boolean;
-
-  /**
-   * Is the coin currently involved in a transaction?
-   *
-   * This delays refreshing until the transaction is finished or
-   * aborted.
+   * Status of the coin.
    */
-  transactionPending: boolean;
+  status: CoinStatus;
 }
 
 
diff --git a/src/wallet.ts b/src/wallet.ts
index 916d8e1..b47a825 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -42,6 +42,7 @@ import {
   WalletBalance,
   WalletBalanceEntry,
   WireInfo, DenominationRecord, DenominationStatus, denominationRecordFromKeys,
+  CoinStatus,
 } from "./types";
 import {
   HttpRequestLibrary,
@@ -266,7 +267,7 @@ export function selectCoins(cds: CoinWithDenom[], 
paymentAmount: AmountJson,
     if (coin.suspended) {
       continue;
     }
-    if (coin.dirty) {
+    if (coin.status != CoinStatus.Fresh) {
       continue;
     }
     if (Amounts.cmp(denom.feeDeposit, coin.currentAmount) >= 0) {
@@ -526,7 +527,7 @@ export class Wallet {
     this.q()
         .iter(Stores.coins)
         .reduce((c: CoinRecord) => {
-          if (c.dirty && !c.transactionPending && !(c.currentAmount.value == 0 
&& c.currentAmount.fraction == 0)) {
+          if (c.status == CoinStatus.Dirty) {
             console.log("resuming pending refresh for coin", c);
             this.refresh(c.coinPub);
           }
@@ -581,10 +582,7 @@ export class Wallet {
         if (coin.suspended) {
           continue;
         }
-        if (coin.dirty) {
-          continue;
-        }
-        if (coin.transactionPending) {
+        if (coin.status != CoinStatus.Fresh) {
           continue;
         }
         cds.push({coin, denom});
@@ -989,8 +987,7 @@ export class Wallet {
       denomSig: denomSig,
       currentAmount: pc.coinValue,
       exchangeBaseUrl: pc.exchangeBaseUrl,
-      dirty: false,
-      transactionPending: false,
+      status: CoinStatus.Fresh,
     };
     return coin;
   }
@@ -1348,6 +1345,9 @@ export class Wallet {
       if (c.suspended) {
         return balance;
       }
+      if (!(c.status == CoinStatus.Dirty || c.status == CoinStatus.Fresh)) {
+        return balance;
+      }
       let currency = c.currentAmount.currency;
       let entry = ensureEntry(balance, currency);
       entry.available = Amounts.add(entry.available, c.currentAmount).amount;
@@ -1496,6 +1496,7 @@ export class Wallet {
         throw AbortTransaction;
       }
       c.currentAmount = r.amount;
+      c.status = CoinStatus.Refreshed;
       return c;
     }
 
@@ -1667,8 +1668,7 @@ export class Wallet {
         denomSig: denomSig,
         currentAmount: denom.value,
         exchangeBaseUrl: refreshSession.exchangeBaseUrl,
-        dirty: false,
-        transactionPending: false,
+        status: CoinStatus.Fresh,
       };
 
       coins.push(coin);
@@ -1787,7 +1787,7 @@ export class Wallet {
           console.error("coin not found");
           return;
         }
-        c.transactionPending = false;
+        c.status = CoinStatus.Dirty;
         modifiedCoins.push(c);
       }
 
diff --git a/src/wxBackend.ts b/src/wxBackend.ts
index 7b1a2b3..f31472c 100644
--- a/src/wxBackend.ts
+++ b/src/wxBackend.ts
@@ -35,7 +35,7 @@ import * as logging from "./logging";
 "use strict";
 
 const DB_NAME = "taler";
-const DB_VERSION = 15;
+const DB_VERSION = 16;
 
 import {Stores} from "./wallet";
 import {Store, Index} from "./query";

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



reply via email to

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