summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-05-25 19:31:14 +0200
committerFlorian Dold <florian@dold.me>2023-05-25 19:31:14 +0200
commit5b665c7d809def0c6e2d7487b43194d3042c9fe9 (patch)
tree1b750646256b3f85b2cf31e30a3cf3bcd3f3163e /packages/taler-wallet-core/src
parentfe8749c3f81547d080ea23d580497750d52fed91 (diff)
downloadwallet-core-5b665c7d809def0c6e2d7487b43194d3042c9fe9.tar.gz
wallet-core-5b665c7d809def0c6e2d7487b43194d3042c9fe9.tar.bz2
wallet-core-5b665c7d809def0c6e2d7487b43194d3042c9fe9.zip
wallet-core: move deposit transaction deletion
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r--packages/taler-wallet-core/src/operations/deposits.ts33
-rw-r--r--packages/taler-wallet-core/src/operations/transactions.ts14
2 files changed, 24 insertions, 23 deletions
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);
});
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts
index 84f879f58..e3cfa0c25 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -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;
}