Skip to content

Commit

Permalink
add diskRoot() api
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak committed Dec 30, 2024
1 parent 696c949 commit 5127804
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,3 +961,30 @@ func (api *ScrollAPI) CalculateRowConsumptionByBlockNumber(ctx context.Context,
asyncChecker.Wait()
return rawdb.ReadBlockRowConsumption(api.eth.ChainDb(), block.Hash()), checkErr
}

type DiskAndHeaderRoot struct {
DiskRoot common.Hash `json:"diskRoot"`
HeaderRoot common.Hash `json:"headerRoot"`
}

// CalculateRowConsumptionByBlockNumber
func (api *ScrollAPI) DiskRoot(ctx context.Context, blockNrOrHash *rpc.BlockNumberOrHash) (DiskAndHeaderRoot, error) {
block, err := api.eth.APIBackend.BlockByNumberOrHash(ctx, *blockNrOrHash)
if err != nil {
return DiskAndHeaderRoot{}, fmt.Errorf("failed to retrieve block: %w", err)
}
if block == nil {
return DiskAndHeaderRoot{}, fmt.Errorf("block not found: %s", blockNrOrHash.String())
}

if diskRoot, _ := rawdb.ReadDiskStateRoot(api.eth.ChainDb(), block.Root()); diskRoot != (common.Hash{}) {
return DiskAndHeaderRoot{
DiskRoot: diskRoot,
HeaderRoot: block.Root(),
}, nil
}
return DiskAndHeaderRoot{
DiskRoot: block.Root(),
HeaderRoot: block.Root(),
}, nil
}
7 changes: 7 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,13 @@ web3._extend({
params: 1,
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
}),
new web3._extend.Method({
name: 'diskRoot',
call: 'scroll_diskRoot',
params: 1,
inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter],
}),
],
properties:
[
Expand Down

0 comments on commit 5127804

Please sign in to comment.