summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/common.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-02-21 14:23:01 +0100
committerFlorian Dold <florian@dold.me>2024-02-21 14:23:01 +0100
commit52a1f63e0a8cc2ca78910e8b56326376eb1d75d0 (patch)
treee59e898731a9eb76a9af3cec75256b5a07adf893 /packages/taler-wallet-core/src/common.ts
parent612b85c18fc17af412d08e075e1fddaa67aa7bf0 (diff)
downloadwallet-core-52a1f63e0a8cc2ca78910e8b56326376eb1d75d0.tar.gz
wallet-core-52a1f63e0a8cc2ca78910e8b56326376eb1d75d0.tar.bz2
wallet-core-52a1f63e0a8cc2ca78910e8b56326376eb1d75d0.zip
wallet-core: use cancellation tokens when possible
Diffstat (limited to 'packages/taler-wallet-core/src/common.ts')
-rw-r--r--packages/taler-wallet-core/src/common.ts88
1 files changed, 46 insertions, 42 deletions
diff --git a/packages/taler-wallet-core/src/common.ts b/packages/taler-wallet-core/src/common.ts
index 9b69ad6c4..8c6650f4a 100644
--- a/packages/taler-wallet-core/src/common.ts
+++ b/packages/taler-wallet-core/src/common.ts
@@ -337,7 +337,7 @@ export function constructTombstone(p: ParsedTombstone): TombstoneIdStr {
* Uniform interface for a particular wallet transaction.
*/
export interface TransactionManager {
- get taskId(): TaskId;
+ get taskId(): TaskIdStr;
get transactionId(): TransactionIdStr;
fail(): Promise<void>;
abort(): Promise<void>;
@@ -600,90 +600,92 @@ export function parseTaskIdentifier(x: string): ParsedTaskIdentifier {
}
}
-export function constructTaskIdentifier(p: ParsedTaskIdentifier): TaskId {
+export function constructTaskIdentifier(p: ParsedTaskIdentifier): TaskIdStr {
switch (p.tag) {
case PendingTaskType.Backup:
- return `${p.tag}:${p.backupProviderBaseUrl}` as TaskId;
+ return `${p.tag}:${p.backupProviderBaseUrl}` as TaskIdStr;
case PendingTaskType.Deposit:
- return `${p.tag}:${p.depositGroupId}` as TaskId;
+ return `${p.tag}:${p.depositGroupId}` as TaskIdStr;
case PendingTaskType.ExchangeUpdate:
- return `${p.tag}:${encodeURIComponent(p.exchangeBaseUrl)}` as TaskId;
+ return `${p.tag}:${encodeURIComponent(p.exchangeBaseUrl)}` as TaskIdStr;
case PendingTaskType.PeerPullDebit:
- return `${p.tag}:${p.peerPullDebitId}` as TaskId;
+ return `${p.tag}:${p.peerPullDebitId}` as TaskIdStr;
case PendingTaskType.PeerPushCredit:
- return `${p.tag}:${p.peerPushCreditId}` as TaskId;
+ return `${p.tag}:${p.peerPushCreditId}` as TaskIdStr;
case PendingTaskType.PeerPullCredit:
- return `${p.tag}:${p.pursePub}` as TaskId;
+ return `${p.tag}:${p.pursePub}` as TaskIdStr;
case PendingTaskType.PeerPushDebit:
- return `${p.tag}:${p.pursePub}` as TaskId;
+ return `${p.tag}:${p.pursePub}` as TaskIdStr;
case PendingTaskType.Purchase:
- return `${p.tag}:${p.proposalId}` as TaskId;
+ return `${p.tag}:${p.proposalId}` as TaskIdStr;
case PendingTaskType.Recoup:
- return `${p.tag}:${p.recoupGroupId}` as TaskId;
+ return `${p.tag}:${p.recoupGroupId}` as TaskIdStr;
case PendingTaskType.Refresh:
- return `${p.tag}:${p.refreshGroupId}` as TaskId;
+ return `${p.tag}:${p.refreshGroupId}` as TaskIdStr;
case PendingTaskType.RewardPickup:
- return `${p.tag}:${p.walletRewardId}` as TaskId;
+ return `${p.tag}:${p.walletRewardId}` as TaskIdStr;
case PendingTaskType.Withdraw:
- return `${p.tag}:${p.withdrawalGroupId}` as TaskId;
+ return `${p.tag}:${p.withdrawalGroupId}` as TaskIdStr;
default:
assertUnreachable(p);
}
}
export namespace TaskIdentifiers {
- export function forWithdrawal(wg: WithdrawalGroupRecord): TaskId {
- return `${PendingTaskType.Withdraw}:${wg.withdrawalGroupId}` as TaskId;
+ export function forWithdrawal(wg: WithdrawalGroupRecord): TaskIdStr {
+ return `${PendingTaskType.Withdraw}:${wg.withdrawalGroupId}` as TaskIdStr;
}
- export function forExchangeUpdate(exch: ExchangeEntryRecord): TaskId {
+ export function forExchangeUpdate(exch: ExchangeEntryRecord): TaskIdStr {
return `${PendingTaskType.ExchangeUpdate}:${encodeURIComponent(
exch.baseUrl,
- )}` as TaskId;
+ )}` as TaskIdStr;
}
- export function forExchangeUpdateFromUrl(exchBaseUrl: string): TaskId {
+ export function forExchangeUpdateFromUrl(exchBaseUrl: string): TaskIdStr {
return `${PendingTaskType.ExchangeUpdate}:${encodeURIComponent(
exchBaseUrl,
- )}` as TaskId;
+ )}` as TaskIdStr;
}
- export function forTipPickup(tipRecord: RewardRecord): TaskId {
- return `${PendingTaskType.RewardPickup}:${tipRecord.walletRewardId}` as TaskId;
+ export function forTipPickup(tipRecord: RewardRecord): TaskIdStr {
+ return `${PendingTaskType.RewardPickup}:${tipRecord.walletRewardId}` as TaskIdStr;
}
- export function forRefresh(refreshGroupRecord: RefreshGroupRecord): TaskId {
- return `${PendingTaskType.Refresh}:${refreshGroupRecord.refreshGroupId}` as TaskId;
+ export function forRefresh(
+ refreshGroupRecord: RefreshGroupRecord,
+ ): TaskIdStr {
+ return `${PendingTaskType.Refresh}:${refreshGroupRecord.refreshGroupId}` as TaskIdStr;
}
- export function forPay(purchaseRecord: PurchaseRecord): TaskId {
- return `${PendingTaskType.Purchase}:${purchaseRecord.proposalId}` as TaskId;
+ export function forPay(purchaseRecord: PurchaseRecord): TaskIdStr {
+ return `${PendingTaskType.Purchase}:${purchaseRecord.proposalId}` as TaskIdStr;
}
- export function forRecoup(recoupRecord: RecoupGroupRecord): TaskId {
- return `${PendingTaskType.Recoup}:${recoupRecord.recoupGroupId}` as TaskId;
+ export function forRecoup(recoupRecord: RecoupGroupRecord): TaskIdStr {
+ return `${PendingTaskType.Recoup}:${recoupRecord.recoupGroupId}` as TaskIdStr;
}
- export function forDeposit(depositRecord: DepositGroupRecord): TaskId {
- return `${PendingTaskType.Deposit}:${depositRecord.depositGroupId}` as TaskId;
+ export function forDeposit(depositRecord: DepositGroupRecord): TaskIdStr {
+ return `${PendingTaskType.Deposit}:${depositRecord.depositGroupId}` as TaskIdStr;
}
- export function forBackup(backupRecord: BackupProviderRecord): TaskId {
+ export function forBackup(backupRecord: BackupProviderRecord): TaskIdStr {
return `${PendingTaskType.Backup}:${encodeURIComponent(
backupRecord.baseUrl,
- )}` as TaskId;
+ )}` as TaskIdStr;
}
export function forPeerPushPaymentInitiation(
ppi: PeerPushDebitRecord,
- ): TaskId {
- return `${PendingTaskType.PeerPushDebit}:${ppi.pursePub}` as TaskId;
+ ): TaskIdStr {
+ return `${PendingTaskType.PeerPushDebit}:${ppi.pursePub}` as TaskIdStr;
}
export function forPeerPullPaymentInitiation(
ppi: PeerPullCreditRecord,
- ): TaskId {
- return `${PendingTaskType.PeerPullCredit}:${ppi.pursePub}` as TaskId;
+ ): TaskIdStr {
+ return `${PendingTaskType.PeerPullCredit}:${ppi.pursePub}` as TaskIdStr;
}
export function forPeerPullPaymentDebit(
ppi: PeerPullPaymentIncomingRecord,
- ): TaskId {
- return `${PendingTaskType.PeerPullDebit}:${ppi.peerPullDebitId}` as TaskId;
+ ): TaskIdStr {
+ return `${PendingTaskType.PeerPullDebit}:${ppi.peerPullDebitId}` as TaskIdStr;
}
export function forPeerPushCredit(
ppi: PeerPushPaymentIncomingRecord,
- ): TaskId {
- return `${PendingTaskType.PeerPushCredit}:${ppi.peerPushCreditId}` as TaskId;
+ ): TaskIdStr {
+ return `${PendingTaskType.PeerPushCredit}:${ppi.peerPushCreditId}` as TaskIdStr;
}
}
@@ -700,6 +702,8 @@ export enum TransitionResult {
* Uniform interface to all transactions.
*/
export interface TransactionContext {
+ get taskId(): TaskIdStr | undefined;
+ get transactionId(): TransactionIdStr;
abortTransaction(): Promise<void>;
suspendTransaction(): Promise<void>;
resumeTransaction(): Promise<void>;
@@ -729,5 +733,5 @@ export enum PendingTaskType {
PeerPullDebit = "peer-pull-debit",
}
-declare const __taskId: unique symbol;
-export type TaskId = string & { [__taskId]: true };
+declare const __taskIdStr: unique symbol;
+export type TaskIdStr = string & { [__taskIdStr]: true };