From 5154aca23446d617882f85038231198824010c47 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 28 Feb 2024 00:23:26 +0100 Subject: wallet-core: translate transactionId to taskIds --- packages/taler-util/src/wallet-types.ts | 14 ++++ packages/taler-wallet-core/src/shepherd.ts | 85 ++++++++++++++++++++++ packages/taler-wallet-core/src/wallet-api-types.ts | 13 ++++ packages/taler-wallet-core/src/wallet.ts | 15 +++- 4 files changed, 126 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 486522f7c..c336752a4 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -2293,6 +2293,20 @@ export interface WalletCurrencyInfo { }[]; } +export interface TestingListTasksForTransactionRequest { + transactionId: TransactionIdStr; +} + +export interface TestingListTasksForTransactionsResponse { + taskIdList: string[]; +} + +export const codecForTestingListTasksForTransactionRequest = + (): Codec => + buildCodecForObject() + .property("transactionId", codecForTransactionIdStr()) + .build("TestingListTasksForTransactionRequest"); + export interface DeleteTransactionRequest { transactionId: TransactionIdStr; } diff --git a/packages/taler-wallet-core/src/shepherd.ts b/packages/taler-wallet-core/src/shepherd.ts index e6ea412e3..8fdf2b66b 100644 --- a/packages/taler-wallet-core/src/shepherd.ts +++ b/packages/taler-wallet-core/src/shepherd.ts @@ -843,6 +843,91 @@ async function makeExchangeRetryNotification( return notif; } +export function listTaskForTransactionId(transactionId: string): TaskIdStr[] { + const tid = parseTransactionIdentifier(transactionId); + if (!tid) { + throw Error("invalid task ID"); + } + switch (tid.tag) { + case TransactionType.Deposit: + return [ + constructTaskIdentifier({ + tag: PendingTaskType.Deposit, + depositGroupId: tid.depositGroupId, + }), + ]; + case TransactionType.InternalWithdrawal: + return [ + constructTaskIdentifier({ + tag: PendingTaskType.Withdraw, + withdrawalGroupId: tid.withdrawalGroupId, + }), + ]; + case TransactionType.Payment: + return [ + constructTaskIdentifier({ + tag: PendingTaskType.Purchase, + proposalId: tid.proposalId, + }), + ]; + case TransactionType.PeerPullCredit: + return [ + constructTaskIdentifier({ + tag: PendingTaskType.PeerPullCredit, + pursePub: tid.pursePub, + }), + ]; + case TransactionType.PeerPullDebit: + return [ + constructTaskIdentifier({ + tag: PendingTaskType.PeerPullDebit, + peerPullDebitId: tid.peerPullDebitId, + }), + ]; + case TransactionType.PeerPushCredit: + return [ + constructTaskIdentifier({ + tag: PendingTaskType.PeerPullCredit, + pursePub: tid.peerPushCreditId, + }), + ]; + case TransactionType.PeerPushDebit: + return [ + constructTaskIdentifier({ + tag: PendingTaskType.PeerPullCredit, + pursePub: tid.pursePub, + }), + ]; + case TransactionType.Recoup: + return [ + constructTaskIdentifier({ + tag: PendingTaskType.Recoup, + recoupGroupId: tid.recoupGroupId, + }), + ]; + case TransactionType.Refresh: + return [ + constructTaskIdentifier({ + tag: PendingTaskType.Refresh, + refreshGroupId: tid.refreshGroupId, + }), + ]; + case TransactionType.Refund: + return []; + case TransactionType.Reward: + return []; + case TransactionType.Withdrawal: + return [ + constructTaskIdentifier({ + tag: PendingTaskType.Withdraw, + withdrawalGroupId: tid.withdrawalGroupId, + }), + ]; + default: + assertUnreachable(tid); + } +} + /** * Convert the task ID for a task that processes a transaction int * the ID for the transaction. diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index cf8f93ed1..5e2d83a33 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -116,6 +116,8 @@ import { StoredBackupList, TestPayArgs, TestPayResult, + TestingListTasksForTransactionRequest, + TestingListTasksForTransactionsResponse, TestingSetTimetravelRequest, TestingWaitTransactionRequest, Transaction, @@ -250,6 +252,7 @@ export enum WalletApiOperation { AddGlobalCurrencyAuditor = "addGlobalCurrencyAuditor", RemoveGlobalCurrencyAuditor = "removeGlobalCurrencyAuditor", ListAssociatedRefreshes = "listAssociatedRefreshes", + TestingListTaskForTransaction = "testingListTasksForTransaction", } // group: Initialization @@ -1113,6 +1116,15 @@ export type TestingSetTimetravelOp = { response: EmptyObject; }; +/** + * Add an offset to the wallet's internal time. + */ +export type TestingListTasksForTransactionOp = { + op: WalletApiOperation.TestingListTaskForTransaction; + request: TestingListTasksForTransactionRequest; + response: TestingListTasksForTransactionsResponse; +}; + /** * Wait until all transactions are in a final state. */ @@ -1263,6 +1275,7 @@ export type WalletOperations = { [WalletApiOperation.AddGlobalCurrencyExchange]: AddGlobalCurrencyExchangeOp; [WalletApiOperation.RemoveGlobalCurrencyExchange]: RemoveGlobalCurrencyExchangeOp; [WalletApiOperation.ListAssociatedRefreshes]: ListAssociatedRefreshesOp; + [WalletApiOperation.TestingListTaskForTransaction]: TestingListTasksForTransactionOp; }; export type WalletCoreRequestType< diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index ea3c4bb83..14f4c85c3 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -55,6 +55,7 @@ import { TalerErrorCode, TalerProtocolTimestamp, TalerUriAction, + TestingListTasksForTransactionsResponse, TestingWaitTransactionRequest, TimerAPI, TimerGroup, @@ -121,6 +122,7 @@ import { codecForStartRefundQueryRequest, codecForSuspendTransaction, codecForTestPayArgs, + codecForTestingListTasksForTransactionRequest, codecForTestingSetTimetravelRequest, codecForTransactionByIdRequest, codecForTransactionsRequest, @@ -233,7 +235,11 @@ import { } from "./pay-peer-push-debit.js"; import { DbAccess } from "./query.js"; import { forceRefresh } from "./refresh.js"; -import { TaskScheduler, TaskSchedulerImpl } from "./shepherd.js"; +import { + TaskScheduler, + TaskSchedulerImpl, + listTaskForTransactionId, +} from "./shepherd.js"; import { runIntegrationTest, runIntegrationTest2, @@ -717,6 +723,13 @@ async function dispatchRequestInternal( await withdrawTestBalance(wex, req); return {}; } + case WalletApiOperation.TestingListTaskForTransaction: { + const req = + codecForTestingListTasksForTransactionRequest().decode(payload); + return { + taskIdList: listTaskForTransactionId(req.transactionId), + } satisfies TestingListTasksForTransactionsResponse; + } case WalletApiOperation.RunIntegrationTest: { const req = codecForIntegrationTestArgs().decode(payload); await runIntegrationTest(wex, req); -- cgit v1.2.3