Skip to content

Commit 5127804

Browse files
committed
add diskRoot() api
1 parent 696c949 commit 5127804

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

eth/api.go

+27
Original file line numberDiff line numberDiff line change
@@ -961,3 +961,30 @@ func (api *ScrollAPI) CalculateRowConsumptionByBlockNumber(ctx context.Context,
961961
asyncChecker.Wait()
962962
return rawdb.ReadBlockRowConsumption(api.eth.ChainDb(), block.Hash()), checkErr
963963
}
964+
965+
type DiskAndHeaderRoot struct {
966+
DiskRoot common.Hash `json:"diskRoot"`
967+
HeaderRoot common.Hash `json:"headerRoot"`
968+
}
969+
970+
// CalculateRowConsumptionByBlockNumber
971+
func (api *ScrollAPI) DiskRoot(ctx context.Context, blockNrOrHash *rpc.BlockNumberOrHash) (DiskAndHeaderRoot, error) {
972+
block, err := api.eth.APIBackend.BlockByNumberOrHash(ctx, *blockNrOrHash)
973+
if err != nil {
974+
return DiskAndHeaderRoot{}, fmt.Errorf("failed to retrieve block: %w", err)
975+
}
976+
if block == nil {
977+
return DiskAndHeaderRoot{}, fmt.Errorf("block not found: %s", blockNrOrHash.String())
978+
}
979+
980+
if diskRoot, _ := rawdb.ReadDiskStateRoot(api.eth.ChainDb(), block.Root()); diskRoot != (common.Hash{}) {
981+
return DiskAndHeaderRoot{
982+
DiskRoot: diskRoot,
983+
HeaderRoot: block.Root(),
984+
}, nil
985+
}
986+
return DiskAndHeaderRoot{
987+
DiskRoot: block.Root(),
988+
HeaderRoot: block.Root(),
989+
}, nil
990+
}

internal/web3ext/web3ext.go

+7
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,13 @@ web3._extend({
949949
params: 1,
950950
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
951951
}),
952+
new web3._extend.Method({
953+
name: 'diskRoot',
954+
call: 'scroll_diskRoot',
955+
params: 1,
956+
inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter],
957+
}),
958+
952959
],
953960
properties:
954961
[

0 commit comments

Comments
 (0)