diff options
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.ts | 59 |
1 files changed, 58 insertions, 1 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 333202a69..e9c34cf73 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 @@ -83,7 +83,6 @@ import { stopLongpolling, } from "./transactions.js"; import { - checkWithdrawalKycStatus, getExchangeWithdrawalInfo, internalCreateWithdrawalGroup, processWithdrawalGroup, @@ -241,6 +240,62 @@ async function longpollKycStatus( }; } +async function processPeerPullCreditAbortingDeletePurse( + ws: InternalWalletState, + peerPullIni: PeerPullPaymentInitiationRecord, +): Promise<OperationAttemptResult> { + const { pursePub, pursePriv } = peerPullIni; + const transactionId = constructTransactionIdentifier({ + tag: TransactionType.PeerPushDebit, + pursePub, + }); + + const sigResp = await ws.cryptoApi.signDeletePurse({ + pursePriv, + }); + const purseUrl = new URL( + `purses/${pursePub}`, + peerPullIni.exchangeBaseUrl, + ); + const resp = await ws.http.fetch(purseUrl.href, { + method: "DELETE", + headers: { + "taler-purse-signature": sigResp.sig, + }, + }); + logger.info(`deleted purse with response status ${resp.status}`); + + const transitionInfo = await ws.db + .mktx((x) => [ + x.peerPullPaymentInitiations, + x.refreshGroups, + x.denominations, + x.coinAvailability, + x.coins, + ]) + .runReadWrite(async (tx) => { + const ppiRec = await tx.peerPullPaymentInitiations.get(pursePub); + if (!ppiRec) { + return undefined; + } + if ( + ppiRec.status !== PeerPullPaymentInitiationStatus.AbortingDeletePurse + ) { + return undefined; + } + const oldTxState = computePeerPullCreditTransactionState(ppiRec); + ppiRec.status = PeerPullPaymentInitiationStatus.Aborted; + const newTxState = computePeerPullCreditTransactionState(ppiRec); + return { + oldTxState, + newTxState, + }; + }); + notifyTransition(ws, transactionId, transitionInfo); + + return OperationAttemptResult.pendingEmpty(); +} + export async function processPeerPullCredit( ws: InternalWalletState, pursePub: string, @@ -320,6 +375,8 @@ export async function processPeerPullCredit( } case PeerPullPaymentInitiationStatus.PendingCreatePurse: break; + case PeerPullPaymentInitiationStatus.AbortingDeletePurse: + return await processPeerPullCreditAbortingDeletePurse(ws, pullIni); default: throw Error(`unknown PeerPullPaymentInitiationStatus ${pullIni.status}`); } |