summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts56
1 files changed, 22 insertions, 34 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts b/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts
index 88bdcb90e..4c00ed592 100644
--- a/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts
+++ b/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts
@@ -66,8 +66,8 @@ import { assertUnreachable } from "../util/assertUnreachable.js";
import { checkDbInvariant } from "../util/invariants.js";
import {
LongpollResult,
- OperationAttemptResult,
- OperationAttemptResultType,
+ TaskRunResult,
+ TaskRunResultType,
constructTaskIdentifier,
runLongpollAsync,
} from "./common.js";
@@ -184,7 +184,7 @@ async function longpollKycStatus(
exchangeUrl: string,
kycInfo: KycPendingInfo,
userType: KycUserType,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const transactionId = constructTransactionIdentifier({
tag: TransactionType.PeerPullCredit,
pursePub,
@@ -242,14 +242,14 @@ async function longpollKycStatus(
}
});
return {
- type: OperationAttemptResultType.Longpoll,
+ type: TaskRunResultType.Longpoll,
};
}
async function processPeerPullCreditAbortingDeletePurse(
ws: InternalWalletState,
peerPullIni: PeerPullPaymentInitiationRecord,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const { pursePub, pursePriv } = peerPullIni;
const transactionId = constructTransactionIdentifier({
tag: TransactionType.PeerPushDebit,
@@ -296,13 +296,13 @@ async function processPeerPullCreditAbortingDeletePurse(
});
notifyTransition(ws, transactionId, transitionInfo);
- return OperationAttemptResult.pendingEmpty();
+ return TaskRunResult.pending();
}
async function handlePeerPullCreditWithdrawing(
ws: InternalWalletState,
pullIni: PeerPullPaymentInitiationRecord,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
if (!pullIni.withdrawalGroupId) {
throw Error("invalid db state (withdrawing, but no withdrawal group ID");
}
@@ -346,17 +346,17 @@ async function handlePeerPullCreditWithdrawing(
});
notifyTransition(ws, transactionId, transitionInfo);
if (finished) {
- return OperationAttemptResult.finishedEmpty();
+ return TaskRunResult.finished();
} else {
// FIXME: Return indicator that we depend on the other operation!
- return OperationAttemptResult.pendingEmpty();
+ return TaskRunResult.pending();
}
}
async function handlePeerPullCreditCreatePurse(
ws: InternalWalletState,
pullIni: PeerPullPaymentInitiationRecord,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const purseFee = Amounts.stringify(Amounts.zeroOfAmount(pullIni.amount));
const pursePub = pullIni.pursePub;
const mergeReserve = await ws.db
@@ -447,16 +447,13 @@ async function handlePeerPullCreditCreatePurse(
await tx.peerPullPaymentInitiations.put(pi2);
});
- return {
- type: OperationAttemptResultType.Finished,
- result: undefined,
- };
+ return TaskRunResult.finished();
}
export async function processPeerPullCredit(
ws: InternalWalletState,
pursePub: string,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const pullIni = await ws.db
.mktx((x) => [x.peerPullPaymentInitiations])
.runReadOnly(async (tx) => {
@@ -475,7 +472,7 @@ export async function processPeerPullCredit(
if (ws.activeLongpoll[retryTag]) {
logger.info("peer-pull-credit already in long-polling, returning!");
return {
- type: OperationAttemptResultType.Longpoll,
+ type: TaskRunResultType.Longpoll,
};
}
@@ -483,10 +480,7 @@ export async function processPeerPullCredit(
switch (pullIni.status) {
case PeerPullPaymentInitiationStatus.Done: {
- return {
- type: OperationAttemptResultType.Finished,
- result: undefined,
- };
+ return TaskRunResult.finished();
}
case PeerPullPaymentInitiationStatus.PendingReady:
runLongpollAsync(ws, retryTag, async (cancellationToken) =>
@@ -496,7 +490,7 @@ export async function processPeerPullCredit(
"returning early from processPeerPullCredit for long-polling in background",
);
return {
- type: OperationAttemptResultType.Longpoll,
+ type: TaskRunResultType.Longpoll,
};
case PeerPullPaymentInitiationStatus.PendingMergeKycRequired: {
if (!pullIni.kycInfo) {
@@ -528,14 +522,14 @@ export async function processPeerPullCredit(
assertUnreachable(pullIni.status);
}
- return OperationAttemptResult.finishedEmpty();
+ return TaskRunResult.finished();
}
async function processPeerPullCreditKycRequired(
ws: InternalWalletState,
peerIni: PeerPullPaymentInitiationRecord,
kycPending: WalletKycUuid,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const transactionId = constructTransactionIdentifier({
tag: TransactionType.PeerPullCredit,
pursePub: peerIni.pursePub,
@@ -560,10 +554,7 @@ async function processPeerPullCreditKycRequired(
kycStatusRes.status === HttpStatusCode.NoContent
) {
logger.warn("kyc requested, but already fulfilled");
- return {
- type: OperationAttemptResultType.Finished,
- result: undefined,
- };
+ return TaskRunResult.finished();
} else if (kycStatusRes.status === HttpStatusCode.Accepted) {
const kycStatus = await kycStatusRes.json();
logger.info(`kyc status: ${j2s(kycStatus)}`);
@@ -574,7 +565,7 @@ async function processPeerPullCreditKycRequired(
if (!peerInc) {
return {
transitionInfo: undefined,
- result: OperationAttemptResult.finishedEmpty(),
+ result: TaskRunResult.finished(),
};
}
const oldTxState = computePeerPullCreditTransactionState(peerInc);
@@ -589,8 +580,8 @@ async function processPeerPullCreditKycRequired(
await tx.peerPullPaymentInitiations.put(peerInc);
// We'll remove this eventually! New clients should rely on the
// kycUrl field of the transaction, not the error code.
- const res: OperationAttemptResult = {
- type: OperationAttemptResultType.Error,
+ const res: TaskRunResult = {
+ type: TaskRunResultType.Error,
errorDetail: makeErrorDetail(
TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED,
{
@@ -604,10 +595,7 @@ async function processPeerPullCreditKycRequired(
};
});
notifyTransition(ws, transactionId, transitionInfo);
- return {
- type: OperationAttemptResultType.Pending,
- result: undefined,
- };
+ return TaskRunResult.pending();
} else {
throw Error(`unexpected response from kyc-check (${kycStatusRes.status})`);
}