wallet-core: move deposit transaction deletion
This commit is contained in:
parent
fe8749c3f8
commit
5b665c7d80
@ -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);
|
||||
});
|
||||
|
@ -77,6 +77,7 @@ import {
|
||||
abortDepositGroup,
|
||||
cancelAbortingDepositGroup,
|
||||
computeDepositTransactionStatus,
|
||||
deleteDepositGroup,
|
||||
processDepositGroup,
|
||||
resumeDepositGroup,
|
||||
suspendDepositGroup,
|
||||
@ -1601,18 +1602,7 @@ export async function deleteTransaction(
|
||||
|
||||
case TransactionType.Deposit: {
|
||||
const depositGroupId = parsedTx.depositGroupId;
|
||||
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,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await deleteDepositGroup(ws, depositGroupId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user