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: have from contr


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] branch master updated: have from contract, remove extended contract query
Date: Fri, 03 Mar 2017 15:37:20 +0100

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 1637127  have from contract, remove extended contract query
1637127 is described below

commit 16371276588b34769a09d940e608426b06ec3163
Author: Florian Dold <address@hidden>
AuthorDate: Fri Mar 3 15:37:04 2017 +0100

    have from contract, remove extended contract query
---
 src/content_scripts/notify.ts |  9 +++++----
 src/types.ts                  |  3 +++
 src/wallet.ts                 | 26 ++++++--------------------
 src/wxBackend.ts              | 38 ++++++++++++++------------------------
 web-common                    |  2 +-
 5 files changed, 29 insertions(+), 49 deletions(-)

diff --git a/src/content_scripts/notify.ts b/src/content_scripts/notify.ts
index a731e4d..07ce879 100644
--- a/src/content_scripts/notify.ts
+++ b/src/content_scripts/notify.ts
@@ -76,11 +76,10 @@ namespace TalerNotify {
     });
   }
 
-  function queryPayment(query: any): Promise<any> {
-    // current URL without fragment
+  function queryPayment(url: string): Promise<any> {
     const walletMsg = {
       type: "query-payment",
-      detail: query,
+      detail: { url },
     };
     return new Promise((resolve, reject) => {
       chrome.runtime.sendMessage(walletMsg, (resp: any) => {
@@ -331,7 +330,9 @@ namespace TalerNotify {
     });
 
     addHandler("taler-pay", async(msg: any, sendResponse: any) => {
-      let res = await queryPayment(msg.contract_query);
+      // current URL without fragment
+      let url = URI(document.location.href).fragment("").href();
+      let res = await queryPayment(url);
       logVerbose && console.log("taler-pay: got response", res);
       if (res && res.payReq) {
         sendResponse(res);
diff --git a/src/types.ts b/src/types.ts
index 28c989a..f28cdb4 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -484,6 +484,9 @@ export class Contract {
   order_id: string;
 
   @Checkable.String
+  pay_url: string;
+
+  @Checkable.String
   fulfillment_url: string;
 
   @Checkable.Any
diff --git a/src/wallet.ts b/src/wallet.ts
index 01d26c2..50febf9 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -669,27 +669,13 @@ export class Wallet {
 
 
   /**
-   * Retrieve all necessary information for looking up the contract
-   * with the given hash.
+   * Retrieve information required to pay for a contract, where the
+   * contract is identified via the fulfillment url.
    */
-  async queryPayment(query: any): Promise<any> {
-    let t: TransactionRecord | undefined;
-
-    console.log("query for payment", query);
-
-    switch (query.type) {
-      case "fulfillment_url":
-        t = await this.q().getIndexed(Stores.transactions.fulfillmentUrlIndex, 
query.value);
-        break;
-      case "order_id":
-        t = await this.q().getIndexed(Stores.transactions.orderIdIndex, 
query.value);
-        break;
-      case "hash":
-        t = await this.q().get<TransactionRecord>(Stores.transactions, 
query.value);
-        break;
-      default:
-        throw Error("invalid type");
-    }
+  async queryPayment(url: string): Promise<any> {
+    console.log("query for payment", url);
+
+    const t = await 
this.q().getIndexed(Stores.transactions.fulfillmentUrlIndex, url);
 
     if (!t) {
       console.log("query for payment failed");
diff --git a/src/wxBackend.ts b/src/wxBackend.ts
index 5957e1e..ad738ac 100644
--- a/src/wxBackend.ts
+++ b/src/wxBackend.ts
@@ -155,7 +155,7 @@ function makeHandlers(db: IDBDatabase,
           return Promise.resolve(msg);
         }
       }
-      return wallet.queryPayment(detail);
+      return wallet.queryPayment(detail.url);
     },
     ["exchange-info"]: function (detail) {
       if (!detail.baseUrl) {
@@ -318,6 +318,13 @@ class ChromeNotifier implements Notifier {
  */
 let paymentRequestCookies: { [n: number]: any } = {};
 
+
+/**
+ * Handle a HTTP response that has the "402 Payment Required" status.
+ * In this callback we don't have access to the body, and must communicate via
+ * shared state with the content script that will later be run later
+ * in this tab.
+ */
 function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: 
string, tabId: number): any {
   const headers: { [s: string]: string } = {};
   for (let kv of headerList) {
@@ -330,44 +337,26 @@ function handleHttpPayment(headerList: 
chrome.webRequest.HttpHeader[], url: stri
     contract_url: headers["x-taler-contract-url"],
     contract_query: headers["x-taler-contract-query"],
     offer_url: headers["x-taler-offer-url"],
-    pay_url: headers["x-taler-pay-url"],
   }
 
-  let n: number = 0;
-
-  for (let key of Object.keys(fields)) {
-    if ((fields as any)[key]) {
-      n++;
-    }
-  }
+  let talerHeaderFound = Object.keys(fields).filter((x: any) => (fields as 
any)[x]).length != 0;
 
-  if (n == 0) {
+  if (!talerHeaderFound) {
     // looks like it's not a taler request, it might be
     // for a different payment system (or the shop is buggy)
     console.log("ignoring non-taler 402 response");
-  }
-
-  let contract_query = undefined;
-  // parse " type [ ':' value ] " format
-  if (fields.contract_query) {
-    let res = /[-a-zA-Z0-9_.,]+(:.*)?/.exec(fields.contract_query);
-    if (res) {
-      contract_query = {type: res[0], value: res[1]};
-      if (contract_query.type == "fulfillment_url" && !contract_query.value) {
-        contract_query.value = url;
-      }
-    }
+    return;
   }
 
   let payDetail = {
-    contract_query,
     contract_url: fields.contract_url,
     offer_url: fields.offer_url,
-    pay_url: fields.pay_url,
   };
 
   console.log("got pay detail", payDetail)
 
+  // This cookie will be read by the injected content script
+  // in the tab that displays the page.
   paymentRequestCookies[tabId] = {
     type: "pay",
     payDetail,
@@ -375,6 +364,7 @@ function handleHttpPayment(headerList: 
chrome.webRequest.HttpHeader[], url: stri
 }
 
 
+
 function handleBankRequest(wallet: Wallet, headerList: 
chrome.webRequest.HttpHeader[],
   url: string, tabId: number): any {
   const headers: { [s: string]: string } = {};
diff --git a/web-common b/web-common
index 4831e66..caf5a98 160000
--- a/web-common
+++ b/web-common
@@ -1 +1 @@
-Subproject commit 4831e664d69759da288625911c053d145aa1b68c
+Subproject commit caf5a98114402d057ba08b14279eb8e46481a02c

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



reply via email to

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