wallet-core: move deposit transaction deletion

This commit is contained in:
Florian Dold 2023-05-25 19:31:14 +02:00
parent fe8749c3f8
commit 5b665c7d80
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 24 additions and 23 deletions

View File

@ -79,7 +79,7 @@ import {
import { InternalWalletState } from "../internal-wallet-state.js"; import { InternalWalletState } from "../internal-wallet-state.js";
import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http"; import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http";
import { OperationAttemptResult } from "../util/retries.js"; import { OperationAttemptResult } from "../util/retries.js";
import { spendCoins } from "./common.js"; import { spendCoins, TombstoneTag } from "./common.js";
import { getExchangeDetails } from "./exchanges.js"; import { getExchangeDetails } from "./exchanges.js";
import { import {
extractContractData, extractContractData,
@ -166,15 +166,15 @@ export function computeDepositTransactionStatus(
case DepositOperationStatus.Aborted: case DepositOperationStatus.Aborted:
return { return {
major: TransactionMajorState.Aborted, major: TransactionMajorState.Aborted,
} };
case DepositOperationStatus.Failed: case DepositOperationStatus.Failed:
return { return {
major: TransactionMajorState.Failed, major: TransactionMajorState.Failed,
} };
case DepositOperationStatus.SuspendedAborting: case DepositOperationStatus.SuspendedAborting:
return { return {
major: TransactionMajorState.SuspendedAborting, major: TransactionMajorState.SuspendedAborting,
} };
default: default:
throw Error(`unexpected deposit group state (${dg.operationStatus})`); throw Error(`unexpected deposit group state (${dg.operationStatus})`);
} }
@ -351,10 +351,21 @@ export async function cancelAbortingDepositGroup(
export async function deleteDepositGroup( export async function deleteDepositGroup(
ws: InternalWalletState, ws: InternalWalletState,
depositGroupId: boolean, depositGroupId: string,
opts: { forced?: boolean } = {},
) { ) {
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", method: "POST",
body: refundReq, 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; let newStatus: DepositElementStatus;
if (httpResp.status === 200) { if (httpResp.status === 200) {
// FIXME: validate response // FIXME: validate response
@ -564,7 +577,6 @@ async function refundDepositGroup(
await tx.depositGroups.put(newDg); await tx.depositGroups.put(newDg);
}); });
return OperationAttemptResult.pendingEmpty(); return OperationAttemptResult.pendingEmpty();
} }
@ -742,8 +754,7 @@ export async function processDepositGroup(
dg.trackingState = {}; dg.trackingState = {};
} }
dg.trackingState[newWiredCoin.id] = dg.trackingState[newWiredCoin.id] = newWiredCoin.value;
newWiredCoin.value;
} }
await tx.depositGroups.put(dg); await tx.depositGroups.put(dg);
}); });

View File

@ -77,6 +77,7 @@ import {
abortDepositGroup, abortDepositGroup,
cancelAbortingDepositGroup, cancelAbortingDepositGroup,
computeDepositTransactionStatus, computeDepositTransactionStatus,
deleteDepositGroup,
processDepositGroup, processDepositGroup,
resumeDepositGroup, resumeDepositGroup,
suspendDepositGroup, suspendDepositGroup,
@ -1601,18 +1602,7 @@ export async function deleteTransaction(
case TransactionType.Deposit: { case TransactionType.Deposit: {
const depositGroupId = parsedTx.depositGroupId; const depositGroupId = parsedTx.depositGroupId;
await ws.db await deleteDepositGroup(ws, depositGroupId);
.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,
});
}
});
return; return;
} }