From 5b665c7d809def0c6e2d7487b43194d3042c9fe9 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 25 May 2023 19:31:14 +0200 Subject: wallet-core: move deposit transaction deletion --- .../taler-wallet-core/src/operations/deposits.ts | 33 ++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/deposits.ts') diff --git a/packages/taler-wallet-core/src/operations/deposits.ts b/packages/taler-wallet-core/src/operations/deposits.ts index dc743e17f..a36091165 100644 --- a/packages/taler-wallet-core/src/operations/deposits.ts +++ b/packages/taler-wallet-core/src/operations/deposits.ts @@ -79,7 +79,7 @@ import { import { InternalWalletState } from "../internal-wallet-state.js"; import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http"; import { OperationAttemptResult } from "../util/retries.js"; -import { spendCoins } from "./common.js"; +import { spendCoins, TombstoneTag } from "./common.js"; import { getExchangeDetails } from "./exchanges.js"; import { extractContractData, @@ -166,15 +166,15 @@ export function computeDepositTransactionStatus( case DepositOperationStatus.Aborted: return { major: TransactionMajorState.Aborted, - } + }; case DepositOperationStatus.Failed: return { major: TransactionMajorState.Failed, - } + }; case DepositOperationStatus.SuspendedAborting: return { major: TransactionMajorState.SuspendedAborting, - } + }; default: throw Error(`unexpected deposit group state (${dg.operationStatus})`); } @@ -351,10 +351,21 @@ export async function cancelAbortingDepositGroup( export async function deleteDepositGroup( ws: InternalWalletState, - depositGroupId: boolean, - opts: { forced?: boolean } = {}, + depositGroupId: string, ) { - throw Error("not implemented"); + // FIXME: We should check first if we are in a final state + // where deletion is allowed. + await ws.db + .mktx((x) => [x.depositGroups, x.tombstones]) + .runReadWrite(async (tx) => { + const tipRecord = await tx.depositGroups.get(depositGroupId); + if (tipRecord) { + await tx.depositGroups.delete(depositGroupId); + await tx.tombstones.put({ + id: TombstoneTag.DeleteDepositGroup + ":" + depositGroupId, + }); + } + }); } /** @@ -503,7 +514,9 @@ async function refundDepositGroup( method: "POST", body: refundReq, }); - logger.info(`coin ${i} refund HTTP status for coin: ${httpResp.status}`); + logger.info( + `coin ${i} refund HTTP status for coin: ${httpResp.status}`, + ); let newStatus: DepositElementStatus; if (httpResp.status === 200) { // FIXME: validate response @@ -564,7 +577,6 @@ async function refundDepositGroup( await tx.depositGroups.put(newDg); }); - return OperationAttemptResult.pendingEmpty(); } @@ -742,8 +754,7 @@ export async function processDepositGroup( dg.trackingState = {}; } - dg.trackingState[newWiredCoin.id] = - newWiredCoin.value; + dg.trackingState[newWiredCoin.id] = newWiredCoin.value; } await tx.depositGroups.put(dg); }); -- cgit v1.2.3