gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-wallet-core] branch master updated (82591a9b -> fab4


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-core] branch master updated (82591a9b -> fab4e338)
Date: Wed, 04 Sep 2019 15:28:25 +0200

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

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

    from 82591a9b don't show wrong balance
     new 604a7400 rudimentary history command
     new 5c809c3d wait for refreshes to finish before exiting integration test
     new fab4e338 deps / prettier

The 3 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:
 package.json                     |   1 +
 src/headless/integrationtest.ts  |   3 ++
 src/headless/taler-wallet-cli.ts |  50 +++++++++++++------
 src/wallet.ts                    | 104 ++++++++++++++++++++++++++++-----------
 yarn.lock                        |   5 ++
 5 files changed, 120 insertions(+), 43 deletions(-)

diff --git a/package.json b/package.json
index e0489154..a6b83ff1 100644
--- a/package.json
+++ b/package.json
@@ -33,6 +33,7 @@
     "nyc": "^14.1.1",
     "po2json": "^1.0.0-alpha",
     "pogen": "^0.0.5",
+    "prettier": "^1.18.2",
     "react": "^16.8.5",
     "react-dom": "^16.8.5",
     "structured-clone": "^0.2.2",
diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts
index 3b0069c2..3e60d418 100644
--- a/src/headless/integrationtest.ts
+++ b/src/headless/integrationtest.ts
@@ -83,5 +83,8 @@ export async function runIntegrationTest(args: {
     throw Error("payment did not succeed");
   }
 
+  const refreshRes = await myWallet.refreshDirtyCoins();
+  console.log(`waited to refresh ${refreshRes.numRefreshed} coins`);
+
   myWallet.stop();
 }
diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts
index da68f46a..ef9030fe 100644
--- a/src/headless/taler-wallet-cli.ts
+++ b/src/headless/taler-wallet-cli.ts
@@ -77,6 +77,22 @@ program
     process.exit(0);
   });
 
