wallet-core: implement deletion for new refund implementation
This commit is contained in:
parent
a2ef2e391a
commit
318f544184
@ -362,9 +362,10 @@ export enum TombstoneTag {
|
||||
DeletePeerPushCredit = "delete-peer-push-credit",
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an event ID from the type and the primary key for the event.
|
||||
*
|
||||
* @deprecated use constructTombstone instead
|
||||
*/
|
||||
export function makeTombstoneId(type: TombstoneTag, ...args: string[]): string {
|
||||
return `tmb:${type}:${args.map((x) => encodeURIComponent(x)).join(":")}`;
|
||||
@ -458,3 +459,19 @@ export function runLongpollAsync(
|
||||
};
|
||||
asyncFn();
|
||||
}
|
||||
|
||||
export type ParsedTombstone =
|
||||
| {
|
||||
tag: TombstoneTag.DeleteWithdrawalGroup;
|
||||
withdrawalGroupId: string;
|
||||
}
|
||||
| { tag: TombstoneTag.DeleteRefund; refundGroupId: string };
|
||||
|
||||
export function constructTombstone(p: ParsedTombstone): string {
|
||||
switch (p.tag) {
|
||||
case TombstoneTag.DeleteWithdrawalGroup:
|
||||
return `tmb:${p.tag}:${p.withdrawalGroupId}`;
|
||||
case TombstoneTag.DeleteRefund:
|
||||
return `tmb:${p.tag}:${p.refundGroupId}`;
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ import { assertUnreachable } from "../util/assertUnreachable.js";
|
||||
import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js";
|
||||
import { constructTaskIdentifier, TaskIdentifiers } from "../util/retries.js";
|
||||
import {
|
||||
constructTombstone,
|
||||
makeTombstoneId,
|
||||
resetOperationTimeout,
|
||||
runOperationWithErrorReporting,
|
||||
@ -1615,7 +1616,22 @@ export async function deleteTransaction(
|
||||
}
|
||||
|
||||
case TransactionType.Refund: {
|
||||
// FIXME: Implement!
|
||||
const refundGroupId = parsedTx.refundGroupId;
|
||||
await ws.db
|
||||
.mktx((x) => [x.refundGroups, x.tombstones])
|
||||
.runReadWrite(async (tx) => {
|
||||
const refundRecord = await tx.refundGroups.get(refundGroupId);
|
||||
if (!refundRecord) {
|
||||
return;
|
||||
}
|
||||
await tx.refundGroups.delete(refundGroupId);
|
||||
await tx.tombstones.put({
|
||||
id: constructTombstone({
|
||||
tag: TombstoneTag.DeleteRefund,
|
||||
refundGroupId,
|
||||
}),
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user