Skip to content

Commit

Permalink
Add ability to disable trace and decode only based on receipt and logs (
Browse files Browse the repository at this point in the history
#101)

* Add ability to disable trace and decode only based on receipt and logs

* Update the usage of supportTraceAPI in docs and web playground
  • Loading branch information
Ferossgp authored Sep 10, 2024
1 parent 26ffe1f commit 1e074ac
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-books-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@3loop/transaction-decoder': minor
---

Allow disabling tracer for an RPC client thus relaying only on logs and receipt
4 changes: 2 additions & 2 deletions apps/docs/src/content/docs/recipes/fc-bot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The `constants.ts` file contains the RPC URL and configuration. The Base RPCs do
export const RPC = {
8453: {
url: `wss://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`,
supportTraceAPI: false,
traceAPI: 'none',
},
}
```
Expand All @@ -95,7 +95,7 @@ const getPublicClient = (chainId: number) => {
transport: webSocket(rpc.url),
}),
config: {
supportTraceAPI: rpc.supportTraceAPI,
traceAPI: rpc.traceAPI,
},
}
}
Expand Down
18 changes: 12 additions & 6 deletions apps/web/src/app/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ export const EXAMPLE_TXS = {
],
}

export const supportedChains = [
export const supportedChains: {
name: string
chainID: number
rpcUrl: string
traceAPI?: 'parity' | 'geth' | 'none'
batchMaxCount?: number
}[] = [
{
name: 'Ethereum Mainnet',
chainID: 1,
Expand All @@ -100,32 +106,32 @@ export const supportedChains = [
name: 'Base mainnet',
chainID: 8453,
rpcUrl: process.env.BASE_RPC_URL as string,
supportTraceAPI: false,
traceAPI: 'geth',
batchMaxCount: 1,
},
{
name: 'Polygon Mainnet',
chainID: 137,
rpcUrl: (process.env.POLYGON_RPC_URL as string) ?? 'https://rpc.ankr.com/polygon',
suppurtTraceAPI: true,
traceAPI: 'geth',
},
{
name: 'Optimism Mainnet',
chainID: 10,
rpcUrl: process.env.OPTIMISM_RPC_URL as string,
supportTraceAPI: false,
traceAPI: 'geth',
},
{
name: 'Arbitrum One',
chainID: 42161,
rpcUrl: process.env.ARBITRUM_RPC_URL as string,
supportTraceAPI: false,
traceAPI: 'geth',
},
{
name: 'Manta pacific',
chainID: 169,
rpcUrl: (process.env.MANTA_RPC_URL as string) ?? 'https://pacific-rpc.manta.network/http',
supportTraceAPI: false,
traceAPI: 'geth',
},
]

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function getProvider(chainID: number): PublicClientObject | null {
transport: http(url),
}),
config: {
supportTraceAPI: providerConfigs[chainID]?.supportTraceAPI,
traceAPI: providerConfigs[chainID]?.traceAPI,
},
}

Expand Down
2 changes: 1 addition & 1 deletion packages/transaction-decoder/src/public-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class RPCFetchError {
}

export interface PublicClientConfig {
readonly supportTraceAPI?: boolean
readonly traceAPI?: 'parity' | 'geth' | 'none'
}

export interface PublicClientObject {
Expand Down
14 changes: 8 additions & 6 deletions packages/transaction-decoder/src/transaction-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export const getTransactionReceipt = (hash: Hash, chainID: number) =>
export const getTrace = (hash: Hash, chainID: number) =>
Effect.gen(function* () {
const service = yield* PublicClient
const { client, config } = yield* service.getPublicClient(chainID)
const traceAPISupport = config?.supportTraceAPI ?? true
const { client, config = {} } = yield* service.getPublicClient(chainID)
const traceAPI = config.traceAPI ?? 'parity'

if (traceAPISupport) {
if (traceAPI === 'parity') {
const trace = yield* Effect.withSpan(
Effect.tryPromise({
try: async () => {
Expand All @@ -60,7 +60,7 @@ export const getTrace = (hash: Hash, chainID: number) =>
catch: () => new RPCFetchError('Get trace'),
}),
'TransactionLoader.Trace',
{ attributes: { hash, chainID, traceAPISupport } },
{ attributes: { hash, chainID, traceAPI } },
)

const effects: Effect.Effect<TraceLog, ParseError>[] = trace.map((log: string) => {
Expand All @@ -73,7 +73,7 @@ export const getTrace = (hash: Hash, chainID: number) =>
})

return results
} else {
} else if (traceAPI === 'geth') {
const trace = yield* Effect.withSpan(
Effect.tryPromise({
try: async () => {
Expand All @@ -87,13 +87,15 @@ export const getTrace = (hash: Hash, chainID: number) =>
catch: (e) => new RPCFetchError(e),
}),
'TransactionLoader.Trace',
{ attributes: { hash, chainID, traceAPISupport } },
{ attributes: { hash, chainID, traceAPI } },
)

const transformedTrace = transformTraceTree(trace as unknown as TraceLogTree)

return transformedTrace
}

return []
})

export const getBlockTimestamp = (blockNumber: bigint, chainID: number) =>
Expand Down

0 comments on commit 1e074ac

Please sign in to comment.