gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 01/02: implement force-retrying transactions


From: gnunet
Subject: [taler-wallet-core] 01/02: implement force-retrying transactions
Date: Mon, 14 Jun 2021 19:38:21 +0200

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

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

commit ef636c022bb6f8017ef237a5e6468f5c449665ad
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon Jun 14 19:37:35 2021 +0200

    implement force-retrying transactions
---
 packages/taler-util/src/walletTypes.ts             |  9 +++++
 .../src/crypto/primitives/nacl-fast.ts             | 12 ++++--
 .../src/operations/transactions.ts                 | 45 ++++++++++++++++++++++
 packages/taler-wallet-core/src/wallet.ts           |  8 +++-
 4 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/packages/taler-util/src/walletTypes.ts 
b/packages/taler-util/src/walletTypes.ts
index 10dbf75e..6a0c5713 100644
--- a/packages/taler-util/src/walletTypes.ts
+++ b/packages/taler-util/src/walletTypes.ts
@@ -949,7 +949,16 @@ export interface DeleteTransactionRequest {
   transactionId: string;
 }
 
+export interface RetryTransactionRequest {
+  transactionId: string;
+}
+
 export const codecForDeleteTransactionRequest = (): 
Codec<DeleteTransactionRequest> =>
   buildCodecForObject<DeleteTransactionRequest>()
     .property("transactionId", codecForString())
     .build("DeleteTransactionRequest");
+
+export const codecForRetryTransactionRequest = (): 
Codec<RetryTransactionRequest> =>
+  buildCodecForObject<RetryTransactionRequest>()
+    .property("transactionId", codecForString())
+    .build("RetryTransactionRequest");
diff --git a/packages/taler-wallet-core/src/crypto/primitives/nacl-fast.ts 
b/packages/taler-wallet-core/src/crypto/primitives/nacl-fast.ts
index 711c83ec..eab4a2e5 100644
--- a/packages/taler-wallet-core/src/crypto/primitives/nacl-fast.ts
+++ b/packages/taler-wallet-core/src/crypto/primitives/nacl-fast.ts
@@ -5,11 +5,15 @@
 // Implementation derived from TweetNaCl version 20140427.
 // See for details: http://tweetnacl.cr.yp.to/
 
-import { createRequire } from "module";
+import * as mod from "module";
 
-// We need this require function to synchronously
-// import the "crypto" module in the CSPRNG initialization.
-const require = createRequire(import.meta.url);
+let require: any;
+
+if (typeof require !== "function" && mod.default && mod.default.createRequire) 
{
+  // We need this require function to synchronously
+  // import the "crypto" module in the CSPRNG initialization.
+  require = mod.default.createRequire(import.meta.url);
+}
 
 const gf = function (init: number[] = []): Float64Array {
   const r = new Float64Array(16);
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts 
b/packages/taler-wallet-core/src/operations/transactions.ts
index 3d9f1be4..1b2c8477 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -38,6 +38,11 @@ import {
 } from "@gnu-taler/taler-util";
 import { getFundingPaytoUris } from "./reserves.js";
 import { getExchangeDetails } from "./exchanges.js";
+import { processWithdrawGroup } from "./withdraw.js";
+import { processPurchasePay } from "./pay.js";
+import { processDepositGroup } from "./deposits.js";
+import { processTip } from "./tip.js";
+import { processRefreshGroup } from "./refresh.js";
 
 /**
  * Create an event ID from the type and the primary key for the event.
@@ -398,6 +403,46 @@ export enum TombstoneTag {
   DeleteRefund = "delete-refund",
 }
 
+/**
+ * Immediately retry the underlying operation
+ * of a transaction.
+ */
+export async function retryTransaction(
+  ws: InternalWalletState,
+  transactionId: string,
+): Promise<void> {
+  const [type, ...rest] = transactionId.split(":");
+
+  switch (type) {
+    case TransactionType.Deposit:
+      const depositGroupId = rest[0];
+      processDepositGroup(ws, depositGroupId, true);
+      break;
+    case TransactionType.Withdrawal: {
+      const withdrawalGroupId = rest[0];
+      await processWithdrawGroup(ws, withdrawalGroupId, true);
+      break;
+    }
+    case TransactionType.Payment: {
+      const proposalId = rest[0]
+      await processPurchasePay(ws, proposalId, true);
+      break;
+    }
+    case TransactionType.Tip: {
+      const walletTipId = rest[0];
+      await processTip(ws, walletTipId, true);
+      break;
+    }
+    case TransactionType.Refresh: {
+      const refreshGroupId = rest[0];
+      await processRefreshGroup(ws, refreshGroupId, true);
+      break;
+    }
+    default:
+      break;
+  }
+}
+
 /**
  * Permanently delete a transaction based on the transaction ID.
  */
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 900a2e77..33e431f3 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -26,6 +26,7 @@ import {
   BackupRecovery,
   codecForAny,
   codecForDeleteTransactionRequest,
+  codecForRetryTransactionRequest,
   DeleteTransactionRequest,
   durationFromSpec,
   durationMax,
@@ -103,7 +104,7 @@ import {
   withdrawTestBalance,
 } from "./operations/testing";
 import { acceptTip, prepareTip, processTip } from "./operations/tip";
-import { deleteTransaction, getTransactions } from "./operations/transactions";
+import { deleteTransaction, getTransactions, retryTransaction } from 
"./operations/transactions";
 import {
   getExchangeWithdrawalInfo,
   getWithdrawalDetailsForUri,
@@ -1194,6 +1195,11 @@ export class Wallet {
         await deleteTransaction(this.ws, req.transactionId);
         return {};
       }
+      case "retryTransaction": {
+        const req = codecForRetryTransactionRequest().decode(payload);
+        await retryTransaction(this.ws, req.transactionId);
+        return {};
+      }
     }
     throw OperationFailedError.fromCode(
       TalerErrorCode.WALLET_CORE_API_OPERATION_UNKNOWN,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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