gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: implement refusing proposals


From: gnunet
Subject: [taler-wallet-core] branch master updated: implement refusing proposals
Date: Fri, 20 Dec 2019 01:25:25 +0100

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 378d8dee implement refusing proposals
378d8dee is described below

commit 378d8dee5825c67f9387542661ea6b34c30adbea
Author: Florian Dold <address@hidden>
AuthorDate: Fri Dec 20 01:25:22 2019 +0100

    implement refusing proposals
---
 src/android/index.ts             |  9 ++++++++-
 src/headless/integrationtest.ts  |  3 +--
 src/headless/taler-wallet-cli.ts |  4 ++--
 src/operations/history.ts        |  2 +-
 src/operations/pay.ts            | 23 ++++++++++++++++++++++-
 src/types/dbTypes.ts             |  2 +-
 src/wallet.ts                    | 11 ++++++++---
 src/webex/wxBackend.ts           |  2 +-
 8 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/src/android/index.ts b/src/android/index.ts
index a6229993..20d83d71 100644
--- a/src/android/index.ts
+++ b/src/android/index.ts
@@ -154,6 +154,13 @@ class AndroidWalletMessageHandler {
         this.wp.resolve(w);
         return {};
       }
+      case "abortProposal": {
+        const wallet = await this.wp.promise;
+        if (typeof args.proposalId !== "string") {
+          throw Error("propsalId must be a string");
+        }
+        return await wallet.refuseProposal(args.proposalId);
+      }
       case "getBalances": {
         const wallet = await this.wp.promise;
         return await wallet.getBalances();
@@ -182,7 +189,7 @@ class AndroidWalletMessageHandler {
       }
       case "preparePay": {
         const wallet = await this.wp.promise;
-        return await wallet.preparePay(args.url);
+        return await wallet.preparePayForUri(args.url);
         break;
       }
       case "confirmPay": {
diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts
index 494f7c02..05aa760b 100644
--- a/src/headless/integrationtest.ts
+++ b/src/headless/integrationtest.ts
@@ -40,7 +40,6 @@ export async function runIntegrationTest(args: {
 
   const myWallet = await getDefaultNodeWallet({ httpLib: myHttpLib });
 
-
   myWallet.runRetryLoop().catch((e) => {
     console.error("exception during retry loop:", e);
   });
@@ -75,7 +74,7 @@ export async function runIntegrationTest(args: {
     throw Error("no taler://pay/ URI in payment response");
   }
 
-  const preparePayResult = await myWallet.preparePay(talerPayUri);
+  const preparePayResult = await myWallet.preparePayForUri(talerPayUri);
 
   console.log("prepare pay result", preparePayResult);
 
diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts
index 12f729be..491f6f55 100644
--- a/src/headless/taler-wallet-cli.ts
+++ b/src/headless/taler-wallet-cli.ts
@@ -43,7 +43,7 @@ async function doPay(
   payUrl: string,
   options: { alwaysYes: boolean } = { alwaysYes: true },
 ) {
-  const result = await wallet.preparePay(payUrl);
+  const result = await wallet.preparePayForUri(payUrl);
   if (result.status === "error") {
     console.error("Could not pay:", result.error);
     process.exit(1);
@@ -317,7 +317,7 @@ advancedCli
   .requiredArgument("url", clk.STRING)
   .action(async args => {
     await withWallet(args, async wallet => {
-      const res = await wallet.preparePay(args.payPrepare.url);
+      const res = await wallet.preparePayForUri(args.payPrepare.url);
       switch (res.status) {
         case "error":
           console.log("error:", res.error);
diff --git a/src/operations/history.ts b/src/operations/history.ts
index f02894b6..00727918 100644
--- a/src/operations/history.ts
+++ b/src/operations/history.ts
@@ -91,7 +91,7 @@ async function collectProposalHistory(
       case ProposalStatus.PROPOSED:
         // no history event needed
         break;
-      case ProposalStatus.REJECTED:
+      case ProposalStatus.REFUSED:
         {
           const shortInfo = getOrderShortInfo(proposal);
           if (!shortInfo) {
diff --git a/src/operations/pay.ts b/src/operations/pay.ts
index db2a2431..c7920020 100644
--- a/src/operations/pay.ts
+++ b/src/operations/pay.ts
@@ -808,7 +808,7 @@ export async function submitPay(
  * If the payment is possible, the signature are already generated but not
  * yet send to the merchant.
  */
-export async function preparePay(
+export async function preparePayForUri(
   ws: InternalWalletState,
   talerPayUri: string,
 ): Promise<PreparePayResult> {
@@ -1018,3 +1018,24 @@ async function processPurchasePayImpl(
   logger.trace(`processing purchase pay ${proposalId}`);
   await submitPay(ws, proposalId);
 }
+
+export async function refuseProposal(ws: InternalWalletState, proposalId: 
string) {
+  const success = await ws.db.runWithWriteTransaction([Stores.proposals], 
async (tx) => {
+    const proposal = await tx.get(Stores.proposals, proposalId);  
+    if (!proposal) {
+      logger.trace(`proposal ${proposalId} not found, won't refuse proposal`);
+      return false ;
+    }
+    if (proposal.proposalStatus !== ProposalStatus.PROPOSED) {
+      return false;
+    }
+    proposal.proposalStatus = ProposalStatus.REFUSED;
+    await tx.put(Stores.proposals, proposal);
+    return true;
+  });
+  if (success) {
+    ws.notify({
+      type: NotificationType.Wildcard,
+    });
+  }
+}
\ No newline at end of file
diff --git a/src/types/dbTypes.ts b/src/types/dbTypes.ts
index 55559ab5..71fe99b6 100644
--- a/src/types/dbTypes.ts
+++ b/src/types/dbTypes.ts
@@ -689,7 +689,7 @@ export const enum ProposalStatus {
   /**
    * The user has rejected the proposal.
    */
-  REJECTED = "rejected",
+  REFUSED = "refused",
   /**
    * Downloaded proposal was detected as a re-purchase.
    */
diff --git a/src/wallet.ts b/src/wallet.ts
index b08122b6..015a44cc 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -36,7 +36,8 @@ import {
 
 import {
   abortFailedPayment,
-  preparePay,
+  preparePayForUri,
+  refuseProposal,
   confirmPay,
   processDownloadProposal,
   processPurchasePay,
@@ -355,8 +356,8 @@ export class Wallet {
    * If the payment is possible, the signature are already generated but not
    * yet send to the merchant.
    */
-  async preparePay(talerPayUri: string): Promise<PreparePayResult> {
-    return preparePay(this.ws, talerPayUri);
+  async preparePayForUri(talerPayUri: string): Promise<PreparePayResult> {
+    return preparePayForUri(this.ws, talerPayUri);
   }
 
   /**
@@ -681,6 +682,10 @@ export class Wallet {
     }
   }
 
+  async refuseProposal(proposalId: string): Promise<void> {
+    return refuseProposal(this.ws, proposalId);
+  }
+
   async getPurchaseDetails(hc: string): Promise<PurchaseDetails> {
     const purchase = await this.db.get(Stores.purchases, hc);
     if (!purchase) {
diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts
index ae12f9f9..053b8296 100644
--- a/src/webex/wxBackend.ts
+++ b/src/webex/wxBackend.ts
@@ -273,7 +273,7 @@ async function handleMessage(
       return diagnostics;
     }
     case "prepare-pay":
-      return needsWallet().preparePay(detail.talerPayUri);
+      return needsWallet().preparePayForUri(detail.talerPayUri);
     default:
       // Exhaustiveness check.
       // See https://www.typescriptlang.org/docs/handbook/advanced-types.html

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



reply via email to

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