Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add raw body & response to logs #420

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/cli/customTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ import {
getAbiItem,
isHex,
slice,
Hex
type Hex
} from "viem"
import { formatAbiItem, rpc } from "viem/utils"
import { formatAbiItem, getHttpRpcClient } from "viem/utils"
import {
EntryPointV06Abi,
EntryPointV06SimulationsAbi
} from "../types/contracts"

export type RpcRequest = {
jsonrpc?: "2.0" | undefined
method: string
params?: any | undefined
id?: number | undefined
}
import type { RpcResponse, RpcRequest } from "viem/types/rpc"

const EXECUTION_RESULT_SELECTOR = toFunctionSelector(
formatAbiItem(
Expand Down Expand Up @@ -87,18 +81,23 @@ export function customTransport(
key,
name,
async request({ method, params }) {
const body = { method, params }
const fn = async (body: RpcRequest) => {
return [
await rpc.http(url, {
body,
fetchOptions,
timeout
})
]
}
let body: RpcRequest = { method, params }
let rawResponse: RpcResponse | undefined = undefined

const { error, result } = await getHttpRpcClient(
url
).request({
body: body,
fetchOptions,
timeout,
onRequest: async (request) => {
body = await request.clone().json()
},
onResponse: async (response) => {
rawResponse = await response.clone().json()
}
})

const [{ error, result }] = await fn(body)
if (error) {
let loggerFn = logger.error.bind(logger)

Expand All @@ -120,6 +119,7 @@ export function customTransport(
loggerFn(
{
err: error,
rawResponse: rawResponse ?? {},
body
},
"received error response"
Expand Down
Loading