fix bsc not working

This commit is contained in:
2026-05-16 14:44:09 +08:00
parent f5ddc8df1b
commit 21793eeb05
2 changed files with 17 additions and 5 deletions
+8 -3
View File
@@ -9,7 +9,11 @@ import {
type RPCSchema,
} from 'electrobun/bun'
import { inspect } from 'util'
import { getTokenMetadata, getTokensBalances } from './lib/alchemy'
import {
getTokenMetadata,
getTokensBalances,
type Transaction,
} from './lib/alchemy'
import { tryCatch } from '@koins/utils'
import { getTransactionHistory } from './lib/alchemy/get-transaction-history'
import { migrate } from 'drizzle-orm/bun-sqlite/migrator'
@@ -178,7 +182,7 @@ async function fetchAlchemyTransfers(
key: string,
chainid: string,
address: string,
): Promise<any[]> {
) {
const transactions = await getTransactionHistory(
key,
chainid,
@@ -252,7 +256,7 @@ function mapTransfer(t: any): TxEntry {
hash: t.hash,
timeStamp: String(
Math.floor(
new Date(t.metadata.blockTimestamp).getTime() / 1000,
new Date(t.metadata?.blockTimestamp).getTime() / 1000,
),
),
from: t.from,
@@ -302,6 +306,7 @@ const rpc = BrowserView.defineRPC<RPC>({
const addrLower = address.toLowerCase()
const byHash = new Map<string, any[]>()
for (const t of all) {
if (!t.hash) continue
const h = t.hash
if (!byHash.has(h)) byHash.set(h, [])
byHash.get(h)!.push(t)
@@ -2,6 +2,7 @@ import { post } from './call'
import { getChainID, getURL } from './network'
import type { Transaction } from './types'
import { numberToHex } from 'viem'
import { inspect } from 'util'
export const getTransactionHistory = async (
key: string,
@@ -17,6 +18,12 @@ export const getTransactionHistory = async (
key,
})
const category = ['external', 'erc20']
if (chainId !== '56') {
category.push('internal')
}
const body = (fromAddress?: string, toAddress?: string) => ({
jsonrpc: '2.0',
id: 0,
@@ -25,7 +32,7 @@ export const getTransactionHistory = async (
{
...(fromAddress ? { fromAddress } : {}),
...(toAddress ? { toAddress } : {}),
category: ['external', 'internal', 'erc20'],
category: category,
withMetadata: true,
maxCount: numberToHex(maxCount),
},
@@ -39,7 +46,7 @@ export const getTransactionHistory = async (
const inRequest = post<{
transfers: Transaction[]
}>(url, body(address, undefined))
}>(url, body(undefined, address))
const outRes = await outRequest
const inRes = await inRequest