gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: wallet-core: use getAll inste


From: gnunet
Subject: [taler-wallet-core] branch master updated: wallet-core: use getAll instead of iter to query denominations
Date: Mon, 18 Dec 2023 13:53:19 +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 a488ce70d wallet-core: use getAll instead of iter to query 
denominations
a488ce70d is described below

commit a488ce70d6dbfe08845eccaeb2375b367f7c307a
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon Dec 18 13:53:15 2023 +0100

    wallet-core: use getAll instead of iter to query denominations
---
 .../src/operations/pay-merchant.ts                 | 16 +++++++--------
 .../src/operations/pay-peer-common.ts              | 24 ++++++++++++++--------
 .../src/operations/pay-peer-push-debit.ts          | 13 +++++-------
 3 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts 
b/packages/taler-wallet-core/src/operations/pay-merchant.ts
index 2d364a866..17a879d90 100644
--- a/packages/taler-wallet-core/src/operations/pay-merchant.ts
+++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts
@@ -152,6 +152,7 @@ export async function getTotalPaymentCost(
   ws: InternalWalletState,
   pcs: PayCoinSelection,
 ): Promise<AmountJson> {
+  const currency = Amounts.currencyOf(pcs.coinContributions[0]);
   return ws.db
     .mktx((x) => [x.coins, x.denominations])
     .runReadOnly(async (tx) => {
@@ -170,11 +171,11 @@ export async function getTotalPaymentCost(
             "can't calculate payment cost, denomination for coin not found",
           );
         }
-        const allDenoms = await tx.denominations.indexes.byExchangeBaseUrl
-          .iter(coin.exchangeBaseUrl)
-          .filter((x) =>
-            Amounts.isSameCurrency(x.value, pcs.coinContributions[i]),
-          );
+        const allDenoms = (
+          await tx.denominations.indexes.byExchangeBaseUrl.getAll(
+            coin.exchangeBaseUrl,
+          )
+        ).filter((x) => x.currency === currency);
         const amountLeft = Amounts.sub(
           denom.value,
           pcs.coinContributions[i],
@@ -529,9 +530,8 @@ async function processDownloadProposal(
           fulfillmentUrl.startsWith("https://";));
       let otherPurchase: PurchaseRecord | undefined;
       if (isResourceFulfillmentUrl) {
-        otherPurchase = await tx.purchases.indexes.byFulfillmentUrl.get(
-          fulfillmentUrl,
-        );
+        otherPurchase =
+          await tx.purchases.indexes.byFulfillmentUrl.get(fulfillmentUrl);
       }
       // FIXME: Adjust this to account for refunds, don't count as repurchase
       // if original order is refunded.
diff --git a/packages/taler-wallet-core/src/operations/pay-peer-common.ts 
b/packages/taler-wallet-core/src/operations/pay-peer-common.ts
index 6d425289d..aa9e0c858 100644
--- a/packages/taler-wallet-core/src/operations/pay-peer-common.ts
+++ b/packages/taler-wallet-core/src/operations/pay-peer-common.ts
@@ -88,6 +88,7 @@ export async function getTotalPeerPaymentCost(
   ws: InternalWalletState,
   pcs: SelectedPeerCoin[],
 ): Promise<AmountJson> {
+  const currency = Amounts.currencyOf(pcs[0].contribution);
   return ws.db
     .mktx((x) => [x.coins, x.denominations])
     .runReadOnly(async (tx) => {
@@ -97,22 +98,29 @@ export async function getTotalPeerPaymentCost(
         if (!coin) {
           throw Error("can't calculate payment cost, coin not found");
         }
-        const denom = await tx.denominations.get([
+        const denomInfo = await ws.getDenomInfo(
+          ws,
+          tx,
           coin.exchangeBaseUrl,
           coin.denomPubHash,
-        ]);
-        if (!denom) {
+        );
+        if (!denomInfo) {
           throw Error(
             "can't calculate payment cost, denomination for coin not found",
           );
         }
-        const allDenoms = await tx.denominations.indexes.byExchangeBaseUrl
-          .iter(coin.exchangeBaseUrl)
-          .filter((x) => Amounts.isSameCurrency(x.value, pcs[i].contribution));
-        const amountLeft = Amounts.sub(denom.value, 
pcs[i].contribution).amount;
+        const allDenoms = (
+          await tx.denominations.indexes.byExchangeBaseUrl.getAll(
+            coin.exchangeBaseUrl,
+          )
+        ).filter((x) => x.currency === currency);
+        const amountLeft = Amounts.sub(
+          denomInfo.value,
+          pcs[i].contribution,
+        ).amount;
         const refreshCost = getTotalRefreshCost(
           allDenoms,
-          DenominationRecord.toDenomInfo(denom),
+          denomInfo,
           amountLeft,
           ws.config.testing.denomselAllowLate,
         );
diff --git a/packages/taler-wallet-core/src/operations/pay-peer-push-debit.ts 
b/packages/taler-wallet-core/src/operations/pay-peer-push-debit.ts
index 3eed52b91..da779a07d 100644
--- a/packages/taler-wallet-core/src/operations/pay-peer-push-debit.ts
+++ b/packages/taler-wallet-core/src/operations/pay-peer-push-debit.ts
@@ -31,18 +31,14 @@ import {
   TalerPreciseTimestamp,
   TalerProtocolTimestamp,
   TalerProtocolViolationError,
-  TalerUriAction,
   TransactionAction,
   TransactionMajorState,
   TransactionMinorState,
   TransactionState,
   TransactionType,
-  decodeCrock,
   encodeCrock,
   getRandomBytes,
-  hash,
   j2s,
-  stringifyTalerUri,
 } from "@gnu-taler/taler-util";
 import {
   HttpResponse,
@@ -89,6 +85,9 @@ export async function checkPeerPushDebit(
   req: CheckPeerPushDebitRequest,
 ): Promise<CheckPeerPushDebitResponse> {
   const instructedAmount = Amounts.parseOrThrow(req.amount);
+  logger.trace(
+    `checking peer push debit for ${Amounts.stringify(instructedAmount)}`,
+  );
   const coinSelRes = await selectPeerCoins(ws, { instructedAmount });
   if (coinSelRes.type === "failure") {
     throw TalerError.fromDetail(
@@ -98,10 +97,12 @@ export async function checkPeerPushDebit(
       },
     );
   }
+  logger.trace(`selected peer coins (len=${coinSelRes.result.coins.length})`);
   const totalAmount = await getTotalPeerPaymentCost(
     ws,
     coinSelRes.result.coins,
   );
+  logger.trace("computed total peer payment cost");
   return {
     exchangeBaseUrl: coinSelRes.result.exchangeBaseUrl,
     amountEffective: Amounts.stringify(totalAmount),
@@ -243,10 +244,6 @@ async function processPeerPushDebitCreateReserve(
     encryptContractRequest,
   );
 
-  const econtractHash = encodeCrock(
-    hash(decodeCrock(econtractResp.econtract.econtract)),
-  );
-
   const createPurseUrl = new URL(
     `purses/${peerPushInitiation.pursePub}/create`,
     peerPushInitiation.exchangeBaseUrl,

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