taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit d615c2a935d3d126492afdb77fb4dba7d044e2f1
parent 3f1d1e0252fb43afd0c178a3736b7bb56765465a
Author: Florian Dold <florian@dold.me>
Date:   Wed, 23 Oct 2024 14:28:15 +0200

wallet-core: fix scopeInfo handling, fix wrong txId

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts | 8++++----
Mpackages/taler-wallet-core/src/pay-peer-push-credit.ts | 29+++++++++++++++--------------
Mpackages/taler-wallet-core/src/pay-peer-push-debit.ts | 6++----
3 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts b/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts @@ -29,12 +29,12 @@ import { j2s, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, withdrawViaBankV3, } from "../harness/environments.js"; +import { GlobalTestState } from "../harness/harness.js"; /** * Run a test for basic peer-push payments. @@ -153,19 +153,19 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) { t.assertDeepEqual(txDetails.type, TransactionType.PeerPushDebit); t.assertTrue(!!txDetails.talerUri); - const checkResp = await w2.walletClient.call( + const prepareResp = await w2.walletClient.call( WalletApiOperation.PreparePeerPushCredit, { talerUri: txDetails.talerUri, }, ); - console.log(checkResp); + console.log(prepareResp); const acceptResp = await w2.walletClient.call( WalletApiOperation.ConfirmPeerPushCredit, { - transactionId: checkResp.transactionId, + transactionId: prepareResp.transactionId, }, ); diff --git a/packages/taler-wallet-core/src/pay-peer-push-credit.ts b/packages/taler-wallet-core/src/pay-peer-push-credit.ts @@ -29,7 +29,6 @@ import { PeerContractTerms, PreparePeerPushCreditRequest, PreparePeerPushCreditResponse, - ScopeType, TalerErrorDetail, TalerPreciseTimestamp, Transaction, @@ -89,6 +88,7 @@ import { BalanceThresholdCheckResult, checkIncomingAmountLegalUnderKycBalanceThreshold, fetchFreshExchange, + getExchangeScopeInfo, getScopeForAllExchanges, handleStartExchangeWalletKyc, } from "./exchanges.js"; @@ -632,6 +632,11 @@ export async function preparePeerPushCredit( if (existing) { const currency = Amounts.currencyOf(existing.existingContractTerms.amount); + const exchangeBaseUrl = existing.existingPushInc.exchangeBaseUrl; + const scopeInfo = await wex.db.runAllStoresReadOnlyTx( + {}, + async (tx) => await getExchangeScopeInfo(tx, exchangeBaseUrl, currency), + ); return { amount: existing.existingContractTerms.amount, amountEffective: existing.existingPushInc.estimatedAmountEffective, @@ -642,13 +647,8 @@ export async function preparePeerPushCredit( tag: TransactionType.PeerPushCredit, peerPushCreditId: existing.existingPushInc.peerPushCreditId, }), - // FIXME: Shouldn't we place this in a tighter scope? - scopeInfo: { - type: ScopeType.Exchange, - currency, - url: existing.existingPushInc.exchangeBaseUrl, - }, - exchangeBaseUrl: existing.existingPushInc.exchangeBaseUrl, + scopeInfo, + exchangeBaseUrl, ...getPeerCreditLimitInfo( exchange, existing.existingContractTerms.amount, @@ -712,7 +712,7 @@ export async function preparePeerPushCredit( ); } - const ctx = new PeerPushCreditTransactionContext(wex, withdrawalGroupId); + const ctx = new PeerPushCreditTransactionContext(wex, peerPushCreditId); const transitionInfo = await wex.db.runReadWriteTx( { storeNames: ["contractTerms", "peerPushCredit", "transactionsMeta"] }, @@ -754,6 +754,11 @@ export async function preparePeerPushCredit( notifyTransition(wex, ctx.transactionId, transitionInfo); + const scopeInfo = await wex.db.runAllStoresReadOnlyTx( + {}, + async (tx) => await getExchangeScopeInfo(tx, exchangeBaseUrl, currency), + ); + return { amount: purseStatus.balance, amountEffective: wi.withdrawalAmountEffective, @@ -763,11 +768,7 @@ export async function preparePeerPushCredit( transactionId: ctx.transactionId, exchangeBaseUrl, // FIXME: Shouldn't we place this in a tighter scope? - scopeInfo: { - type: ScopeType.Exchange, - currency, - url: exchangeBaseUrl, - }, + scopeInfo, ...getPeerCreditLimitInfo(exchange, purseStatus.balance), }; } diff --git a/packages/taler-wallet-core/src/pay-peer-push-debit.ts b/packages/taler-wallet-core/src/pay-peer-push-debit.ts @@ -458,7 +458,7 @@ async function internalCheckPeerPushDebit( logger.trace( `checking peer push debit for ${Amounts.stringify(instructedAmount)}`, ); - let restrictScope: ScopeInfo; + let restrictScope: ScopeInfo | undefined = undefined; if (req.restrictScope) { restrictScope = req.restrictScope; } else if (req.exchangeBaseUrl) { @@ -467,12 +467,10 @@ async function internalCheckPeerPushDebit( currency, url: req.exchangeBaseUrl, }; - } else { - throw Error("client must either specify exchangeBaseUrl or restrictScope"); } const coinSelRes = await selectPeerCoins(wex, { instructedAmount, - restrictScope: req.restrictScope, + restrictScope, feesCoveredByCounterparty: false, }); let coins: SelectedProspectiveCoin[] | undefined = undefined;