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