diff options
author | Florian Dold <florian@dold.me> | 2024-03-27 19:45:16 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-03-27 19:45:16 +0100 |
commit | e0f4f29bc99372c22b6c1bfa09dcba2d85f3b608 (patch) | |
tree | 704bbca22ebe2a30dd98f7e5f719b49d3d8d985e /packages/taler-wallet-core/src/exchanges.ts | |
parent | be0f21389bb2c206344ed9c4f78c72ae84d5548d (diff) | |
download | wallet-core-e0f4f29bc99372c22b6c1bfa09dcba2d85f3b608.tar.xz |
wallet-core: purge other database tables when purging an exchange
Diffstat (limited to 'packages/taler-wallet-core/src/exchanges.ts')
-rw-r--r-- | packages/taler-wallet-core/src/exchanges.ts | 102 |
1 files changed, 90 insertions, 12 deletions
diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts index 152bc76ce..91d436100 100644 --- a/packages/taler-wallet-core/src/exchanges.ts +++ b/packages/taler-wallet-core/src/exchanges.ts @@ -2093,6 +2093,84 @@ async function internalGetExchangeResources( }; } +async function purgeExchange( + tx: WalletDbReadWriteTransaction< + [ + "exchanges", + "exchangeDetails", + "transactions", + "coinAvailability", + "coins", + "denominations", + "exchangeSignKeys", + "withdrawalGroups", + "planchets", + ] + >, + exchangeBaseUrl: string, +): Promise<void> { + const detRecs = await tx.exchangeDetails.indexes.byExchangeBaseUrl.getAll(); + for (const r of detRecs) { + if (r.rowId == null) { + // Should never happen, as rowId is the primary key. + continue; + } + await tx.exchangeDetails.delete(r.rowId); + const signkeyRecs = + await tx.exchangeSignKeys.indexes.byExchangeDetailsRowId.getAll(r.rowId); + for (const rec of signkeyRecs) { + await tx.exchangeSignKeys.delete([r.rowId, rec.signkeyPub]); + } + } + // FIXME: Also remove records related to transactions? + await tx.exchanges.delete(exchangeBaseUrl); + + { + const coinAvailabilityRecs = + await tx.coinAvailability.indexes.byExchangeBaseUrl.getAll( + exchangeBaseUrl, + ); + for (const rec of coinAvailabilityRecs) { + await tx.coinAvailability.delete([ + exchangeBaseUrl, + rec.denomPubHash, + rec.maxAge, + ]); + } + } + + { + const coinRecs = await tx.coins.indexes.byBaseUrl.getAll(exchangeBaseUrl); + for (const rec of coinRecs) { + await tx.coins.delete(rec.coinPub); + } + } + + { + const denomRecs = + await tx.denominations.indexes.byExchangeBaseUrl.getAll(exchangeBaseUrl); + for (const rec of denomRecs) { + await tx.denominations.delete(rec.denomPubHash); + } + } + + { + const withdrawalGroupRecs = + await tx.withdrawalGroups.indexes.byExchangeBaseUrl.getAll( + exchangeBaseUrl, + ); + for (const wg of withdrawalGroupRecs) { + await tx.withdrawalGroups.delete(wg.withdrawalGroupId); + const planchets = await tx.planchets.indexes.byGroup.getAll( + wg.withdrawalGroupId, + ); + for (const p of planchets) { + await tx.planchets.delete(p.coinPub); + } + } + } +} + export async function deleteExchange( wex: WalletExecutionContext, req: DeleteExchangeRequest, @@ -2100,7 +2178,17 @@ export async function deleteExchange( let inUse: boolean = false; const exchangeBaseUrl = canonicalizeBaseUrl(req.exchangeBaseUrl); await wex.db.runReadWriteTx( - ["exchanges", "coins", "withdrawalGroups", "exchangeDetails"], + [ + "exchanges", + "exchangeDetails", + "transactions", + "coinAvailability", + "coins", + "denominations", + "exchangeSignKeys", + "withdrawalGroups", + "planchets", + ], async (tx) => { const exchangeRec = await tx.exchanges.get(exchangeBaseUrl); if (!exchangeRec) { @@ -2113,17 +2201,7 @@ export async function deleteExchange( inUse = true; return; } - const detRecs = - await tx.exchangeDetails.indexes.byExchangeBaseUrl.getAll(); - for (const r of detRecs) { - if (r.rowId == null) { - // Should never happen, as rowId is the primary key. - continue; - } - await tx.exchangeDetails.delete(r.rowId); - } - // FIXME: Also remove records related to transactions? - await tx.exchanges.delete(exchangeBaseUrl); + await purgeExchange(tx, exchangeBaseUrl); }, ); |