+
+program
+  .command("history")
+  .description("show wallet history")
+  .action(async () => {
+    applyVerbose(program.verbose);
+    console.log("history command called");
+    const wallet = await getDefaultNodeWallet({
+      persistentStoragePath: walletDbPath,
+    });
+    console.log("got wallet");
+    const history = await wallet.getHistory();
+    console.log(JSON.stringify(history, undefined, 2));
+    process.exit(0);
+  });
+
 async function asyncSleep(milliSeconds: number): Promise<void> {
   return new Promise<void>((resolve, reject) => {
     setTimeout(() => resolve(), milliSeconds);
@@ -285,25 +301,31 @@ program
     "amount to withdraw",
     "TESTKUDOS:10",
   )
-  .option("-s, --spend-amount <spend-amt>", "amount to spend", "TESTKUDOS:5")
+  .option("-s, --spend-amount <spend-amt>", "amount to spend", "TESTKUDOS:4")
   .description("Run integration test with bank, exchange and merchant.")
   .action(async cmdObj => {
     applyVerbose(program.verbose);
 
-    await runIntegrationTest({
-      amountToSpend: cmdObj.spendAmount,
-      amountToWithdraw: cmdObj.withdrawAmount,
-      bankBaseUrl: cmdObj.bank,
-      exchangeBaseUrl: cmdObj.exchange,
-      merchantApiKey: cmdObj.merchantApiKey,
-      merchantBaseUrl: cmdObj.merchant,
-      merchantInstance: cmdObj.merchantInstance,
-    }).catch(err => {
-      console.error("Failed with exception:");
-      console.error(err);
-    });
+    try {
+      await runIntegrationTest({
+        amountToSpend: cmdObj.spendAmount,
+        amountToWithdraw: cmdObj.withdrawAmount,
+        bankBaseUrl: cmdObj.bank,
+        exchangeBaseUrl: cmdObj.exchange,
+        merchantApiKey: cmdObj.merchantApiKey,
+        merchantBaseUrl: cmdObj.merchant,
+        merchantInstance: cmdObj.merchantInstance,
+      }).catch(err => {
+        console.error("Failed with exception:");
+        console.error(err);
+      });
+
+      process.exit(0);
+    } catch (e) {
+      console.error(e);
+      process.exit(1);
+    }
 
-    process.exit(0);
   });
 
 // error on unknown commands
diff --git a/src/wallet.ts b/src/wallet.ts
index 14ab4544..45bab48f 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -53,7 +53,6 @@ import {
   DenominationRecord,
   DenominationStatus,
   ExchangeRecord,
-  ExchangeWireFeesRecord,
   PreCoinRecord,
   ProposalDownloadRecord,
   PurchaseRecord,
@@ -132,7 +131,7 @@ interface SpeculativePayData {
  */
 export const WALLET_PROTOCOL_VERSION = "3:0:0";
 
-const WALLET_CACHE_BREAKER="01";
+const WALLET_CACHE_BREAKER = "01";
 
 const builtinCurrencies: CurrencyRecord[] = [
   {
@@ -360,6 +359,9 @@ export class Wallet {
   private activeProcessPreCoinOperations: {
     [preCoinPub: string]: Promise<void>;
   } = {};
+  private activeRefreshOperations: {
+    [coinPub: string]: Promise<void>;
+  } = {};
 
   /**
    * Set of identifiers for running operations.
@@ -943,10 +945,35 @@ export class Wallet {
       nextUrl,
       lastSessionId: sessionId,
     };
+
     return { nextUrl };
   }
 
   /**
+   * Refresh all dirty coins.
+   * The returned promise resolves only after all refresh
+   * operations have completed.
+   */
+  async refreshDirtyCoins(): Promise<{ numRefreshed: number }> {
+    let n = 0;
+    const coins = await this.q()
+      .iter(Stores.coins)
+      .toArray();
+    for (let coin of coins) {
+      if (coin.status == CoinStatus.Dirty) {
+        try {
+          await this.refresh(coin.coinPub);
+        } catch (e) {
+          console.log("error during refresh");
+        }
+
+        n += 1;
+      }
+    }
+    return { numRefreshed: n };
+  }
+
+  /**
    * Add a contract to the wallet and sign coins, and send them.
    */
   async confirmPay(
@@ -1955,7 +1982,9 @@ export class Wallet {
    */
   async updateExchangeFromUrl(baseUrl: string): Promise<ExchangeRecord> {
     baseUrl = canonicalizeBaseUrl(baseUrl);
-    const keysUrl = new 
URI("keys").absoluteTo(baseUrl).addQuery("cacheBreaker", WALLET_CACHE_BREAKER);
+    const keysUrl = new URI("keys")
+      .absoluteTo(baseUrl)
+      .addQuery("cacheBreaker", WALLET_CACHE_BREAKER);
     const keysResp = await this.http.get(keysUrl.href());
     if (keysResp.status !== 200) {
       throw Error("/keys request failed");
@@ -2419,32 +2448,49 @@ export class Wallet {
   }
 
   async refresh(oldCoinPub: string): Promise<void> {
-    const oldRefreshSessions = await this.q()
-      .iter(Stores.refresh)
-      .toArray();
-    for (const session of oldRefreshSessions) {
-      Wallet.enableTracing &&
-        console.log("got old refresh session for", oldCoinPub, session);
-      this.continueRefreshSession(session);
-    }
-    const coin = await this.q().get(Stores.coins, oldCoinPub);
-    if (!coin) {
-      console.warn("can't refresh, coin not in database");
-      return;
-    }
-    if (
-      coin.status === CoinStatus.Useless ||
-      coin.status === CoinStatus.Fresh
-    ) {
-      return;
+    const refreshImpl = async () => {
+      const oldRefreshSessions = await this.q()
+        .iter(Stores.refresh)
+        .toArray();
+      for (const session of oldRefreshSessions) {
+        Wallet.enableTracing &&
+          console.log("got old refresh session for", oldCoinPub, session);
+        return this.continueRefreshSession(session);
+      }
+      const coin = await this.q().get(Stores.coins, oldCoinPub);
+      if (!coin) {
+        console.warn("can't refresh, coin not in database");
+        return;
+      }
+      if (
+        coin.status === CoinStatus.Useless ||
+        coin.status === CoinStatus.Fresh
+      ) {
+        return;
+      }
+      const refreshSession = await this.createRefreshSession(oldCoinPub);
+      if (!refreshSession) {
+        // refreshing not necessary
+        Wallet.enableTracing && console.log("not refreshing", oldCoinPub);
+        return;
+      }
+      return this.continueRefreshSession(refreshSession);
+    };
+
+    const activeRefreshOp = this.activeRefreshOperations[oldCoinPub];
+
+    if (activeRefreshOp) {
+      return activeRefreshOp;
     }
-    const refreshSession = await this.createRefreshSession(oldCoinPub);
-    if (!refreshSession) {
-      // refreshing not necessary
-      Wallet.enableTracing && console.log("not refreshing", oldCoinPub);
-      return;
+
+    try {
+      const newOp = refreshImpl();
+      this.activeRefreshOperations[oldCoinPub] = newOp;
+      const res = await newOp;
+      return res;
+    } finally {
+      delete this.activeRefreshOperations[oldCoinPub];
     }
-    this.continueRefreshSession(refreshSession);
   }
 
   async continueRefreshSession(refreshSession: RefreshSessionRecord) {
@@ -3617,8 +3663,8 @@ export class Wallet {
     const refundsDoneFees = Object.values(purchase.refundsDone).map(x =>
       Amounts.parseOrThrow(x.refund_amount),
     );
-    const refundsPendingFees = Object.values(purchase.refundsPending).map(
-      x => Amounts.parseOrThrow(x.refund_amount),
+    const refundsPendingFees = Object.values(purchase.refundsPending).map(x =>
+      Amounts.parseOrThrow(x.refund_amount),
     );
     const totalRefundFees = Amounts.sum([
       ...refundsDoneFees,
diff --git a/yarn.lock b/yarn.lock
index 15ddd365..63cf700a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5311,6 +5311,11 @@ prepend-http@^2.0.0:
   resolved 
"https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897";
   integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
 
+prettier@^1.18.2:
+  version "1.18.2"
+  resolved 
"https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea";
+  integrity 
sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==
+
 pretty-hrtime@^1.0.0:
   version "1.0.3"
   resolved 
"https://registry.yarnpkg.com/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1";

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



reply via email to

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