gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 02/04: backward compatible change to acceptReward wi


From: gnunet
Subject: [taler-wallet-core] 02/04: backward compatible change to acceptReward with txId
Date: Sun, 04 Feb 2024 21:02:51 +0100

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

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

commit 1b0b40fee2b15dd8847bf91c01630492ced93750
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Sun Feb 4 17:01:46 2024 -0300

    backward compatible change to acceptReward with txId
---
 .../taler-wallet-core/src/operations/reward.ts     | 40 ++++++++++++++++------
 .../src/operations/transactions.ts                 | 10 +++---
 packages/taler-wallet-core/src/wallet.ts           |  9 ++---
 3 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/packages/taler-wallet-core/src/operations/reward.ts 
b/packages/taler-wallet-core/src/operations/reward.ts
index 62ac81d7f..369c1f40d 100644
--- a/packages/taler-wallet-core/src/operations/reward.ts
+++ b/packages/taler-wallet-core/src/operations/reward.ts
@@ -37,6 +37,7 @@ import {
   TalerPreciseTimestamp,
   TipPlanchetDetail,
   TransactionAction,
+  TransactionIdStr,
   TransactionMajorState,
   TransactionMinorState,
   TransactionState,
@@ -81,6 +82,7 @@ import { selectWithdrawalDenominations } from 
"../util/coinSelection.js";
 import {
   constructTransactionIdentifier,
   notifyTransition,
+  parseTransactionIdentifier,
   stopLongpolling,
 } from "./transactions.js";
 import { PendingTaskType } from "../pending-types.js";
@@ -643,18 +645,39 @@ export async function processTip(
   return TaskRunResult.finished();
 }
 
+export async function acceptTipBackwardCompat(
+  ws: InternalWalletState,
+  walletTipId: string | undefined,
+  transactionIdParam: TransactionIdStr | undefined,
+): Promise<AcceptTipResponse> {
+  if (transactionIdParam) {
+    return acceptTip(ws, transactionIdParam)
+  }
+  if (walletTipId) {
+    /**
+     * old clients use still use tipId
+     */
+    const transactionId = constructTransactionIdentifier({
+      tag: TransactionType.Reward,
+      walletRewardId: walletTipId,
+    });
+    return acceptTip(ws, transactionId)
+  }
+  throw Error("Unable to accept tip: neither tipId (deprecated) nor 
transactionId was specified")
+}
+
 export async function acceptTip(
   ws: InternalWalletState,
-  walletTipId: string,
+  transactionId: TransactionIdStr,
 ): Promise<AcceptTipResponse> {
-  const transactionId = constructTransactionIdentifier({
-    tag: TransactionType.Reward,
-    walletRewardId: walletTipId,
-  });
+  const pTxId = parseTransactionIdentifier(transactionId)
+  if (!pTxId) throw Error(`Unable to accept tip: invalid tx tag 
"${transactionId}"`)
+  const rewardId = pTxId.tag === TransactionType.Reward ? pTxId.walletRewardId 
: undefined;
+  if (!rewardId) throw Error(`Unable to accept tip: txId is not a reward tag 
"${pTxId.tag}"`)
   const dbRes = await ws.db
     .mktx((x) => [x.rewards])
     .runReadWrite(async (tx) => {
-      const tipRecord = await tx.rewards.get(walletTipId);
+      const tipRecord = await tx.rewards.get(rewardId);
       if (!tipRecord) {
         logger.error("tip not found");
         return;
@@ -682,10 +705,7 @@ export async function acceptTip(
   const tipRecord = dbRes.tipRecord;
 
   return {
-    transactionId: constructTransactionIdentifier({
-      tag: TransactionType.Reward,
-      walletRewardId: walletTipId,
-    }),
+    transactionId,
     next_url: tipRecord.next_url,
   };
 }
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts 
b/packages/taler-wallet-core/src/operations/transactions.ts
index 8fd7afae6..f64d3d21d 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -539,7 +539,7 @@ function buildTransactionForPeerPullCredit(
     const silentWithdrawalErrorForInvoice =
       wsrOrt?.lastError &&
       wsrOrt.lastError.code ===
-        TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE &&
+      TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE &&
       Object.values(wsrOrt.lastError.errorsPerCoin ?? {}).every((e) => {
         return (
           e.code === TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR &&
@@ -569,10 +569,10 @@ function buildTransactionForPeerPullCredit(
       kycUrl: pullCredit.kycUrl,
       ...(wsrOrt?.lastError
         ? {
-            error: silentWithdrawalErrorForInvoice
-              ? undefined
-              : wsrOrt.lastError,
-          }
+          error: silentWithdrawalErrorForInvoice
+            ? undefined
+            : wsrOrt.lastError,
+        }
         : {}),
     };
   }
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 005fac3c4..6440a9912 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -251,6 +251,7 @@ import {
 } from "./operations/refresh.js";
 import {
   acceptTip,
+  acceptTipBackwardCompat,
   computeRewardTransactionStatus,
   prepareReward,
   processTip,
@@ -734,9 +735,9 @@ async function dumpCoins(ws: InternalWalletState): 
Promise<CoinDumpJson> {
           ageCommitmentProof: c.ageCommitmentProof,
           spend_allocation: c.spendAllocation
             ? {
-                amount: c.spendAllocation.amount,
-                id: c.spendAllocation.id,
-              }
+              amount: c.spendAllocation.amount,
+              id: c.spendAllocation.id,
+            }
             : undefined,
         });
       }
@@ -1194,7 +1195,7 @@ async function dispatchRequestInternal<Op extends 
WalletApiOperation>(
     }
     case WalletApiOperation.AcceptReward: {
       const req = codecForAcceptTipRequest().decode(payload);
-      return await acceptTip(ws, req.walletRewardId);
+      return await acceptTipBackwardCompat(ws, req.walletRewardId, 
req.transactionId);
     }
     case WalletApiOperation.AddBackupProvider: {
       const req = codecForAddBackupProviderRequest().decode(payload);

-- 
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]