diff options
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/shepherd.ts | 151 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 100 |
2 files changed, 141 insertions, 110 deletions
diff --git a/packages/taler-wallet-core/src/shepherd.ts b/packages/taler-wallet-core/src/shepherd.ts index 2fd260b11..bf2f6b50f 100644 --- a/packages/taler-wallet-core/src/shepherd.ts +++ b/packages/taler-wallet-core/src/shepherd.ts @@ -31,6 +31,7 @@ import { TalerErrorDetail, TaskThrottler, TransactionIdStr, + TransactionState, TransactionType, WalletNotification, assertUnreachable, @@ -53,20 +54,50 @@ import { OPERATION_STATUS_ACTIVE_FIRST, OPERATION_STATUS_ACTIVE_LAST, WalletDbAllStoresReadOnlyTransaction, + WalletDbReadOnlyTransaction, timestampAbsoluteFromDb, } from "./db.js"; -import { processDepositGroup } from "./deposits.js"; +import { + computeDepositTransactionStatus, + processDepositGroup, +} from "./deposits.js"; import { updateExchangeFromUrlHandler } from "./exchanges.js"; -import { processPurchase } from "./pay-merchant.js"; -import { processPeerPullCredit } from "./pay-peer-pull-credit.js"; -import { processPeerPullDebit } from "./pay-peer-pull-debit.js"; -import { processPeerPushCredit } from "./pay-peer-push-credit.js"; -import { processPeerPushDebit } from "./pay-peer-push-debit.js"; +import { + computePayMerchantTransactionState, + computeRefundTransactionState, + processPurchase, +} from "./pay-merchant.js"; +import { + computePeerPullCreditTransactionState, + processPeerPullCredit, +} from "./pay-peer-pull-credit.js"; +import { + computePeerPullDebitTransactionState, + processPeerPullDebit, +} from "./pay-peer-pull-debit.js"; +import { + computePeerPushCreditTransactionState, + processPeerPushCredit, +} from "./pay-peer-push-credit.js"; +import { + computePeerPushDebitTransactionState, + processPeerPushDebit, +} from "./pay-peer-push-debit.js"; import { processRecoupGroup } from "./recoup.js"; -import { processRefreshGroup } from "./refresh.js"; -import { constructTransactionIdentifier } from "./transactions.js"; +import { + computeRefreshTransactionState, + processRefreshGroup, +} from "./refresh.js"; +import { computeRewardTransactionStatus } from "./reward.js"; +import { + constructTransactionIdentifier, + parseTransactionIdentifier, +} from "./transactions.js"; import { InternalWalletState } from "./wallet.js"; -import { processWithdrawalGroup } from "./withdraw.js"; +import { + computeWithdrawalTransactionStatus, + processWithdrawalGroup, +} from "./withdraw.js"; const logger = new Logger("shepherd.ts"); @@ -616,6 +647,106 @@ async function taskToRetryNotification( } } +async function getTransactionState( + ws: InternalWalletState, + tx: WalletDbReadOnlyTransaction< + [ + "depositGroups", + "withdrawalGroups", + "purchases", + "refundGroups", + "peerPullCredit", + "peerPullDebit", + "peerPushDebit", + "peerPushCredit", + "rewards", + "refreshGroups", + ] + >, + transactionId: string, +): Promise<TransactionState | undefined> { + 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.peerPullCredit.get(parsedTxId.pursePub); + if (!rec) { + return undefined; + } + return computePeerPullCreditTransactionState(rec); + case TransactionType.PeerPullDebit: { + const rec = await tx.peerPullDebit.get(parsedTxId.peerPullDebitId); + if (!rec) { + return undefined; + } + return computePeerPullDebitTransactionState(rec); + } + case TransactionType.PeerPushCredit: { + const rec = await tx.peerPushCredit.get(parsedTxId.peerPushCreditId); + if (!rec) { + return undefined; + } + return computePeerPushCreditTransactionState(rec); + } + case TransactionType.PeerPushDebit: { + const rec = await tx.peerPushDebit.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.Reward: { + const rec = await tx.rewards.get(parsedTxId.walletRewardId); + if (!rec) { + return undefined; + } + return computeRewardTransactionStatus(rec); + } + case TransactionType.Recoup: + throw Error("not yet supported"); + default: + assertUnreachable(parsedTxId); + } +} + async function makeTransactionRetryNotification( ws: InternalWalletState, tx: WalletDbAllStoresReadOnlyTransaction, @@ -626,7 +757,7 @@ async function makeTransactionRetryNotification( if (!txId) { return undefined; } - const txState = await ws.getTransactionState(ws, tx, txId); + const txState = await getTransactionState(ws, tx, txId); if (!txState) { return undefined; } diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 7eac73827..13762d6e6 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -1535,106 +1535,6 @@ export class InternalWalletState { } } - async getTransactionState( - ws: InternalWalletState, - tx: WalletDbReadOnlyTransaction< - [ - "depositGroups", - "withdrawalGroups", - "purchases", - "refundGroups", - "peerPullCredit", - "peerPullDebit", - "peerPushDebit", - "peerPushCredit", - "rewards", - "refreshGroups", - ] - >, - transactionId: string, - ): Promise<TransactionState | undefined> { - 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.peerPullCredit.get(parsedTxId.pursePub); - if (!rec) { - return undefined; - } - return computePeerPullCreditTransactionState(rec); - case TransactionType.PeerPullDebit: { - const rec = await tx.peerPullDebit.get(parsedTxId.peerPullDebitId); - if (!rec) { - return undefined; - } - return computePeerPullDebitTransactionState(rec); - } - case TransactionType.PeerPushCredit: { - const rec = await tx.peerPushCredit.get(parsedTxId.peerPushCreditId); - if (!rec) { - return undefined; - } - return computePeerPushCreditTransactionState(rec); - } - case TransactionType.PeerPushDebit: { - const rec = await tx.peerPushDebit.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.Reward: { - const rec = await tx.rewards.get(parsedTxId.walletRewardId); - if (!rec) { - return undefined; - } - return computeRewardTransactionStatus(rec); - } - case TransactionType.Recoup: - throw Error("not yet supported"); - default: - assertUnreachable(parsedTxId); - } - } - async getDenomInfo( ws: InternalWalletState, tx: WalletDbReadOnlyTransaction<["denominations"]>, |