summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-12-18 13:53:15 +0100
committerFlorian Dold <florian@dold.me>2023-12-18 13:53:15 +0100
commita488ce70d6dbfe08845eccaeb2375b367f7c307a (patch)
tree25ab6b81f69e3a33ef0ec0907e4542d0287310a7 /packages/taler-wallet-core/src/operations
parent44f52cfad7158ca59115cdbf4b87824f98a06150 (diff)
downloadwallet-core-a488ce70d6dbfe08845eccaeb2375b367f7c307a.tar.gz
wallet-core-a488ce70d6dbfe08845eccaeb2375b367f7c307a.tar.bz2
wallet-core-a488ce70d6dbfe08845eccaeb2375b367f7c307a.zip
wallet-core: use getAll instead of iter to query denominations
Diffstat (limited to 'packages/taler-wallet-core/src/operations')
-rw-r--r--packages/taler-wallet-core/src/operations/pay-merchant.ts16
-rw-r--r--packages/taler-wallet-core/src/operations/pay-peer-common.ts24
-rw-r--r--packages/taler-wallet-core/src/operations/pay-peer-push-debit.ts13
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,