fix sync flush looping and batch size, add alchemy call logging

This commit is contained in:
2026-05-21 17:55:29 +08:00
parent 85c25883c6
commit edd4f6fff0
8 changed files with 226 additions and 39 deletions
+12
View File
@@ -16,6 +16,7 @@ import {
getTransactionDetails,
getCachedTransactionHistory,
} from './lib/transactions'
import { syncTransactionHistory } from './lib/sync'
import { migrate } from 'drizzle-orm/bun-sqlite/migrator'
import { eq } from 'drizzle-orm'
import { db } from './lib/db'
@@ -185,6 +186,10 @@ type RPC = {
}
response: TxEntry[]
}
syncTxHistory: {
params: { address: string; chainid: string }
response: void
}
fetchTokenBalances: {
params: {
address: string
@@ -573,6 +578,13 @@ const rpc = BrowserView.defineRPC<RPC>({
const transfers = getCachedTransactionHistory(chainid, address)
return transfers.map(mapTransfer)
},
syncTxHistory: async ({ address, chainid }) => {
const key = await Bun.secrets.get({ service: 'koins', name: 'alchemy_key' })
if (!key) return
syncTransactionHistory(key, chainid, address).catch((e) =>
console.error('[sync] error:', e),
)
},
fetchTokenBalances: async ({ address, chainid }) => {
const key = await Bun.secrets.get({
service: 'koins',