From c7c6ee7ba59467b8ddcfe8196b4f7586a864f3c0 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 13 Feb 2026 21:07:55 -0800 Subject: account level currency and autowithdraw settings --- lib/migrate.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib/migrate.ts') diff --git a/lib/migrate.ts b/lib/migrate.ts index 4b64bee5..d0e38276 100644 --- a/lib/migrate.ts +++ b/lib/migrate.ts @@ -136,4 +136,44 @@ export const migrateToMicrosats = async () => { return count; }; +export const migrateAutowithdraw = async () => { + const migrated = await db.get("autowithdraw:migrated"); + if (migrated) return 0; + + let count = 0; + + for await (const k of db.scanIterator({ MATCH: "user:*" })) { + try { + const raw = await db.get(k); + if (!raw || !raw.startsWith("{")) continue; + + const user = JSON.parse(raw); + if (!user.id || !user.autowithdraw) continue; + + const accountIds = await db.lRange(`${user.id}:accounts`, 0, -1); + + for (const aid of accountIds) { + const account = await g(`account:${aid}`); + if (!account) continue; + if (account.seed || account.type === "ark") continue; + if (account.autowithdraw) continue; + + account.autowithdraw = true; + account.threshold = account.threshold ?? user.threshold; + account.reserve = account.reserve ?? user.reserve; + account.destination = account.destination ?? user.destination; + + await s(`account:${aid}`, account); + count++; + } + } catch (e) { + warn("autowithdraw migration error", k, e.message); + } + } + + await db.set("autowithdraw:migrated", Date.now().toString()); + l(`Migrated autowithdraw to ${count} accounts`); + return count; +}; + export default migrate; -- cgit v1.2.3