diff options
author | Florian Dold <florian@dold.me> | 2021-05-20 17:11:44 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-05-20 17:11:44 +0200 |
commit | 6f1b7f5b998c1d7c385cad2f29a85db311999131 (patch) | |
tree | 26b41eb9fd4b86505a0ba869ae251dee2dcc5332 /packages/taler-wallet-core/src | |
parent | 6fc9a052b7f8e3ef0bd1b26279b11dc6bc12f5e4 (diff) | |
download | wallet-core-6f1b7f5b998c1d7c385cad2f29a85db311999131.tar.xz |
implement more deletion operations
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/operations/transactions.ts | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 48d0ffec5..02675adbd 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -368,8 +368,12 @@ export async function getTransactions( } export enum TombstoneTag { - WithdrawalGroup = "withdrawal-group", - Reserve = "reserve", + DeleteWithdrawalGroup = "delete-withdrawal-group", + DeleteReserve = "delete-reserve", + DeletePayment = "delete-payment", + DeleteTip = "delete-tip", + DeleteRefreshGroup = "delete-refresh-group", + DeleteDepositGroup = "delete-deposit-group", } /** @@ -383,7 +387,7 @@ export async function deleteTransaction( if (type === TransactionType.Withdrawal) { const withdrawalGroupId = rest[0]; - ws.db.runWithWriteTransaction( + await ws.db.runWithWriteTransaction( [Stores.withdrawalGroups, Stores.reserves, Stores.tombstones], async (tx) => { const withdrawalGroupRecord = await tx.get( @@ -393,7 +397,7 @@ export async function deleteTransaction( if (withdrawalGroupRecord) { await tx.delete(Stores.withdrawalGroups, withdrawalGroupId); await tx.put(Stores.tombstones, { - id: TombstoneTag.WithdrawalGroup + ":" + withdrawalGroupId, + id: TombstoneTag.DeleteWithdrawalGroup + ":" + withdrawalGroupId, }); return; } @@ -405,7 +409,72 @@ export async function deleteTransaction( const reservePub = reserveRecord.reservePub; await tx.delete(Stores.reserves, reservePub); await tx.put(Stores.tombstones, { - id: TombstoneTag.Reserve + ":" + reservePub, + id: TombstoneTag.DeleteReserve + ":" + reservePub, + }); + } + }, + ); + } else if (type === TransactionType.Payment) { + const proposalId = rest[0]; + await ws.db.runWithWriteTransaction( + [Stores.proposals, Stores.purchases, Stores.tombstones], + async (tx) => { + let found = false; + const proposal = await tx.get(Stores.proposals, proposalId); + if (proposal) { + found = true; + await tx.delete(Stores.proposals, proposalId); + } + const purchase = await tx.get(Stores.purchases, proposalId); + if (purchase) { + found = true; + await tx.delete(Stores.proposals, proposalId); + } + if (found) { + await tx.put(Stores.tombstones, { + id: TombstoneTag.DeletePayment + ":" + proposalId, + }); + } + }, + ); + } else if (type === TransactionType.Refresh) { + const refreshGroupId = rest[0]; + await ws.db.runWithWriteTransaction( + [Stores.refreshGroups, Stores.tombstones], + async (tx) => { + const rg = await tx.get(Stores.refreshGroups, refreshGroupId); + if (rg) { + await tx.delete(Stores.refreshGroups, refreshGroupId); + await tx.put(Stores.tombstones, { + id: TombstoneTag.DeleteRefreshGroup + ":" + refreshGroupId, + }); + } + }, + ); + } else if (type === TransactionType.Tip) { + const tipId = rest[0]; + await ws.db.runWithWriteTransaction( + [Stores.tips, Stores.tombstones], + async (tx) => { + const tipRecord = await tx.get(Stores.tips, tipId); + if (tipRecord) { + await tx.delete(Stores.tips, tipId); + await tx.put(Stores.tombstones, { + id: TombstoneTag.DeleteTip + ":" + tipId, + }); + } + }, + ); + } else if (type === TransactionType.Deposit) { + const depositGroupId = rest[0]; + await ws.db.runWithWriteTransaction( + [Stores.depositGroups, Stores.tombstones], + async (tx) => { + const tipRecord = await tx.get(Stores.depositGroups, depositGroupId); + if (tipRecord) { + await tx.delete(Stores.depositGroups, depositGroupId); + await tx.put(Stores.tombstones, { + id: TombstoneTag.DeleteDepositGroup + ":" + depositGroupId, }); } }, |