diff options
| author | Adam Soltys <[email protected]> | 2026-02-04 13:05:01 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-06 08:59:26 -0800 |
| commit | 384c4778ca5421c091a7d282b90b00965f3596cd (patch) | |
| tree | 0803cb8872128007e5487f94a9b9e7a00cbffba6 /lib/migrate.ts | |
| parent | 5e3bfba5eb3d54cc03551f98624a2e92dca5825f (diff) | |
| download | coinos-server-384c4778ca5421c091a7d282b90b00965f3596cd.tar.gz coinos-server-384c4778ca5421c091a7d282b90b00965f3596cd.zip | |
zmq logic
Diffstat (limited to 'lib/migrate.ts')
| -rw-r--r-- | lib/migrate.ts | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/migrate.ts b/lib/migrate.ts index 58623ec1..8fd4ec1a 100644 --- a/lib/migrate.ts +++ b/lib/migrate.ts @@ -1,4 +1,6 @@ -import { g } from "$lib/db"; +import { db, g, s } from "$lib/db"; +import { findLastUsedIndex, parseDescriptor } from "$lib/esplora"; +import { warn } from "$lib/logging"; async function migrate(id) { const k = id?.replace(/\s/g, "").toLowerCase(); @@ -7,4 +9,44 @@ async function migrate(id) { return user; } +export const migrateAccounts = async () => { + const keys = await db.keys("account:*"); + let migrated = 0; + + for (const key of keys) { + try { + if (key.endsWith(":invoices")) continue; + const keyType = await db.type(key); + if (keyType !== "string") continue; + + const account = await g(key); + if (!account || !account.id) continue; + if (account.pubkey || account.type === "ark" || !account.seed) continue; + if (!account.descriptors?.length) continue; + + const parsed = parseDescriptor(account.descriptors[0].desc); + if (!parsed) continue; + + account.pubkey = parsed.pubkey; + account.fingerprint = parsed.fingerprint; + try { + account.nextIndex = await findLastUsedIndex( + parsed.pubkey, + parsed.fingerprint, + ); + } catch (e) { + warn("account migration index scan skipped", key, e.message); + account.nextIndex = account.nextIndex || 0; + } + + await s(`account:${account.id}`, account); + migrated++; + } catch (e) { + warn("failed to migrate account", key, e.message); + } + } + + return migrated; +}; + export default migrate; |
