summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/transactions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/transactions.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/transactions.ts127
1 files changed, 119 insertions, 8 deletions
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts
index 3645edd93..f1cfaed45 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -86,20 +86,40 @@ import {
computeRefundTransactionState,
expectProposalDownload,
extractContractData,
+ resumePayMerchant,
+ suspendPayMerchant,
} from "./pay-merchant.js";
import {
computePeerPullCreditTransactionState,
computePeerPullDebitTransactionState,
computePeerPushCreditTransactionState,
computePeerPushDebitTransactionState,
+ resumePeerPullCreditTransaction,
+ resumePeerPullDebitTransaction,
+ resumePeerPushCreditTransaction,
+ resumePeerPushDebitTransaction,
+ suspendPeerPullCreditTransaction,
+ suspendPeerPullDebitTransaction,
+ suspendPeerPushCreditTransaction,
+ suspendPeerPushDebitTransaction,
} from "./pay-peer.js";
-import { computeRefreshTransactionState } from "./refresh.js";
-import { computeTipTransactionStatus } from "./tip.js";
+import {
+ computeRefreshTransactionState,
+ resumeRefreshGroup,
+ suspendRefreshGroup,
+} from "./refresh.js";
+import {
+ computeTipTransactionStatus,
+ resumeTipTransaction,
+ suspendTipTransaction,
+} from "./tip.js";
import {
abortWithdrawalTransaction,
augmentPaytoUrisForWithdrawal,
cancelAbortingWithdrawalTransaction,
computeWithdrawalTransactionStatus,
+ resumeWithdrawalTransaction,
+ suspendWithdrawalTransaction,
} from "./withdraw.js";
const logger = new Logger("taler-wallet-core:transactions.ts");
@@ -159,6 +179,7 @@ export async function getTransactionById(
}
switch (parsedTx.tag) {
+ case TransactionType.InternalWithdrawal:
case TransactionType.Withdrawal: {
const withdrawalGroupId = parsedTx.withdrawalGroupId;
return await ws.db
@@ -844,7 +865,7 @@ async function buildTransactionForPurchase(
proposalId: purchaseRecord.proposalId,
info,
refundQueryActive:
- purchaseRecord.purchaseStatus === PurchaseStatus.QueryingRefund,
+ purchaseRecord.purchaseStatus === PurchaseStatus.PendingQueryingRefund,
...(ort?.lastError ? { error: ort.lastError } : {}),
};
}
@@ -1197,7 +1218,8 @@ export type ParsedTransactionIdentifier =
| { tag: TransactionType.Refresh; refreshGroupId: string }
| { tag: TransactionType.Refund; refundGroupId: string }
| { tag: TransactionType.Tip; walletTipId: string }
- | { tag: TransactionType.Withdrawal; withdrawalGroupId: string };
+ | { tag: TransactionType.Withdrawal; withdrawalGroupId: string }
+ | { tag: TransactionType.InternalWithdrawal; withdrawalGroupId: string };
export function constructTransactionIdentifier(
pTxId: ParsedTransactionIdentifier,
@@ -1223,6 +1245,8 @@ export function constructTransactionIdentifier(
return `txn:${pTxId.tag}:${pTxId.walletTipId}` as TransactionIdStr;
case TransactionType.Withdrawal:
return `txn:${pTxId.tag}:${pTxId.withdrawalGroupId}` as TransactionIdStr;
+ case TransactionType.InternalWithdrawal:
+ return `txn:${pTxId.tag}:${pTxId.withdrawalGroupId}` as TransactionIdStr;
default:
assertUnreachable(pTxId);
}
@@ -1242,6 +1266,10 @@ export function parseTransactionIdentifier(
const [prefix, type, ...rest] = txnParts;
+ if (prefix != "txn") {
+ throw Error("invalid transaction identifier");
+ }
+
switch (type) {
case TransactionType.Deposit:
return { tag: TransactionType.Deposit, depositGroupId: rest[0] };
@@ -1329,6 +1357,7 @@ export async function retryTransaction(
stopLongpolling(ws, taskId);
break;
}
+ case TransactionType.InternalWithdrawal:
case TransactionType.Withdrawal: {
// FIXME: Abort current long-poller!
const taskId = constructTaskIdentifier({
@@ -1366,8 +1395,38 @@ export async function retryTransaction(
stopLongpolling(ws, taskId);
break;
}
- default:
+ case TransactionType.PeerPullDebit: {
+ const taskId = constructTaskIdentifier({
+ tag: PendingTaskType.PeerPullDebit,
+ peerPullPaymentIncomingId: parsedTx.peerPullPaymentIncomingId,
+ });
+ await resetOperationTimeout(ws, taskId);
+ stopLongpolling(ws, taskId);
+ break;
+ }
+ case TransactionType.PeerPushCredit: {
+ const taskId = constructTaskIdentifier({
+ tag: PendingTaskType.PeerPushCredit,
+ peerPushPaymentIncomingId: parsedTx.peerPushPaymentIncomingId,
+ });
+ await resetOperationTimeout(ws, taskId);
+ stopLongpolling(ws, taskId);
break;
+ }
+ case TransactionType.PeerPushDebit: {
+ const taskId = constructTaskIdentifier({
+ tag: PendingTaskType.PeerPushDebit,
+ pursePub: parsedTx.pursePub,
+ });
+ await resetOperationTimeout(ws, taskId);
+ stopLongpolling(ws, taskId);
+ break;
+ }
+ case TransactionType.Refund:
+ // Nothing to do for a refund transaction.
+ break;
+ default:
+ assertUnreachable(parsedTx);
}
}
@@ -1389,8 +1448,35 @@ export async function suspendTransaction(
case TransactionType.Deposit:
await suspendDepositGroup(ws, tx.depositGroupId);
return;
+ case TransactionType.Refresh:
+ await suspendRefreshGroup(ws, tx.refreshGroupId);
+ return;
+ case TransactionType.InternalWithdrawal:
+ case TransactionType.Withdrawal:
+ await suspendWithdrawalTransaction(ws, tx.withdrawalGroupId);
+ return;
+ case TransactionType.Payment:
+ await suspendPayMerchant(ws, tx.proposalId);
+ return;
+ case TransactionType.PeerPullCredit:
+ await suspendPeerPullCreditTransaction(ws, tx.pursePub);
+ break;
+ case TransactionType.PeerPushDebit:
+ await suspendPeerPushDebitTransaction(ws, tx.pursePub);
+ break;
+ case TransactionType.PeerPullDebit:
+ await suspendPeerPullDebitTransaction(ws, tx.peerPullPaymentIncomingId);
+ break;
+ case TransactionType.PeerPushCredit:
+ await suspendPeerPushCreditTransaction(ws, tx.peerPushPaymentIncomingId);
+ break;
+ case TransactionType.Refund:
+ throw Error("refund transactions can't be suspended or resumed");
+ case TransactionType.Tip:
+ await suspendTipTransaction(ws, tx.walletTipId);
+ break;
default:
- logger.warn(`unable to suspend transaction of type '${tx.tag}'`);
+ assertUnreachable(tx);
}
}
@@ -1429,8 +1515,33 @@ export async function resumeTransaction(
case TransactionType.Deposit:
await resumeDepositGroup(ws, tx.depositGroupId);
return;
- default:
- logger.warn(`unable to resume transaction of type '${tx.tag}'`);
+ case TransactionType.Refresh:
+ await resumeRefreshGroup(ws, tx.refreshGroupId);
+ return;
+ case TransactionType.InternalWithdrawal:
+ case TransactionType.Withdrawal:
+ await resumeWithdrawalTransaction(ws, tx.withdrawalGroupId);
+ return;
+ case TransactionType.Payment:
+ await resumePayMerchant(ws, tx.proposalId);
+ return;
+ case TransactionType.PeerPullCredit:
+ await resumePeerPullCreditTransaction(ws, tx.pursePub);
+ break;
+ case TransactionType.PeerPushDebit:
+ await resumePeerPushDebitTransaction(ws, tx.pursePub);
+ break;
+ case TransactionType.PeerPullDebit:
+ await resumePeerPullDebitTransaction(ws, tx.peerPullPaymentIncomingId);
+ break;
+ case TransactionType.PeerPushCredit:
+ await resumePeerPushCreditTransaction(ws, tx.peerPushPaymentIncomingId);
+ break;
+ case TransactionType.Refund:
+ throw Error("refund transactions can't be suspended or resumed");
+ case TransactionType.Tip:
+ await resumeTipTransaction(ws, tx.walletTipId);
+ break;
}
}