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: fix terminology


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] branch master updated: fix terminology, better types
Date: Thu, 01 Jun 2017 18:46:09 +0200

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 29b107f9 fix terminology, better types
29b107f9 is described below

commit 29b107f93763420c5bc0cbde38c68e40e705ff38
Author: Florian Dold <address@hidden>
AuthorDate: Thu Jun 1 18:46:07 2017 +0200

    fix terminology, better types
---
 node_modules/nyc/node_modules/yargs/package.json | 138 ++++++++++++++++++-----
 src/types-test.ts                                |   6 +-
 src/types.ts                                     |  58 +++++++++-
 src/wallet.ts                                    |  59 +++++-----
 src/webex/notify.ts                              |  19 +++-
 src/webex/pages/confirm-contract.tsx             |  12 +-
 src/webex/renderHtml.tsx                         |  14 +--
 src/webex/wxApi.ts                               |   3 +-
 8 files changed, 219 insertions(+), 90 deletions(-)

diff --git a/node_modules/nyc/node_modules/yargs/package.json 
b/node_modules/nyc/node_modules/yargs/package.json
index a396ea7b..42fa3bd3 100644
--- a/node_modules/nyc/node_modules/yargs/package.json
+++ b/node_modules/nyc/node_modules/yargs/package.json
@@ -1,16 +1,57 @@
 {
-  "name": "yargs",
-  "version": "7.1.0",
-  "description": "yargs the modern, pirate-themed, successor to optimist.",
-  "main": "./index.js",
-  "files": [
-    "index.js",
-    "yargs.js",
-    "lib",
-    "locales",
-    "completion.sh.hbs",
-    "LICENSE"
+  "_args": [
+    [
+      {
+        "raw": "address@hidden",
+        "scope": null,
+        "escapedName": "yargs",
+        "name": "yargs",
+        "rawSpec": "^7.1.0",
+        "spec": ">=7.1.0 <8.0.0",
+        "type": "range"
+      },
+      "/Users/benjamincoe/oss/nyc"
+    ]
+  ],
+  "_from": "yargs@>=7.1.0 <8.0.0",
+  "_id": "address@hidden",
+  "_inCache": true,
+  "_location": "/yargs",
+  "_nodeVersion": "6.9.5",
+  "_npmOperationalInternal": {
+    "host": "packages-12-west.internal.npmjs.com",
+    "tmp": "tmp/yargs-7.1.0.tgz_1492119927787_0.18849953636527061"
+  },
+  "_npmUser": {
+    "name": "bcoe",
+    "email": "address@hidden"
+  },
+  "_npmVersion": "4.5.0",
+  "_phantomChildren": {
+    "string-width": "1.0.2",
+    "strip-ansi": "3.0.1",
+    "wrap-ansi": "2.1.0"
+  },
+  "_requested": {
+    "raw": "address@hidden",
+    "scope": null,
+    "escapedName": "yargs",
+    "name": "yargs",
+    "rawSpec": "^7.1.0",
+    "spec": ">=7.1.0 <8.0.0",
+    "type": "range"
+  },
+  "_requiredBy": [
+    "/"
   ],
+  "_resolved": "https://registry.npmjs.org/yargs/-/yargs-7.1.0.tgz";,
+  "_shasum": "6ba318eb16961727f5d284f8ea003e8d6154d0c8",
+  "_shrinkwrap": null,
+  "_spec": "address@hidden",
+  "_where": "/Users/benjamincoe/oss/nyc",
+  "bugs": {
+    "url": "https://github.com/yargs/yargs/issues";
+  },
   "dependencies": {
     "camelcase": "^3.0.0",
     "cliui": "^3.2.0",
@@ -26,6 +67,7 @@
     "y18n": "^3.2.1",
     "yargs-parser": "^5.0.0"
   },
+  "description": "yargs the modern, pirate-themed, successor to optimist.",
   "devDependencies": {
     "chai": "^3.4.1",
     "chalk": "^1.1.3",
@@ -41,22 +83,31 @@
     "standard-version": "^3.0.0",
     "which": "^1.2.9"
   },
-  "scripts": {
-    "pretest": "standard",
-    "test": "nyc --cache mocha --require ./test/before.js --timeout=8000 
--check-leaks",
-    "coverage": "nyc report --reporter=text-lcov | coveralls",
-    "release": "standard-version"
+  "directories": {},
+  "dist": {
+    "shasum": "6ba318eb16961727f5d284f8ea003e8d6154d0c8",
+    "tarball": "https://registry.npmjs.org/yargs/-/yargs-7.1.0.tgz";
   },
-  "repository": {
-    "type": "git",
-    "url": "http://github.com/yargs/yargs.git";
+  "engine": {
+    "node": ">=0.10"
   },
-  "homepage": "http://yargs.js.org/";,
-  "standard": {
+  "files": [
+    "index.js",
+    "yargs.js",
+    "lib",
+    "locales",
+    "completion.sh.hbs",
+    "LICENSE"
+  ],
+  "gitHead": "e7359d632595c3a5fcfd691994859b66e8943c85",
+  "greenkeeper": {
     "ignore": [
-      "**/example/**"
+      "string-width",
+      "read-pkg-up",
+      "camelcase"
     ]
   },
+  "homepage": "http://yargs.js.org/";,
   "keywords": [
     "argument",
     "args",
@@ -67,14 +118,43 @@
     "command"
   ],
   "license": "MIT",
-  "engine": {
-    "node": ">=0.10"
+  "main": "./index.js",
+  "maintainers": [
+    {
+      "name": "bcoe",
+      "email": "address@hidden"
+    },
+    {
+      "name": "chevex",
+      "email": "address@hidden"
+    },
+    {
+      "name": "nexdrew",
+      "email": "address@hidden"
+    },
+    {
+      "name": "nylen",
+      "email": "address@hidden"
+    }
+  ],
+  "name": "yargs",
+  "optionalDependencies": {},
+  "readme": "  yargs\n========\n\nYargs be a node.js library fer hearties 
tryin' ter parse optstrings.\n\nWith yargs, ye be havin' a map that leads 
straight to yer treasure! Treasure of course, being a simple option 
hash.\n\n[![Build Status][travis-image]][travis-url]\n[![Coverage 
Status][coveralls-image]][coveralls-url]\n[![NPM 
version][npm-image]][npm-url]\n[![Windows 
Tests][windows-image]][windows-url]\n[![js-standard-style][standard-image]][standard-url]\n[![Conventional
 Commits][con [...]
+  "readmeFilename": "README.md",
+  "repository": {
+    "type": "git",
+    "url": "git+ssh://address@hidden/yargs/yargs.git"
   },
-  "greenkeeper": {
+  "scripts": {
+    "coverage": "nyc report --reporter=text-lcov | coveralls",
+    "pretest": "standard",
+    "release": "standard-version",
+    "test": "nyc --cache mocha --require ./test/before.js --timeout=8000 
--check-leaks"
+  },
+  "standard": {
     "ignore": [
-      "string-width",
-      "read-pkg-up",
-      "camelcase"
+      "**/example/**"
     ]
-  }
+  },
+  "version": "7.1.0"
 }
diff --git a/src/types-test.ts b/src/types-test.ts
index a84bdaec..3657d6d2 100644
--- a/src/types-test.ts
+++ b/src/types-test.ts
@@ -54,7 +54,7 @@ test("amount subtraction (saturation)", (t) => {
 });
 
 
-test("contract validation", (t) => {
+test("contract terms validation", (t) => {
   const c = {
     H_wire: "123",
     amount: amt(1, 2, "EUR"),
@@ -73,13 +73,13 @@ test("contract validation", (t) => {
     wire_method: "test",
   };
 
-  types.Contract.checked(c);
+  types.ContractTerms.checked(c);
 
   const c1 = JSON.parse(JSON.stringify(c));
   c1.exchanges = [];
 
   try {
-    types.Contract.checked(c1);
+    types.ContractTerms.checked(c1);
   } catch (e) {
     t.pass();
     return;
diff --git a/src/types.ts b/src/types.ts
index 82777f96..0f817ccb 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -903,10 +903,10 @@ export interface WalletBalanceEntry {
  * Contract terms from a merchant.
  */
 @Checkable.Class({validate: true})
-export class Contract {
+export class ContractTerms {
   validate() {
     if (this.exchanges.length === 0) {
-      throw Error("no exchanges in contract");
+      throw Error("no exchanges in contract terms");
     }
   }
 
@@ -1042,7 +1042,7 @@ export class Contract {
    * Verify that a value matches the schema of this class and convert it into a
    * member.
    */
-  static checked: (obj: any) => Contract;
+  static checked: (obj: any) => ContractTerms;
 }
 
 
@@ -1054,8 +1054,8 @@ export class ProposalRecord {
   /**
    * The contract that was offered by the merchant.
    */
-  @Checkable.Value(Contract)
-  contractTerms: Contract;
+  @Checkable.Value(ContractTerms)
+  contractTerms: ContractTerms;
 
   /**
    * Signature by the merchant over the contract details.
@@ -1398,3 +1398,51 @@ export interface HistoryRecord {
 }
 
 
+/**
+ * Payment body sent to the merchant's /pay.
+ */
+export interface PayReq {
+  /**
+   * Coins with signature.
+   */
+  coins: CoinPaySig[];
+
+  /**
+   * The merchant public key, used to uniquely
+   * identify the merchant instance.
+   */
+  merchant_pub: string;
+
+  /**
+   * Order ID that's being payed for.
+   */
+  order_id: string;
+
+  /**
+   * Exchange that the coins are from.
+   */
+  exchange: string;
+}
+
+
+/**
+ * Response to a query payment request.  Tagged union over the 'found' field.
+ */
+export type QueryPaymentResult = QueryPaymentNotFound | QueryPaymentFound;
+
+/**
+ * Query payment response when the payment was found.
+ */
+export interface QueryPaymentNotFound {
+  found: false;
+}
+
+/**
+ * Query payment response when the payment wasn't found.
+ */
+export interface QueryPaymentFound {
+  found: true;
+  contractTermsHash: string;
+  contractTerms: ContractTerms;
+  payReq: PayReq;
+}
diff --git a/src/wallet.ts b/src/wallet.ts
index 8dc9a75a..0bbab15e 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -47,11 +47,10 @@ import {
   Amounts,
   Auditor,
   CheckPayResult,
-  CoinPaySig,
   CoinRecord,
   CoinStatus,
   ConfirmPayResult,
-  Contract,
+  ContractTerms,
   CreateReserveResponse,
   CurrencyRecord,
   Denomination,
@@ -63,10 +62,12 @@ import {
   HistoryLevel,
   HistoryRecord,
   Notifier,
-  ProposalRecord,
   PayCoinInfo,
+  PayReq,
   PaybackConfirmation,
   PreCoinRecord,
+  ProposalRecord,
+  QueryPaymentResult,
   RefreshSessionRecord,
   ReserveCreationInfo,
   ReserveRecord,
@@ -272,16 +273,9 @@ export class ConfirmReserveRequest {
 }
 
 
-interface PayReq {
-  coins: CoinPaySig[];
-  merchant_pub: string;
-  order_id: string;
-  exchange: string;
-}
-
 interface TransactionRecord {
-  contractHash: string;
-  contract: Contract;
+  contractTermsHash: string;
+  contractTerms: ContractTerms;
   payReq: PayReq;
   merchantSig: string;
 
@@ -518,11 +512,11 @@ export namespace Stores {
 
   class TransactionsStore extends Store<TransactionRecord> {
     constructor() {
-      super("transactions", {keyPath: "contractHash"});
+      super("transactions", {keyPath: "contractTermsHash"});
     }
 
-    fulfillmentUrlIndex = new Index<string, TransactionRecord>(this, 
"fulfillment_url", "contract.fulfillment_url");
-    orderIdIndex = new Index<string, TransactionRecord>(this, "order_id", 
"contract.order_id");
+    fulfillmentUrlIndex = new Index<string, TransactionRecord>(this, 
"fulfillment_url", "contractTerms.fulfillment_url");
+    orderIdIndex = new Index<string, TransactionRecord>(this, "order_id", 
"contractTerms.order_id");
   }
 
   class DenominationsStore extends Store<DenominationRecord> {
@@ -832,7 +826,7 @@ export class Wallet {
 
   /**
    * Record all information that is necessary to
-   * pay for a contract in the wallet's database.
+   * pay for a proposal in the wallet's database.
    */
   private async recordConfirmPay(proposal: ProposalRecord,
                                  payCoinInfo: PayCoinInfo,
@@ -844,8 +838,8 @@ export class Wallet {
       order_id: proposal.contractTerms.order_id,
     };
     const t: TransactionRecord = {
-      contract: proposal.contractTerms,
-      contractHash: proposal.contractTermsHash,
+      contractTerms: proposal.contractTerms,
+      contractTermsHash: proposal.contractTermsHash,
       finished: false,
       merchantSig: proposal.merchantSig,
       payReq,
@@ -854,7 +848,7 @@ export class Wallet {
     const historyEntry: HistoryRecord = {
       detail: {
         amount: proposal.contractTerms.amount,
-        contractHash: proposal.contractTermsHash,
+        contractTermsHash: proposal.contractTermsHash,
         fulfillmentUrl: proposal.contractTerms.fulfillment_url,
         merchantName: proposal.contractTerms.merchant.name,
       },
@@ -980,7 +974,7 @@ export class Wallet {
    * Retrieve information required to pay for a contract, where the
    * contract is identified via the fulfillment url.
    */
-  async queryPayment(url: string): Promise<any> {
+  async queryPayment(url: string): Promise<QueryPaymentResult> {
     console.log("query for payment", url);
 
     const t = await 
this.q().getIndexed(Stores.transactions.fulfillmentUrlIndex, url);
@@ -988,17 +982,16 @@ export class Wallet {
     if (!t) {
       console.log("query for payment failed");
       return {
-        success: false,
+        found: false,
       };
     }
     console.log("query for payment succeeded:", t);
-    const resp = {
-      H_contract: t.contractHash,
-      contract: t.contract,
+    return {
+      contractTermsHash: t.contractTermsHash,
+      contractTerms: t.contractTerms,
       payReq: t.payReq,
-      success: true,
+      found: true,
     };
-    return resp;
   }
 
 
@@ -1804,9 +1797,9 @@ export class Wallet {
       if (t.finished) {
         return balance;
       }
-      const entry = ensureEntry(balance, t.contract.amount.currency);
+      const entry = ensureEntry(balance, t.contractTerms.amount.currency);
       entry.pendingPayment = Amounts.add(entry.pendingPayment,
-                                         t.contract.amount).amount;
+                                         t.contractTerms.amount).amount;
 
       return balance;
     }
@@ -2171,7 +2164,7 @@ export class Wallet {
                .toArray();
   }
 
-  async hashContract(contract: Contract): Promise<string> {
+  async hashContract(contract: ContractTerms): Promise<string> {
     return this.cryptoApi.hashString(canonicalJson(contract));
   }
 
@@ -2193,16 +2186,16 @@ export class Wallet {
   }
 
 
-  async paymentSucceeded(contractHash: string, merchantSig: string): 
Promise<any> {
+  async paymentSucceeded(contractTermsHash: string, merchantSig: string): 
Promise<any> {
     const doPaymentSucceeded = async() => {
       const t = await this.q().get<TransactionRecord>(Stores.transactions,
-                                                    contractHash);
+                                                    contractTermsHash);
       if (!t) {
         console.error("contract not found");
         return;
       }
-      const merchantPub = t.contract.merchant_pub;
-      const valid = this.cryptoApi.isValidPaymentSignature(merchantSig, 
contractHash, merchantPub);
+      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
diff --git a/src/webex/notify.ts b/src/webex/notify.ts
index 2f38658b..09c5ae00 100644
--- a/src/webex/notify.ts
+++ b/src/webex/notify.ts
@@ -28,6 +28,8 @@ import URI = require("urijs");
 
 import wxApi = require("./wxApi");
 
+import { QueryPaymentResult } from "../types";
+
 declare var cloneInto: any;
 
 let logVerbose: boolean = false;
@@ -96,7 +98,12 @@ function setStyles(installed: boolean) {
 }
 
 
-function handlePaymentResponse(walletResp: any) {
+function handlePaymentResponse(maybeFoundResponse: QueryPaymentResult) {
+  if (!maybeFoundResponse.found) {
+    console.log("pay-failed", {hint: "payment not found in the wallet"});
+    return;
+  }
+  const walletResp = maybeFoundResponse;
   /**
    * Handle a failed payment.
    *
@@ -115,7 +122,7 @@ function handlePaymentResponse(walletResp: any) {
     }
     timeoutHandle = window.setTimeout(onTimeout, 200);
 
-    await wxApi.paymentFailed(walletResp.H_contract);
+    await wxApi.paymentFailed(walletResp.contractTermsHash);
     if (timeoutHandle !== null) {
       clearTimeout(timeoutHandle);
       timeoutHandle = null;
@@ -131,7 +138,7 @@ function handlePaymentResponse(walletResp: any) {
   let timeoutHandle: number|null = null;
   function sendPay() {
     r = new XMLHttpRequest();
-    r.open("post", walletResp.contract.pay_url);
+    r.open("post", walletResp.contractTerms.pay_url);
     r.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
     r.send(JSON.stringify(walletResp.payReq));
     r.onload = async () => {
@@ -142,8 +149,8 @@ function handlePaymentResponse(walletResp: any) {
         case 200:
           const merchantResp = JSON.parse(r.responseText);
           logVerbose && console.log("got success from pay_url");
-          await wxApi.paymentSucceeded(walletResp.H_contract, 
merchantResp.sig);
-          const nextUrl = walletResp.contract.fulfillment_url;
+          await wxApi.paymentSucceeded(walletResp.contractTermsHash, 
merchantResp.sig);
+          const nextUrl = walletResp.contractTerms.fulfillment_url;
           logVerbose && console.log("taler-payment-succeeded done, going to", 
nextUrl);
           window.location.href = nextUrl;
           window.location.reload(true);
@@ -318,7 +325,7 @@ function talerPay(msg: any): Promise<any> {
     const url = new URI(document.location.href).fragment("").href();
     const res = await wxApi.queryPayment(url);
     logVerbose && console.log("taler-pay: got response", res);
-    if (res && res.payReq) {
+    if (res && res.found && res.payReq) {
       resolve(res);
       return;
     }
diff --git a/src/webex/pages/confirm-contract.tsx 
b/src/webex/pages/confirm-contract.tsx
index c5513f7c..e80aed19 100644
--- a/src/webex/pages/confirm-contract.tsx
+++ b/src/webex/pages/confirm-contract.tsx
@@ -25,12 +25,12 @@
  */
 import * as i18n from "../../i18n";
 import {
-  Contract,
+  ContractTerms,
   ExchangeRecord,
   ProposalRecord,
 } from "../../types";
 
-import { renderContract } from "../renderHtml";
+import { renderContractTerms } from "../renderHtml";
 import * as wxApi from "../wxApi";
 
 import * as React from "react";
@@ -43,7 +43,7 @@ interface DetailState {
 }
 
 interface DetailProps {
-  contract: Contract;
+  contractTerms: ContractTerms;
   collapsed: boolean;
   exchanges: null|ExchangeRecord[];
 }
@@ -82,7 +82,7 @@ class Details extends React.Component<DetailProps, 
DetailState> {
           <div>
             {i18n.str`Accepted exchanges:`}
             <ul>
-              {this.props.contract.exchanges.map(
+              {this.props.contractTerms.exchanges.map(
                 (e) => <li>{`${e.url}: ${e.master_pub}`}</li>)}
             </ul>
             {i18n.str`Exchanges in the wallet:`}
@@ -185,7 +185,7 @@ class ContractPrompt extends 
React.Component<ContractPromptProps, ContractPrompt
     return (
       <div>
         <div>
-          {renderContract(c)}
+          {renderContractTerms(c)}
         </div>
         <button onClick={() => this.doPayment()}
                 disabled={this.state.payDisabled}
@@ -195,7 +195,7 @@ class ContractPrompt extends 
React.Component<ContractPromptProps, ContractPrompt
         <div>
           {(this.state.error ? <p className="errorbox">{this.state.error}</p> 
: <p />)}
         </div>
-        <Details exchanges={this.state.exchanges} contract={c} 
collapsed={!this.state.error}/>
+        <Details exchanges={this.state.exchanges} contractTerms={c} 
collapsed={!this.state.error}/>
       </div>
     );
   }
diff --git a/src/webex/renderHtml.tsx b/src/webex/renderHtml.tsx
index 70cd61d6..4dd7bade 100644
--- a/src/webex/renderHtml.tsx
+++ b/src/webex/renderHtml.tsx
@@ -27,7 +27,7 @@
 import { amountToPretty } from "../helpers";
 import * as i18n from "../i18n";
 import {
-  Contract,
+  ContractTerms,
 } from "../types";
 
 import * as React from "react";
@@ -35,14 +35,14 @@ import * as React from "react";
 /**
  * Render contract terms for the end user to view.
  */
-export function renderContract(contract: Contract): JSX.Element {
+export function renderContractTerms(contractTerms: ContractTerms): JSX.Element 
{
   let merchantName;
-  if (contract.merchant && contract.merchant.name) {
-    merchantName = <strong>{contract.merchant.name}</strong>;
+  if (contractTerms.merchant && contractTerms.merchant.name) {
+    merchantName = <strong>{contractTerms.merchant.name}</strong>;
   } else {
-    merchantName = <strong>(pub: {contract.merchant_pub})</strong>;
+    merchantName = <strong>(pub: {contractTerms.merchant_pub})</strong>;
   }
-  const amount = <strong>{amountToPretty(contract.amount)}</strong>;
+  const amount = <strong>{amountToPretty(contractTerms.amount)}</strong>;
 
   return (
     <div>
@@ -53,7 +53,7 @@ export function renderContract(contract: Contract): 
JSX.Element {
       </i18n.Translate>
       <p>{i18n.str`You are about to purchase:`}</p>
       <ul>
-        {contract.products.map(
+        {contractTerms.products.map(
           (p: any, i: number) => (<li key={i}>{`${p.description}: 
${amountToPretty(p.price)}`}</li>))
         }
       </ul>
diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts
index 4babb2a7..1968b657 100644
--- a/src/webex/wxApi.ts
+++ b/src/webex/wxApi.ts
@@ -33,6 +33,7 @@ import {
   PreCoinRecord,
   ReserveCreationInfo,
   ReserveRecord,
+  QueryPaymentResult,
 } from "../types";
 
 import { MessageType, MessageMap } from "./messages";
@@ -213,7 +214,7 @@ export function confirmReserve(reservePub: string): 
Promise<void> {
 /**
  * Query for a payment by fulfillment URL.
  */
-export function queryPayment(url: string): Promise<any> {
+export function queryPayment(url: string): Promise<QueryPaymentResult> {
   return callBackend("query-payment", { url });
 }
 

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



reply via email to

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