From 9c708251f92e6691ebba80fa8d129c6c04cec618 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 20 Jun 2023 11:40:06 +0200 Subject: wallet-core: emit DD37 self-transition notifications with errors --- packages/taler-wallet-core/src/wallet.ts | 108 +++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 5 deletions(-) (limited to 'packages/taler-wallet-core/src/wallet.ts') diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index a04464630..e5cd713b8 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -48,6 +48,7 @@ import { RefreshReason, TalerError, TalerErrorCode, + TransactionState, TransactionType, URL, ValidateIbanResponse, @@ -170,9 +171,10 @@ import { getBalanceDetail, getBalances } from "./operations/balance.js"; import { getExchangeTosStatus, makeExchangeListItem, - runOperationWithErrorReporting, + runTaskWithErrorReporting, } from "./operations/common.js"; import { + computeDepositTransactionStatus, createDepositGroup, generateDepositGroupTxId, prepareDepositGroup, @@ -191,6 +193,9 @@ import { } from "./operations/exchanges.js"; import { getMerchantInfo } from "./operations/merchants.js"; import { + computePayMerchantTransactionActions, + computePayMerchantTransactionState, + computeRefundTransactionState, confirmPay, getContractTermsDetails, preparePayForUri, @@ -200,21 +205,25 @@ import { } from "./operations/pay-merchant.js"; import { checkPeerPullPaymentInitiation, + computePeerPullCreditTransactionState, initiatePeerPullPayment, processPeerPullCredit, } from "./operations/pay-peer-pull-credit.js"; import { + computePeerPullDebitTransactionState, confirmPeerPullDebit, preparePeerPullDebit, processPeerPullDebit, } from "./operations/pay-peer-pull-debit.js"; import { + computePeerPushCreditTransactionState, confirmPeerPushCredit, preparePeerPushCredit, processPeerPushCredit, } from "./operations/pay-peer-push-credit.js"; import { checkPeerPushDebit, + computePeerPushDebitTransactionState, initiatePeerPushDebit, processPeerPushDebit, } from "./operations/pay-peer-push-debit.js"; @@ -222,6 +231,7 @@ import { getPendingOperations } from "./operations/pending.js"; import { createRecoupGroup, processRecoupGroup } from "./operations/recoup.js"; import { autoRefresh, + computeRefreshTransactionState, createRefreshGroup, processRefreshGroup, } from "./operations/refresh.js"; @@ -231,7 +241,7 @@ import { testPay, withdrawTestBalance, } from "./operations/testing.js"; -import { acceptTip, prepareTip, processTip } from "./operations/tip.js"; +import { acceptTip, computeTipTransactionStatus, prepareTip, processTip } from "./operations/tip.js"; import { abortTransaction, deleteTransaction, @@ -245,6 +255,7 @@ import { } from "./operations/transactions.js"; import { acceptWithdrawalFromUri, + computeWithdrawalTransactionStatus, createManualWithdrawal, getExchangeWithdrawalInfo, getWithdrawalDetailsForUri, @@ -268,7 +279,7 @@ import { GetReadOnlyAccess, GetReadWriteAccess, } from "./util/query.js"; -import { OperationAttemptResult, TaskIdentifiers } from "./util/retries.js"; +import { OperationAttemptResult, TaskIdentifiers } from "./operations/common.js"; import { TimerAPI, TimerGroup } from "./util/timer.js"; import { WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, @@ -337,7 +348,7 @@ export async function runPending(ws: InternalWalletState): Promise { if (!AbsoluteTime.isExpired(p.timestampDue)) { continue; } - await runOperationWithErrorReporting(ws, p.id, async () => { + await runTaskWithErrorReporting(ws, p.id, async () => { logger.trace(`running pending ${JSON.stringify(p, undefined, 2)}`); return await callOperationHandler(ws, p); }); @@ -439,7 +450,7 @@ async function runTaskLoop( if (!AbsoluteTime.isExpired(p.timestampDue)) { continue; } - await runOperationWithErrorReporting(ws, p.id, async () => { + await runTaskWithErrorReporting(ws, p.id, async () => { logger.trace(`running pending ${JSON.stringify(p, undefined, 2)}`); return await callOperationHandler(ws, p); }); @@ -1711,6 +1722,93 @@ class InternalWalletStateImpl implements InternalWalletState { } } + async getTransactionState( + ws: InternalWalletState, + tx: GetReadOnlyAccess, + transactionId: string, + ): Promise { + const parsedTxId = parseTransactionIdentifier(transactionId); + if (!parsedTxId) { + throw Error("invalid tx identifier"); + } + switch (parsedTxId.tag) { + case TransactionType.Deposit: { + const rec = await tx.depositGroups.get(parsedTxId.depositGroupId); + if (!rec) { + return undefined; + } + return computeDepositTransactionStatus(rec); + } + case TransactionType.InternalWithdrawal: + case TransactionType.Withdrawal: { + const rec = await tx.withdrawalGroups.get(parsedTxId.withdrawalGroupId); + if (!rec) { + return undefined; + } + return computeWithdrawalTransactionStatus(rec); + } + case TransactionType.Payment: { + const rec = await tx.purchases.get(parsedTxId.proposalId); + if (!rec) { + return; + } + return computePayMerchantTransactionState(rec); + } + case TransactionType.Refund: { + const rec = await tx.refundGroups.get( + parsedTxId.refundGroupId, + ); + if (!rec) { + return undefined; + } + return computeRefundTransactionState(rec); + } + case TransactionType.PeerPullCredit: + const rec = await tx.peerPullPaymentInitiations.get(parsedTxId.pursePub); + if (!rec) { + return undefined; + } + return computePeerPullCreditTransactionState(rec); + case TransactionType.PeerPullDebit: { + const rec = await tx.peerPullPaymentIncoming.get(parsedTxId.peerPullPaymentIncomingId); + if (!rec) { + return undefined; + } + return computePeerPullDebitTransactionState(rec); + } + case TransactionType.PeerPushCredit: { + const rec = await tx.peerPushPaymentIncoming.get(parsedTxId.peerPushPaymentIncomingId); + if (!rec) { + return undefined; + } + return computePeerPushCreditTransactionState(rec); + } + case TransactionType.PeerPushDebit: { + const rec = await tx.peerPushPaymentInitiations.get(parsedTxId.pursePub); + if (!rec) { + return undefined; + } + return computePeerPushDebitTransactionState(rec); + } + case TransactionType.Refresh: { + const rec = await tx.refreshGroups.get(parsedTxId.refreshGroupId); + if (!rec) { + return undefined; + } + return computeRefreshTransactionState(rec) + } + case TransactionType.Tip: { + const rec = await tx.tips.get(parsedTxId.walletTipId); + if (!rec) { + return undefined; + } + return computeTipTransactionStatus(rec); + } + default: + assertUnreachable(parsedTxId); + } + } + async getDenomInfo( ws: InternalWalletState, tx: GetReadWriteAccess<{ -- cgit v1.2.3