diff options
4 files changed, 47 insertions, 17 deletions
diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index c67c59646..b7ebae1c1 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -1030,6 +1030,7 @@ export enum RefreshReason { AbortPay = "abort-pay", AbortDeposit = "abort-deposit", AbortPeerPushDebit = "abort-peer-push-debit", + AbortPeerPullDebit = "abort-peer-pull-debit", Recoup = "recoup", BackupRestored = "backup-restored", Scheduled = "scheduled", diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 0af04f80f..e92b0d449 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -1900,6 +1900,7 @@ export enum PeerPullPaymentCreditStatus { Done = 0x0500_0000, Failed = 0x0501_0000, + Expired = 0x0502_0000, Aborted = 0x0503_0000, } 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 3bcfa6643..44c9436b1 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 @@ -107,26 +107,47 @@ async function queryPurseForPeerPullCredit( timeout: { d_ms: 60000 }, cancellationToken, }); + const transactionId = constructTransactionIdentifier({ + tag: TransactionType.PeerPullCredit, + pursePub: pullIni.pursePub, + }); logger.info(`purse status code: HTTP ${resp.status}`); - const result = await readSuccessResponseJsonOrErrorCode( + switch (resp.status) { + case HttpStatusCode.Gone: { + // Exchange says that purse doesn't exist anymore => expired! + const transitionInfo = await ws.db + .mktx((x) => [x.peerPullCredit]) + .runReadWrite(async (tx) => { + const finPi = await tx.peerPullCredit.get(pullIni.pursePub); + if (!finPi) { + logger.warn("peerPullCredit not found anymore"); + return; + } + const oldTxState = computePeerPullCreditTransactionState(finPi); + if (finPi.status === PeerPullPaymentCreditStatus.PendingReady) { + finPi.status = PeerPullPaymentCreditStatus.Expired; + } + await tx.peerPullCredit.put(finPi); + const newTxState = computePeerPullCreditTransactionState(finPi); + return { oldTxState, newTxState }; + }); + notifyTransition(ws, transactionId, transitionInfo); + return { ready: true }; + } + case HttpStatusCode.NotFound: + return { ready: false }; + } + + const result = await readSuccessResponseJsonOrThrow( resp, codecForExchangePurseStatus(), ); - if (result.isError) { - logger.info(`got purse status error, EC=${result.talerErrorResponse.code}`); - if (resp.status === 404) { - return { ready: false }; - } else { - throwUnexpectedRequestError(resp, result.talerErrorResponse); - } - } - - logger.trace(`purse status: ${j2s(result.response)}`); + logger.trace(`purse status: ${j2s(result)}`); - const depositTimestamp = result.response.deposit_timestamp; + const depositTimestamp = result.deposit_timestamp; if (!depositTimestamp || TalerProtocolTimestamp.isNever(depositTimestamp)) { logger.info("purse not ready yet (no deposit)"); @@ -157,10 +178,6 @@ async function queryPurseForPeerPullCredit( pub: reserve.reservePub, }, }); - const transactionId = constructTransactionIdentifier({ - tag: TransactionType.PeerPullCredit, - pursePub: pullIni.pursePub, - }); const transitionInfo = await ws.db .mktx((x) => [x.peerPullCredit]) .runReadWrite(async (tx) => { @@ -538,6 +555,7 @@ export async function processPeerPullCredit( return handlePeerPullCreditWithdrawing(ws, pullIni); case PeerPullPaymentCreditStatus.Aborted: case PeerPullPaymentCreditStatus.Failed: + case PeerPullPaymentCreditStatus.Expired: case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: case PeerPullPaymentCreditStatus.SuspendedCreatePurse: case PeerPullPaymentCreditStatus.SuspendedMergeKycRequired: @@ -876,6 +894,7 @@ export async function suspendPeerPullCreditTransaction( case PeerPullPaymentCreditStatus.SuspendedWithdrawing: case PeerPullPaymentCreditStatus.Aborted: case PeerPullPaymentCreditStatus.Failed: + case PeerPullPaymentCreditStatus.Expired: case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: break; default: @@ -936,6 +955,7 @@ export async function abortPeerPullCreditTransaction( case PeerPullPaymentCreditStatus.Aborted: case PeerPullPaymentCreditStatus.AbortingDeletePurse: case PeerPullPaymentCreditStatus.Failed: + case PeerPullPaymentCreditStatus.Expired: case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: break; default: @@ -990,6 +1010,7 @@ export async function failPeerPullCreditTransaction( case PeerPullPaymentCreditStatus.SuspendedWithdrawing: case PeerPullPaymentCreditStatus.Aborted: case PeerPullPaymentCreditStatus.Failed: + case PeerPullPaymentCreditStatus.Expired: break; case PeerPullPaymentCreditStatus.AbortingDeletePurse: case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: @@ -1043,6 +1064,7 @@ export async function resumePeerPullCreditTransaction( case PeerPullPaymentCreditStatus.AbortingDeletePurse: case PeerPullPaymentCreditStatus.Done: case PeerPullPaymentCreditStatus.Failed: + case PeerPullPaymentCreditStatus.Expired: case PeerPullPaymentCreditStatus.Aborted: break; case PeerPullPaymentCreditStatus.SuspendedCreatePurse: @@ -1140,6 +1162,10 @@ export function computePeerPullCreditTransactionState( return { major: TransactionMajorState.Failed, }; + case PeerPullPaymentCreditStatus.Expired: + return { + major: TransactionMajorState.Expired, + }; case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: return { major: TransactionMajorState.Aborting, @@ -1176,6 +1202,8 @@ export function computePeerPullCreditTransactionActions( return [TransactionAction.Suspend, TransactionAction.Fail]; case PeerPullPaymentCreditStatus.Failed: return [TransactionAction.Delete]; + case PeerPullPaymentCreditStatus.Expired: + return [TransactionAction.Delete]; case PeerPullPaymentCreditStatus.SuspendedAbortingDeletePurse: return [TransactionAction.Resume, TransactionAction.Fail]; } diff --git a/packages/taler-wallet-core/src/operations/pay-peer-pull-debit.ts b/packages/taler-wallet-core/src/operations/pay-peer-pull-debit.ts index e7cf22187..cf5fc355d 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer-pull-debit.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer-pull-debit.ts @@ -272,7 +272,7 @@ async function processPeerPullDebitPendingDeposit( tx, currency, coinPubs, - RefreshReason.AbortPeerPushDebit, + RefreshReason.AbortPeerPullDebit, ); pi.status = PeerPullDebitRecordStatus.AbortingRefresh; |