diff options
Diffstat (limited to 'lib/tb.ts')
| -rw-r--r-- | lib/tb.ts | 49 |
1 files changed, 0 insertions, 49 deletions
@@ -671,52 +671,3 @@ export async function getFundBalance(name: string): Promise<number | null> { return accountBalance(account); } -// Migration helper: multiply existing balance by MULTIPLIER to convert sats→microsats -// Called by migrateToMicrosats() - adds (balance * 999999) to turn X into X*1000000 -// NOTE: This migration should only run ONCE - guarded by tb:microsats flag in migrate.ts -export async function tbMultiplyForMicrosats(uid: string): Promise<number> { - // Ensure client is initialized (needed when called during startup) - if (!client) { - await initTigerBeetle(); - } - - const MULTIPLIER = 999999n; // Adding this turns X into X*1000000 - let count = 0; - - const multiplyAccount = async (accountId: bigint, ledger: number, houseId: bigint) => { - const acct = await client.lookupAccounts([u128(accountId)]); - if (!acct.length) return; - const current = BigInt(acct[0].credits_posted) - BigInt(acct[0].debits_posted); - if (current <= 0n) return; - - const results = await client.createTransfers([ - { - id: nextTransferId(), - debit_account_id: u128(houseId), - credit_account_id: u128(accountId), - amount: current * MULTIPLIER, - pending_id: 0n, - user_data_128: 0n, - user_data_64: 0n, - user_data_32: 0, - timeout: 0, - ledger, - code: 1, - flags: 0, - timestamp: 0n, - }, - ]); - if (results.length === 0) count++; - }; - - const balId = balanceId(uid); - const pendId = pendingId(uid); - - await multiplyAccount(balId, LEDGER_SATS, HOUSE_SATS); - await multiplyAccount(pendId, LEDGER_SATS, HOUSE_SATS); - await multiplyAccount(creditId(uid, "bitcoin"), LEDGER_CREDIT_BTC, HOUSE_BTC); - await multiplyAccount(creditId(uid, "lightning"), LEDGER_CREDIT_LN, HOUSE_LN); - await multiplyAccount(creditId(uid, "liquid"), LEDGER_CREDIT_LQ, HOUSE_LQ); - - return count; -} |
