Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,31 @@
|
||||
// Generated, do not edit. sha256:ef4dc1eb01e833a602dd00a17d235a583edc55c162bc923df89b4ecb9c82da16
|
||||
import * as db from '../db.js';
|
||||
import { nowIso } from './_shared.js';
|
||||
import { assertSourceMatchesAccount } from './wallet-sources.js';
|
||||
|
||||
export function listWalletAddresses(accountId) {
|
||||
return db.all(`SELECT * FROM WalletAddress
|
||||
WHERE accountId = ? ORDER BY chainIndex, derivationIndex, address`, [accountId]);
|
||||
}
|
||||
export async function upsertWalletAddresses(list) {
|
||||
for (const a of list) {
|
||||
assertSourceMatchesAccount('WalletAddress', a.accountId, a.sourceId);
|
||||
db.run(`INSERT INTO WalletAddress
|
||||
(accountId, sourceId, address, chainIndex, derivationIndex, automaticLabel, balanceSats, transactionCount, lastScannedAt)
|
||||
VALUES (?,?,?,?,?,?,?,?,?)
|
||||
ON CONFLICT(address) DO UPDATE SET
|
||||
accountId=excluded.accountId, sourceId=excluded.sourceId, chainIndex=excluded.chainIndex,
|
||||
derivationIndex=excluded.derivationIndex, automaticLabel=excluded.automaticLabel,
|
||||
balanceSats=excluded.balanceSats, transactionCount=excluded.transactionCount, lastScannedAt=excluded.lastScannedAt`,
|
||||
[a.accountId, a.sourceId ?? null, a.address, a.chainIndex ?? null, a.derivationIndex ?? null,
|
||||
a.automaticLabel ?? null, a.balanceSats ?? null, a.transactionCount ?? null, a.lastScannedAt ?? nowIso()]);
|
||||
}
|
||||
await db.persist();
|
||||
}
|
||||
export function sourceBalance(sourceId) {
|
||||
return db.one(`SELECT COALESCE(SUM(balanceSats),0) AS sats, COUNT(*) AS n, MAX(lastScannedAt) AS scanned
|
||||
FROM WalletAddress WHERE sourceId=?`, [sourceId]);
|
||||
}
|
||||
export function accountOnchainBalance(accountId) {
|
||||
return db.one(`SELECT COALESCE(SUM(balanceSats),0) AS sats FROM WalletAddress WHERE accountId=?`, [accountId]).sats;
|
||||
}
|
||||
Reference in new issue
Block a user