gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: -fix botched refactor


From: gnunet
Subject: [taler-wallet-core] branch master updated: -fix botched refactor
Date: Tue, 27 Feb 2024 15:39:54 +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 130a90825 -fix botched refactor
130a90825 is described below

commit 130a90825609bd2a754d65041aab55d254eea8e9
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue Feb 27 15:39:50 2024 +0100

    -fix botched refactor
---
 packages/taler-wallet-core/src/recoup.ts | 72 +++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)

diff --git a/packages/taler-wallet-core/src/recoup.ts 
b/packages/taler-wallet-core/src/recoup.ts
index 3105b3709..3ef494c3a 100644
--- a/packages/taler-wallet-core/src/recoup.ts
+++ b/packages/taler-wallet-core/src/recoup.ts
@@ -39,6 +39,7 @@ import {
   codecForReserveStatus,
   encodeCrock,
   getRandomBytes,
+  j2s,
 } from "@gnu-taler/taler-util";
 import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http";
 import {
@@ -55,11 +56,11 @@ import {
   RecoupOperationStatus,
   RefreshCoinSource,
   WalletDbReadWriteTransaction,
+  WithdrawCoinSource,
   WithdrawalGroupStatus,
   WithdrawalRecordType,
   timestampPreciseToDb,
 } from "./db.js";
-import { recoupWithdrawCoin } from "./recoupWithdrawCoin.js";
 import { createRefreshGroup } from "./refresh.js";
 import { constructTransactionIdentifier } from "./transactions.js";
 import { getDenomInfo, type InternalWalletState } from "./wallet.js";
@@ -224,6 +225,75 @@ async function recoupRefreshCoin(
   );
 }
 
+export async function recoupWithdrawCoin(
+  ws: InternalWalletState,
+  recoupGroupId: string,
+  coinIdx: number,
+  coin: CoinRecord,
+  cs: WithdrawCoinSource,
+): Promise<void> {
+  const reservePub = cs.reservePub;
+  const denomInfo = await ws.db.runReadOnlyTx(["denominations"], async (tx) => 
{
+    const denomInfo = await getDenomInfo(
+      ws,
+      tx,
+      coin.exchangeBaseUrl,
+      coin.denomPubHash,
+    );
+    return denomInfo;
+  });
+  if (!denomInfo) {
+    // FIXME:  We should at least emit some pending operation / warning for 
this?
+    return;
+  }
+
+  const recoupRequest = await ws.cryptoApi.createRecoupRequest({
+    blindingKey: coin.blindingKey,
+    coinPriv: coin.coinPriv,
+    coinPub: coin.coinPub,
+    denomPub: denomInfo.denomPub,
+    denomPubHash: coin.denomPubHash,
+    denomSig: coin.denomSig,
+  });
+  const reqUrl = new URL(`/coins/${coin.coinPub}/recoup`, 
coin.exchangeBaseUrl);
+  logger.trace(`requesting recoup via ${reqUrl.href}`);
+  const resp = await ws.http.fetch(reqUrl.href, {
+    method: "POST",
+    body: recoupRequest,
+  });
+  const recoupConfirmation = await readSuccessResponseJsonOrThrow(
+    resp,
+    codecForRecoupConfirmation(),
+  );
+
+  logger.trace(`got recoup confirmation ${j2s(recoupConfirmation)}`);
+
+  if (recoupConfirmation.reserve_pub !== reservePub) {
+    throw Error(`Coin's reserve doesn't match reserve on recoup`);
+  }
+
+  // FIXME: verify that our expectations about the amount match
+  await ws.db.runReadWriteTx(
+    ["coins", "denominations", "recoupGroups", "refreshGroups"],
+    async (tx) => {
+      const recoupGroup = await tx.recoupGroups.get(recoupGroupId);
+      if (!recoupGroup) {
+        return;
+      }
+      if (recoupGroup.recoupFinishedPerCoin[coinIdx]) {
+        return;
+      }
+      const updatedCoin = await tx.coins.get(coin.coinPub);
+      if (!updatedCoin) {
+        return;
+      }
+      updatedCoin.status = CoinStatus.Dormant;
+      await tx.coins.put(updatedCoin);
+      await putGroupAsFinished(ws, tx, recoupGroup, coinIdx);
+    },
+  );
+}
+
 export async function processRecoupGroup(
   ws: InternalWalletState,
   recoupGroupId: string,

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