Skip to content

Commit

Permalink
Merge pull request #323 from pimlicolabs/fix-public-client-logs
Browse files Browse the repository at this point in the history
log execution reverted errors as info messages
  • Loading branch information
nikmel2803 authored Oct 11, 2024
2 parents ae33883 + 2b1ade9 commit 06a10e1
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions src/cli/customTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import {
type HttpTransportConfig,
RpcRequestError,
UrlRequiredError,
createTransport
createTransport,
toFunctionSelector,
getAbiItem,
isHex,
slice,
Hex
} from "viem"
import { rpc } from "viem/utils"
import { formatAbiItem, rpc } from "viem/utils"
import { EntryPointV06Abi } from "../types/contracts"

export type RpcRequest = {
jsonrpc?: "2.0" | undefined
Expand All @@ -15,6 +21,33 @@ export type RpcRequest = {
id?: number | undefined
}

const EXECUTION_RESULT_SELECTOR = toFunctionSelector(
formatAbiItem(
getAbiItem({
abi: EntryPointV06Abi,
name: "ExecutionResult"
})
)
)

const VALIDATION_RESULT_SELECTOR = toFunctionSelector(
formatAbiItem(
getAbiItem({
abi: EntryPointV06Abi,
name: "ValidationResult"
})
)
)

const FAILED_OP_SELECTOR = toFunctionSelector(
formatAbiItem(
getAbiItem({
abi: EntryPointV06Abi,
name: "FailedOp"
})
)
)

export function customTransport(
/** URL of the JSON-RPC API. Defaults to the chain's public RPC URL. */
url_: string,
Expand Down Expand Up @@ -54,13 +87,30 @@ export function customTransport(

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

if (isHex(error?.data) && error?.data?.length > 10) {
const errorSelector = slice(error?.data, 0, 4)

if (
[
EXECUTION_RESULT_SELECTOR,
VALIDATION_RESULT_SELECTOR,
FAILED_OP_SELECTOR
].includes(errorSelector as Hex)
) {
loggerFn = logger.info.bind(logger)
}
}

loggerFn(
{
error,
err: error,
body
},
"Received error response"
"received error response"
)

throw new RpcRequestError({
body,
error: {
Expand All @@ -75,7 +125,7 @@ export function customTransport(
url: url
})
}
logger.info({ body, result }, "Received response")
logger.info({ body, result }, "received response")
return result
},
retryCount,
Expand Down

0 comments on commit 06a10e1

Please sign in to comment.