Skip to content

Commit

Permalink
skip sending log if revert comes from simulations
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Oct 10, 2024
1 parent 59feee4 commit 4d3f7f8
Showing 1 changed file with 60 additions and 9 deletions.
69 changes: 60 additions & 9 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 @@ -60,13 +93,31 @@ export function customTransport(
loggerFn = logger.info
}

loggerFn(
{
error,
body
},
"received error response"
)
let shouldSkipLog = false

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

if (
[
EXECUTION_RESULT_SELECTOR,
VALIDATION_RESULT_SELECTOR,
FAILED_OP_SELECTOR
].includes(errorSelector as Hex)
) {
shouldSkipLog = true
}
}

if (!shouldSkipLog) {
loggerFn(
{
error,
body
},
"received error response"
)
}

throw new RpcRequestError({
body,
Expand Down

0 comments on commit 4d3f7f8

Please sign in to comment.