summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/pay-peer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-peer.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/pay-peer.ts348
1 files changed, 344 insertions, 4 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-peer.ts b/packages/taler-wallet-core/src/operations/pay-peer.ts
index fb1260e3c..95878543b 100644
--- a/packages/taler-wallet-core/src/operations/pay-peer.ts
+++ b/packages/taler-wallet-core/src/operations/pay-peer.ts
@@ -1008,7 +1008,7 @@ export async function processPeerPushCredit(
const amount = Amounts.parseOrThrow(contractTerms.amount);
if (
- peerInc.status === PeerPushPaymentIncomingStatus.MergeKycRequired &&
+ peerInc.status === PeerPushPaymentIncomingStatus.PendingMergeKycRequired &&
peerInc.kycInfo
) {
const txId = constructTransactionIdentifier({
@@ -1080,7 +1080,7 @@ export async function processPeerPushCredit(
paytoHash: kycPending.h_payto,
requirementRow: kycPending.requirement_row,
};
- peerInc.status = PeerPushPaymentIncomingStatus.MergeKycRequired;
+ peerInc.status = PeerPushPaymentIncomingStatus.PendingMergeKycRequired;
await tx.peerPushPaymentIncoming.put(peerInc);
});
return {
@@ -1122,7 +1122,7 @@ export async function processPeerPushCredit(
}
if (
peerInc.status === PeerPushPaymentIncomingStatus.PendingMerge ||
- peerInc.status === PeerPushPaymentIncomingStatus.MergeKycRequired
+ peerInc.status === PeerPushPaymentIncomingStatus.PendingMergeKycRequired
) {
peerInc.status = PeerPushPaymentIncomingStatus.Done;
}
@@ -2186,6 +2186,345 @@ export async function suspendPeerPushDebitTransaction(
notifyTransition(ws, transactionId, transitionInfo);
}
+export async function suspendPeerPullDebitTransaction(
+ ws: InternalWalletState,
+ peerPullPaymentIncomingId: string,
+) {
+ const taskId = constructTaskIdentifier({
+ tag: PendingTaskType.PeerPullDebit,
+ peerPullPaymentIncomingId,
+ });
+ const transactionId = constructTransactionIdentifier({
+ tag: TransactionType.PeerPullDebit,
+ peerPullPaymentIncomingId,
+ });
+ stopLongpolling(ws, taskId);
+ const transitionInfo = await ws.db
+ .mktx((x) => [x.peerPullPaymentIncoming])
+ .runReadWrite(async (tx) => {
+ const pullDebitRec = await tx.peerPullPaymentIncoming.get(
+ peerPullPaymentIncomingId,
+ );
+ if (!pullDebitRec) {
+ logger.warn(`peer pull debit ${peerPullPaymentIncomingId} not found`);
+ return;
+ }
+ let newStatus: PeerPullDebitRecordStatus | undefined = undefined;
+ switch (pullDebitRec.status) {
+ case PeerPullDebitRecordStatus.DialogProposed:
+ break;
+ case PeerPullDebitRecordStatus.DonePaid:
+ break;
+ case PeerPullDebitRecordStatus.PendingDeposit:
+ newStatus = PeerPullDebitRecordStatus.SuspendedDeposit;
+ break;
+ case PeerPullDebitRecordStatus.SuspendedDeposit:
+ break;
+ default:
+ assertUnreachable(pullDebitRec.status);
+ }
+ if (newStatus != null) {
+ const oldTxState = computePeerPullDebitTransactionState(pullDebitRec);
+ pullDebitRec.status = newStatus;
+ const newTxState = computePeerPullDebitTransactionState(pullDebitRec);
+ await tx.peerPullPaymentIncoming.put(pullDebitRec);
+ return {
+ oldTxState,
+ newTxState,
+ };
+ }
+ return undefined;
+ });
+ notifyTransition(ws, transactionId, transitionInfo);
+}
+
+export async function resumePeerPullDebitTransaction(
+ ws: InternalWalletState,
+ peerPullPaymentIncomingId: string,
+) {
+ const taskId = constructTaskIdentifier({
+ tag: PendingTaskType.PeerPullDebit,
+ peerPullPaymentIncomingId,
+ });
+ const transactionId = constructTransactionIdentifier({
+ tag: TransactionType.PeerPullDebit,
+ peerPullPaymentIncomingId,
+ });
+ stopLongpolling(ws, taskId);
+ const transitionInfo = await ws.db
+ .mktx((x) => [x.peerPullPaymentIncoming])
+ .runReadWrite(async (tx) => {
+ const pullDebitRec = await tx.peerPullPaymentIncoming.get(
+ peerPullPaymentIncomingId,
+ );
+ if (!pullDebitRec) {
+ logger.warn(`peer pull debit ${peerPullPaymentIncomingId} not found`);
+ return;
+ }
+ let newStatus: PeerPullDebitRecordStatus | undefined = undefined;
+ switch (pullDebitRec.status) {
+ case PeerPullDebitRecordStatus.DialogProposed:
+ case PeerPullDebitRecordStatus.DonePaid:
+ case PeerPullDebitRecordStatus.PendingDeposit:
+ break;
+ case PeerPullDebitRecordStatus.SuspendedDeposit:
+ newStatus = PeerPullDebitRecordStatus.PendingDeposit;
+ break;
+ default:
+ assertUnreachable(pullDebitRec.status);
+ }
+ if (newStatus != null) {
+ const oldTxState = computePeerPullDebitTransactionState(pullDebitRec);
+ pullDebitRec.status = newStatus;
+ const newTxState = computePeerPullDebitTransactionState(pullDebitRec);
+ await tx.peerPullPaymentIncoming.put(pullDebitRec);
+ return {
+ oldTxState,
+ newTxState,
+ };
+ }
+ return undefined;
+ });
+ ws.workAvailable.trigger();
+ notifyTransition(ws, transactionId, transitionInfo);
+}
+
+export async function suspendPeerPushCreditTransaction(
+ ws: InternalWalletState,
+ peerPushPaymentIncomingId: string,
+) {
+ const taskId = constructTaskIdentifier({
+ tag: PendingTaskType.PeerPushCredit,
+ peerPushPaymentIncomingId,
+ });
+ const transactionId = constructTransactionIdentifier({
+ tag: TransactionType.PeerPushCredit,
+ peerPushPaymentIncomingId,
+ });
+ stopLongpolling(ws, taskId);
+ const transitionInfo = await ws.db
+ .mktx((x) => [x.peerPushPaymentIncoming])
+ .runReadWrite(async (tx) => {
+ const pushCreditRec = await tx.peerPushPaymentIncoming.get(
+ peerPushPaymentIncomingId,
+ );
+ if (!pushCreditRec) {
+ logger.warn(`peer push credit ${peerPushPaymentIncomingId} not found`);
+ return;
+ }
+ let newStatus: PeerPushPaymentIncomingStatus | undefined = undefined;
+ switch (pushCreditRec.status) {
+ case PeerPushPaymentIncomingStatus.DialogProposed:
+ case PeerPushPaymentIncomingStatus.Done:
+ case PeerPushPaymentIncomingStatus.SuspendedMerge:
+ case PeerPushPaymentIncomingStatus.SuspendedMergeKycRequired:
+ case PeerPushPaymentIncomingStatus.SuspendedWithdrawing:
+ break;
+ case PeerPushPaymentIncomingStatus.PendingMergeKycRequired:
+ newStatus = PeerPushPaymentIncomingStatus.SuspendedMergeKycRequired;
+ break;
+ case PeerPushPaymentIncomingStatus.PendingMerge:
+ newStatus = PeerPushPaymentIncomingStatus.SuspendedMerge;
+ break;
+ case PeerPushPaymentIncomingStatus.PendingWithdrawing:
+ // FIXME: Suspend internal withdrawal transaction!
+ newStatus = PeerPushPaymentIncomingStatus.SuspendedWithdrawing;
+ break;
+ default:
+ assertUnreachable(pushCreditRec.status);
+ }
+ if (newStatus != null) {
+ const oldTxState = computePeerPushCreditTransactionState(pushCreditRec);
+ pushCreditRec.status = newStatus;
+ const newTxState = computePeerPushCreditTransactionState(pushCreditRec);
+ await tx.peerPushPaymentIncoming.put(pushCreditRec);
+ return {
+ oldTxState,
+ newTxState,
+ };
+ }
+ return undefined;
+ });
+ notifyTransition(ws, transactionId, transitionInfo);
+}
+
+export async function resumePeerPushCreditTransaction(
+ ws: InternalWalletState,
+ peerPushPaymentIncomingId: string,
+) {
+ const taskId = constructTaskIdentifier({
+ tag: PendingTaskType.PeerPushCredit,
+ peerPushPaymentIncomingId,
+ });
+ const transactionId = constructTransactionIdentifier({
+ tag: TransactionType.PeerPushCredit,
+ peerPushPaymentIncomingId,
+ });
+ stopLongpolling(ws, taskId);
+ const transitionInfo = await ws.db
+ .mktx((x) => [x.peerPushPaymentIncoming])
+ .runReadWrite(async (tx) => {
+ const pushCreditRec = await tx.peerPushPaymentIncoming.get(
+ peerPushPaymentIncomingId,
+ );
+ if (!pushCreditRec) {
+ logger.warn(`peer push credit ${peerPushPaymentIncomingId} not found`);
+ return;
+ }
+ let newStatus: PeerPushPaymentIncomingStatus | undefined = undefined;
+ switch (pushCreditRec.status) {
+ case PeerPushPaymentIncomingStatus.DialogProposed:
+ case PeerPushPaymentIncomingStatus.Done:
+ case PeerPushPaymentIncomingStatus.PendingMergeKycRequired:
+ case PeerPushPaymentIncomingStatus.PendingMerge:
+ case PeerPushPaymentIncomingStatus.PendingWithdrawing:
+ case PeerPushPaymentIncomingStatus.SuspendedMerge:
+ newStatus = PeerPushPaymentIncomingStatus.PendingMerge;
+ break;
+ case PeerPushPaymentIncomingStatus.SuspendedMergeKycRequired:
+ newStatus = PeerPushPaymentIncomingStatus.PendingMergeKycRequired;
+ break;
+ case PeerPushPaymentIncomingStatus.SuspendedWithdrawing:
+ // FIXME: resume underlying "internal-withdrawal" transaction.
+ newStatus = PeerPushPaymentIncomingStatus.PendingWithdrawing;
+ break;
+ default:
+ assertUnreachable(pushCreditRec.status);
+ }
+ if (newStatus != null) {
+ const oldTxState = computePeerPushCreditTransactionState(pushCreditRec);
+ pushCreditRec.status = newStatus;
+ const newTxState = computePeerPushCreditTransactionState(pushCreditRec);
+ await tx.peerPushPaymentIncoming.put(pushCreditRec);
+ return {
+ oldTxState,
+ newTxState,
+ };
+ }
+ return undefined;
+ });
+ ws.workAvailable.trigger();
+ notifyTransition(ws, transactionId, transitionInfo);
+}
+
+export async function suspendPeerPullCreditTransaction(
+ ws: InternalWalletState,
+ pursePub: string,
+) {
+ const taskId = constructTaskIdentifier({
+ tag: PendingTaskType.PeerPullCredit,
+ pursePub,
+ });
+ const transactionId = constructTransactionIdentifier({
+ tag: TransactionType.PeerPullCredit,
+ pursePub,
+ });
+ stopLongpolling(ws, taskId);
+ const transitionInfo = await ws.db
+ .mktx((x) => [x.peerPullPaymentInitiations])
+ .runReadWrite(async (tx) => {
+ const pullCreditRec = await tx.peerPullPaymentInitiations.get(pursePub);
+ if (!pullCreditRec) {
+ logger.warn(`peer pull credit ${pursePub} not found`);
+ return;
+ }
+ let newStatus: PeerPullPaymentInitiationStatus | undefined = undefined;
+ switch (pullCreditRec.status) {
+ case PeerPullPaymentInitiationStatus.PendingCreatePurse:
+ newStatus = PeerPullPaymentInitiationStatus.SuspendedCreatePurse;
+ break;
+ case PeerPullPaymentInitiationStatus.PendingMergeKycRequired:
+ newStatus = PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired;
+ break;
+ case PeerPullPaymentInitiationStatus.PendingWithdrawing:
+ newStatus = PeerPullPaymentInitiationStatus.SuspendedWithdrawing;
+ break;
+ case PeerPullPaymentInitiationStatus.PendingReady:
+ newStatus = PeerPullPaymentInitiationStatus.SuspendedReady;
+ break;
+ case PeerPullPaymentInitiationStatus.DonePurseDeposited:
+ case PeerPullPaymentInitiationStatus.SuspendedCreatePurse:
+ case PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired:
+ case PeerPullPaymentInitiationStatus.SuspendedReady:
+ case PeerPullPaymentInitiationStatus.SuspendedWithdrawing:
+ break;
+ default:
+ assertUnreachable(pullCreditRec.status);
+ }
+ if (newStatus != null) {
+ const oldTxState = computePeerPullCreditTransactionState(pullCreditRec);
+ pullCreditRec.status = newStatus;
+ const newTxState = computePeerPullCreditTransactionState(pullCreditRec);
+ await tx.peerPullPaymentInitiations.put(pullCreditRec);
+ return {
+ oldTxState,
+ newTxState,
+ };
+ }
+ return undefined;
+ });
+ notifyTransition(ws, transactionId, transitionInfo);
+}
+
+export async function resumePeerPullCreditTransaction(
+ ws: InternalWalletState,
+ pursePub: string,
+) {
+ const taskId = constructTaskIdentifier({
+ tag: PendingTaskType.PeerPullCredit,
+ pursePub,
+ });
+ const transactionId = constructTransactionIdentifier({
+ tag: TransactionType.PeerPullCredit,
+ pursePub,
+ });
+ stopLongpolling(ws, taskId);
+ const transitionInfo = await ws.db
+ .mktx((x) => [x.peerPullPaymentInitiations])
+ .runReadWrite(async (tx) => {
+ const pullCreditRec = await tx.peerPullPaymentInitiations.get(pursePub);
+ if (!pullCreditRec) {
+ logger.warn(`peer pull credit ${pursePub} not found`);
+ return;
+ }
+ let newStatus: PeerPullPaymentInitiationStatus | undefined = undefined;
+ switch (pullCreditRec.status) {
+ case PeerPullPaymentInitiationStatus.PendingCreatePurse:
+ case PeerPullPaymentInitiationStatus.PendingMergeKycRequired:
+ case PeerPullPaymentInitiationStatus.PendingWithdrawing:
+ case PeerPullPaymentInitiationStatus.PendingReady:
+ case PeerPullPaymentInitiationStatus.DonePurseDeposited:
+ case PeerPullPaymentInitiationStatus.SuspendedCreatePurse:
+ newStatus = PeerPullPaymentInitiationStatus.PendingCreatePurse;
+ break;
+ case PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired:
+ newStatus = PeerPullPaymentInitiationStatus.PendingMergeKycRequired;
+ break;
+ case PeerPullPaymentInitiationStatus.SuspendedReady:
+ newStatus = PeerPullPaymentInitiationStatus.PendingReady;
+ break;
+ case PeerPullPaymentInitiationStatus.SuspendedWithdrawing:
+ newStatus = PeerPullPaymentInitiationStatus.PendingWithdrawing;
+ break;
+ default:
+ assertUnreachable(pullCreditRec.status);
+ }
+ if (newStatus != null) {
+ const oldTxState = computePeerPullCreditTransactionState(pullCreditRec);
+ pullCreditRec.status = newStatus;
+ const newTxState = computePeerPullCreditTransactionState(pullCreditRec);
+ await tx.peerPullPaymentInitiations.put(pullCreditRec);
+ return {
+ oldTxState,
+ newTxState,
+ };
+ }
+ return undefined;
+ });
+ ws.workAvailable.trigger();
+ notifyTransition(ws, transactionId, transitionInfo);
+}
+
export async function resumePeerPushDebitTransaction(
ws: InternalWalletState,
pursePub: string,
@@ -2244,6 +2583,7 @@ export async function resumePeerPushDebitTransaction(
}
return undefined;
});
+ ws.workAvailable.trigger();
notifyTransition(ws, transactionId, transitionInfo);
}
@@ -2265,7 +2605,7 @@ export function computePeerPushCreditTransactionState(
return {
major: TransactionMajorState.Done,
};
- case PeerPushPaymentIncomingStatus.MergeKycRequired:
+ case PeerPushPaymentIncomingStatus.PendingMergeKycRequired:
return {
major: TransactionMajorState.Pending,
minor: TransactionMinorState.KycRequired,