Skip to content

Commit 9f200c6

Browse files
committed
debug_traceBlockByHash
1 parent 0128f63 commit 9f200c6

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

api/coreservice.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ type (
192192
BlobSidecarsByHeight(height uint64) ([]*apitypes.BlobSidecarResult, error)
193193
// TraceBlockByNumber returns the trace result of a block by its height
194194
TraceBlockByNumber(ctx context.Context, height uint64, config *tracers.TraceConfig) ([][]byte, []*action.Receipt, any, error)
195+
// TraceBlockByHash returns the trace result of a block by its hash
196+
TraceBlockByHash(ctx context.Context, blkHash string, config *tracers.TraceConfig) ([][]byte, []*action.Receipt, any, error)
195197

196198
// Historical methods
197199
BalanceAt(ctx context.Context, addr address.Address, height uint64) (string, error)
@@ -2149,6 +2151,18 @@ func (core *coreService) TraceBlockByNumber(ctx context.Context, height uint64,
21492151
return core.traceBlock(ctx, blk, config)
21502152
}
21512153

2154+
func (core *coreService) TraceBlockByHash(ctx context.Context, blkHash string, config *tracers.TraceConfig) ([][]byte, []*action.Receipt, any, error) {
2155+
h, err := hash.HexStringToHash256(util.Remove0xPrefix(blkHash))
2156+
if err != nil {
2157+
return nil, nil, nil, err
2158+
}
2159+
blk, err := core.dao.GetBlock(h)
2160+
if err != nil {
2161+
return nil, nil, nil, err
2162+
}
2163+
return core.traceBlock(ctx, blk, config)
2164+
}
2165+
21522166
// Track tracks the api call
21532167
func (core *coreService) Track(ctx context.Context, start time.Time, method string, size int64, success bool) {
21542168
if core.apiStats == nil {

api/mock_apicoreservice.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/web3server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ func (svr *web3Handler) handleWeb3Req(ctx context.Context, web3Req *gjson.Result
260260
res, err = svr.traceCall(ctx, web3Req)
261261
case "debug_traceBlockByNumber":
262262
res, err = svr.traceBlockByNumber(ctx, web3Req)
263+
case "debug_traceBlockByHash":
264+
res, err = svr.traceBlockByHash(ctx, web3Req)
263265
case "eth_coinbase", "eth_getUncleCountByBlockHash", "eth_getUncleCountByBlockNumber",
264266
"eth_sign", "eth_signTransaction", "eth_sendTransaction", "eth_getUncleByBlockHashAndIndex",
265267
"eth_getUncleByBlockNumberAndIndex", "eth_pendingTransactions":
@@ -1184,6 +1186,13 @@ func (svr *web3Handler) traceBlockByNumber(ctx context.Context, in *gjson.Result
11841186
return results, err
11851187
}
11861188

1189+
func (svr *web3Handler) traceBlockByHash(ctx context.Context, in *gjson.Result) (any, error) {
1190+
blkParam, tracerParam := in.Get("params.0"), in.Get("params.1")
1191+
tracer := parseTracerConfig(&tracerParam)
1192+
_, _, results, err := svr.coreService.TraceBlockByHash(ctx, blkParam.String(), tracer)
1193+
return results, err
1194+
}
1195+
11871196
func (svr *web3Handler) unimplemented() (interface{}, error) {
11881197
return nil, errNotImplemented
11891198
}

0 commit comments

Comments
 (0)