Skip to content

Commit 17f7f88

Browse files
committed
Code formating
1 parent 05f4d82 commit 17f7f88

File tree

6 files changed

+46
-35
lines changed

6 files changed

+46
-35
lines changed

packages/transaction-decoder/src/sql/abi-store.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,19 @@ export const make = (strategies: AbiStore.AbiStore['strategies']) =>
105105
)`.pipe(Effect.tapError((error) => Effect.logError(`Failed to create v3 table during migration: ${error}`)))
106106

107107
// Check if v2 table exists before attempting migration
108-
const v2TableExists = yield* q.onDialectOrElse({
109-
sqlite: () => q`SELECT name FROM sqlite_master WHERE type='table' AND name='_loop_decoder_contract_abi_v2'`,
110-
pg: () => q`SELECT tablename FROM pg_tables WHERE tablename='_loop_decoder_contract_abi_v2'`,
111-
mysql: () => q`SELECT table_name FROM information_schema.tables WHERE table_name='_loop_decoder_contract_abi_v2'`,
112-
orElse: () => q`SELECT COUNT(*) as count FROM ${tableV2} WHERE 1=0`, // Try to query table directly
113-
}).pipe(
114-
Effect.map((rows) => rows.length > 0),
115-
Effect.catchAll(() => Effect.succeed(false)),
116-
)
108+
const v2TableExists = yield* q
109+
.onDialectOrElse({
110+
sqlite: () =>
111+
q`SELECT name FROM sqlite_master WHERE type='table' AND name='_loop_decoder_contract_abi_v2'`,
112+
pg: () => q`SELECT tablename FROM pg_tables WHERE tablename='_loop_decoder_contract_abi_v2'`,
113+
mysql: () =>
114+
q`SELECT table_name FROM information_schema.tables WHERE table_name='_loop_decoder_contract_abi_v2'`,
115+
orElse: () => q`SELECT COUNT(*) as count FROM ${tableV2} WHERE 1=0`, // Try to query table directly
116+
})
117+
.pipe(
118+
Effect.map((rows) => rows.length > 0),
119+
Effect.catchAll(() => Effect.succeed(false)),
120+
)
117121

118122
if (!v2TableExists) {
119123
yield* Effect.logInfo('No v2 table found, skipping data migration')
@@ -172,9 +176,7 @@ export const make = (strategies: AbiStore.AbiStore['strategies']) =>
172176
)
173177
`.pipe(
174178
Effect.tap(() => Effect.logInfo('Successfully migrated ABIs from v2 to v3 table with preserved IDs')),
175-
Effect.tapError((error) =>
176-
Effect.logError(`Failed to migrate ABIs from v2 to v3 table: ${error}`)
177-
)
179+
Effect.tapError((error) => Effect.logError(`Failed to migrate ABIs from v2 to v3 table: ${error}`)),
178180
)
179181
}),
180182
),
@@ -218,8 +220,10 @@ export const make = (strategies: AbiStore.AbiStore['strategies']) =>
218220
}).pipe(
219221
Effect.tapError((error) =>
220222
Effect.logError(
221-
`Failed to insert ABI into database for ${abi.type} key (address: ${key.address}, chainID: ${key.chainID
222-
}). ABI status: ${abi.status}, ABI length: ${abi.abi?.length || 'null'}, source: ${abi.source || 'unknown'
223+
`Failed to insert ABI into database for ${abi.type} key (address: ${key.address}, chainID: ${
224+
key.chainID
225+
}). ABI status: ${abi.status}, ABI length: ${abi.abi?.length || 'null'}, source: ${
226+
abi.source || 'unknown'
223227
}. Error: ${error}`,
224228
),
225229
),
@@ -235,7 +239,8 @@ export const make = (strategies: AbiStore.AbiStore['strategies']) =>
235239
const items = yield* sql` SELECT * FROM ${table} WHERE ${query}`.pipe(
236240
Effect.tapError((error) =>
237241
Effect.logError(
238-
`Failed to query ABI from database for key (address: ${address}, signature: ${signature || 'none'
242+
`Failed to query ABI from database for key (address: ${address}, signature: ${
243+
signature || 'none'
239244
}, event: ${event || 'none'}, chainID: ${chainID}): ${error}`,
240245
),
241246
),

packages/transaction-decoder/src/sql/migrations.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Effect } from 'effect'
2-
import { SqlClient } from '@effect/sql'
2+
import { SqlClient, type SqlError } from '@effect/sql'
33

44
// _loop_decoder_migrations (
55
// id TEXT PRIMARY KEY, -- usually a timestamped name like 001_init
@@ -8,7 +8,7 @@ import { SqlClient } from '@effect/sql'
88

99
export type Migration = {
1010
id: string
11-
up: (sql: SqlClient.SqlClient) => Effect.Effect<void, unknown, unknown>
11+
up: (sql: SqlClient.SqlClient) => Effect.Effect<void, SqlError.SqlError, never>
1212
}
1313

1414
const MIGRATIONS_TABLE = '_loop_decoder_migrations'
@@ -45,24 +45,24 @@ export const runMigrations = (migrations: readonly Migration[]) =>
4545

4646
// compute latest applied (lexicographic order). Expect zero-padded ids like 001_...
4747
const latest = yield* getLatestAppliedMigration(sql).pipe(
48-
Effect.tapError((error) =>
49-
Effect.logError(`Migration failed: ${error}`)
50-
),
48+
Effect.tapError((error) => Effect.logError(`Migration failed: ${error}`)),
5149
)
5250

5351
// filter only migrations with id greater than latest
5452
const pending = latest == null ? migrations : migrations.filter((m) => m.id > latest)
5553

56-
yield* Effect.forEach(pending, (m) =>
57-
Effect.gen(function* () {
58-
// First run the migration
59-
yield* m.up(sql)
54+
yield* Effect.forEach(
55+
pending,
56+
(m) =>
57+
Effect.gen(function* () {
58+
// First run the migration
59+
yield* m.up(sql)
6060

61-
// Only mark as applied if migration succeeded
62-
const table = sql(MIGRATIONS_TABLE)
63-
yield* sql`INSERT INTO ${table} (id) VALUES (${m.id})`
64-
}),
65-
{ discard: true }
61+
// Only mark as applied if migration succeeded
62+
const table = sql(MIGRATIONS_TABLE)
63+
yield* sql`INSERT INTO ${table} (id) VALUES (${m.id})`
64+
}),
65+
{ discard: true },
6666
)
6767
})
6868
// Helpers to define migrations succinctly

packages/transaction-decoder/test/mocks/abi-loader-mock.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ export const MockedAbiStoreLive = AbiStore.layer({
4545
const addressExists = yield* Effect.sync(() => fs.existsSync(`./test/mocks/abi/${address.toLowerCase()}.json`))
4646

4747
if (addressExists) {
48-
const abi = yield* Effect.sync(
49-
() => fs.readFileSync(`./test/mocks/abi/${address.toLowerCase()}.json`)?.toString(),
48+
const abi = yield* Effect.sync(() =>
49+
fs.readFileSync(`./test/mocks/abi/${address.toLowerCase()}.json`)?.toString(),
5050
)
5151

5252
results.push({
53+
id: `${address.toLowerCase()}-address`,
5354
type: 'address',
5455
abi,
5556
address,
@@ -64,12 +65,13 @@ export const MockedAbiStoreLive = AbiStore.layer({
6465
const signatureExists = yield* Effect.sync(() => fs.existsSync(`./test/mocks/abi/${sig.toLowerCase()}.json`))
6566

6667
if (signatureExists) {
67-
const signatureAbi = yield* Effect.sync(
68-
() => fs.readFileSync(`./test/mocks/abi/${sig.toLowerCase()}.json`)?.toString(),
68+
const signatureAbi = yield* Effect.sync(() =>
69+
fs.readFileSync(`./test/mocks/abi/${sig.toLowerCase()}.json`)?.toString(),
6970
)
7071

7172
if (signature) {
7273
results.push({
74+
id: `${address.toLowerCase()}-${signature.toLowerCase()}-func`,
7375
type: 'func',
7476
abi: signatureAbi,
7577
address,
@@ -79,6 +81,7 @@ export const MockedAbiStoreLive = AbiStore.layer({
7981
})
8082
} else if (event) {
8183
results.push({
84+
id: `${address.toLowerCase()}-${event.toLowerCase()}-event`,
8285
type: 'event',
8386
abi: signatureAbi,
8487
address,

packages/transaction-decoder/test/vanilla.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('Transaction Decoder', () => {
2828
if (addressExists) {
2929
return [
3030
{
31+
id: `${address.toLowerCase()}-address`,
3132
type: 'address',
3233
abi: fs.readFileSync(`./test/mocks/abi/${address.toLowerCase()}.json`)?.toString(),
3334
address,
@@ -44,6 +45,7 @@ describe('Transaction Decoder', () => {
4445
if (signature) {
4546
return [
4647
{
48+
id: `${address.toLowerCase()}-${signature.toLowerCase()}-func`,
4749
type: 'func',
4850
abi: signatureAbi,
4951
address,
@@ -55,6 +57,7 @@ describe('Transaction Decoder', () => {
5557
} else if (event) {
5658
return [
5759
{
60+
id: `${address.toLowerCase()}-${event.toLowerCase()}-event`,
5861
type: 'event',
5962
abi: signatureAbi,
6063
address,

packages/transaction-decoder/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path'
1+
import * as path from 'path'
22
import { globSync } from 'glob'
33
import { defineConfig } from 'tsup'
44

packages/transaction-interpreter/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path'
1+
import * as path from 'path'
22
import { defineConfig } from 'tsup'
33

44
export default defineConfig({

0 commit comments

Comments
 (0)