diff --git a/bun.lockb b/bun.lockb index d0c52df..4c2c8b1 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/lib/utils.ts b/src/lib/utils.ts index b34e5f2..361be22 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -69,7 +69,10 @@ export const getContractInformation = async ( ): Promise => { try { const response = await fetch(`https://anyabi.xyz/api/get-abi/${chainId}/${address}`) - if (!response.ok) return { name: 'Unverified', address, abi: [] } + if (!response.ok) { + consola.info('ABI not found.') + return { name: 'Unverified', address, abi: [] } + } const contractData = await response.json() return { @@ -78,7 +81,8 @@ export const getContractInformation = async ( } } catch (e) { consola.error(e) - throw new Error('Contract not found') + consola.info('ABI not found.') + return { name: 'Unverified', address, abi: [] } } } @@ -89,6 +93,7 @@ export const getCachedContractInformation = async ( ): Promise => { try { consola.info('Fetching contract information for', address, 'on chain', chainId) + consola.info('Checking for cached ABI...') const result = await db .select() .from(contracts) @@ -102,6 +107,7 @@ export const getCachedContractInformation = async ( address, } } + consola.info('Not found in cache. Fetching from anyabi.xyz...') const contract = await getContractInformation(address, chainId) // Don't cache unverified contracts @@ -110,7 +116,7 @@ export const getCachedContractInformation = async ( } // Update the database - consola.info('Updating db cache') + consola.info('Updating db cache...') await db.insert(contracts).values({ id: `${chainId}:${address}`, name: contract.name, @@ -122,7 +128,7 @@ export const getCachedContractInformation = async ( return contract } catch (e) { consola.error(e) - throw new Error('Contract not found') + throw new Error('Failed to fetch contract information') } } diff --git a/src/routes/diamond/[address]/+page.server.ts b/src/routes/diamond/[address]/+page.server.ts index 60a0f16..fd47753 100644 --- a/src/routes/diamond/[address]/+page.server.ts +++ b/src/routes/diamond/[address]/+page.server.ts @@ -16,6 +16,7 @@ import { chainMap } from '$lib/chains' import { type BunSQLiteDatabase } from 'drizzle-orm/bun-sqlite' import { diamonds } from '../../../schema' import { sql } from 'drizzle-orm' +import consola from 'consola' export const load: PageServerLoad = async ({ params, url, locals }) => { const { address } = params @@ -54,6 +55,7 @@ export const load: PageServerLoad = async ({ params, url, locals }) => { } // Udate the database + consola.info('Updating stats...') await locals.db .insert(diamonds) .values({ diff --git a/src/routes/diamond/[address]/json/+server.ts b/src/routes/diamond/[address]/json/+server.ts index 6958855..f317c99 100644 --- a/src/routes/diamond/[address]/json/+server.ts +++ b/src/routes/diamond/[address]/json/+server.ts @@ -17,10 +17,10 @@ import { } from 'viem' import type { Chain } from 'viem/chains' import { chainMap } from '$lib/chains' -import { drizzle, type BunSQLiteDatabase } from 'drizzle-orm/bun-sqlite' -import { Database } from 'bun:sqlite' +import { type BunSQLiteDatabase } from 'drizzle-orm/bun-sqlite' import { diamonds } from '../../../../schema' import { sql } from 'drizzle-orm' +import consola from 'consola' export const GET: RequestHandler = async ({ params, url, locals }) => { const { address } = params @@ -59,9 +59,8 @@ export const GET: RequestHandler = async ({ params, url, locals }) => { } // Udate the database - const sqlite = new Database('./data/louper.db') - const db = drizzle(sqlite) - await db + consola.info('Updating stats...') + await locals.db .insert(diamonds) .values({ id: `${network}:${address}`, @@ -77,8 +76,6 @@ export const GET: RequestHandler = async ({ params, url, locals }) => { }, }) - sqlite.close() - return json({ chain: network, diamond,