gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-wallet-webex] 01/03: refactor submitPay


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] 01/03: refactor submitPay
Date: Mon, 29 Jan 2018 16:41:29 +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 aec2c1301edd6c62b7665d4bfbf2087927f9419b
Author: Florian Dold <address@hidden>
AuthorDate: Tue Jan 23 16:19:03 2018 +0100

    refactor submitPay
---
 src/wallet.ts | 70 +++++++++++++++++++++++++----------------------------------
 1 file changed, 30 insertions(+), 40 deletions(-)

diff --git a/src/wallet.ts b/src/wallet.ts
index 01db8c61..8167556f 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -745,7 +745,36 @@ export class Wallet {
       fu.addSearch("session_sig", merchantResp.session_sig);
       await this.q().put(Stores.purchases, purchase).finish();
     }
-    await this.paymentSucceeded(purchase.contractTermsHash, merchantResp.sig);
+
+    const merchantPub = purchase.contractTerms.merchant_pub;
+    const valid: boolean = await (
+      this.cryptoApi.isValidPaymentSignature(merchantResp.sig, 
contractTermsHash, merchantPub)
+    );
+    if (!valid) {
+      console.error("merchant payment signature invalid");
+      // FIXME: properly display error
+      throw Error("merchant payment signature invalid");
+    }
+    purchase.finished = true;
+    const modifiedCoins: CoinRecord[] = [];
+    for (const pc of purchase.payReq.coins) {
+      const c = await this.q().get<CoinRecord>(Stores.coins, pc.coin_pub);
+      if (!c) {
+        console.error("coin not found");
+        throw Error("coin used in payment not found");
+      }
+      c.status = CoinStatus.Dirty;
+      modifiedCoins.push(c);
+    }
+
+    await this.q()
+              .putAll(Stores.coins, modifiedCoins)
+              .put(Stores.purchases, purchase)
+              .finish();
+    for (const c of purchase.payReq.coins) {
+      this.refresh(c.coin_pub);
+    }
+
     const nextUrl = fu.href();
     this.cachedNextUrl[purchase.contractTerms.fulfillment_url] = { nextUrl, 
lastSessionId: sessionId };
     return { nextUrl };
@@ -2245,45 +2274,6 @@ export class Wallet {
   }
 
 
-  private async paymentSucceeded(contractTermsHash: string, merchantSig: 
string): Promise<any> {
-    const doPaymentSucceeded = async() => {
-      const t = await this.q().get<PurchaseRecord>(Stores.purchases,
-                                                   contractTermsHash);
-      if (!t) {
-        console.error("contract not found");
-        return;
-      }
-      const merchantPub = t.contractTerms.merchant_pub;
-      const valid = this.cryptoApi.isValidPaymentSignature(merchantSig, 
contractTermsHash, merchantPub);
-      if (!valid) {
-        console.error("merchant payment signature invalid");
-        // FIXME: properly display error
-        return;
-      }
-      t.finished = true;
-      const modifiedCoins: CoinRecord[] = [];
-      for (const pc of t.payReq.coins) {
-        const c = await this.q().get<CoinRecord>(Stores.coins, pc.coin_pub);
-        if (!c) {
-          console.error("coin not found");
-          return;
-        }
-        c.status = CoinStatus.Dirty;
-        modifiedCoins.push(c);
-      }
-
-      await this.q()
-                .putAll(Stores.coins, modifiedCoins)
-                .put(Stores.purchases, t)
-                .finish();
-      for (const c of t.payReq.coins) {
-        this.refresh(c.coin_pub);
-      }
-    };
-    doPaymentSucceeded();
-    return;
-  }
-
   async payback(coinPub: string): Promise<void> {
     let coin = await this.q().get(Stores.coins, coinPub);
     if (!coin) {

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



reply via email to

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