diff --git a/eth/api.go b/eth/api.go index d1c9fee90a..49e5bfcf67 100644 --- a/eth/api.go +++ b/eth/api.go @@ -698,3 +698,13 @@ func (api *ScrollAPI) GetBlockByHash(ctx context.Context, hash common.Hash, full } return nil, err } + +// GetBlockByNumber returns the requested block. When fullTx is true all transactions in the block are returned in full +// detail, otherwise only the transaction hash is returned. +func (api *ScrollAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) { + block, err := api.eth.APIBackend.BlockByNumber(ctx, number) + if block != nil { + return api.rpcMarshalBlock(ctx, block, fullTx) + } + return nil, err +} diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 5f1f54794f..f46aed9a73 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -357,11 +357,16 @@ func (r *rpcRowConsumption) UnmarshalJSON(input []byte) error { return nil } -// GetBlockByHash returns the requested block. When fullTx is true all transactions in the block are returned in full -// detail, otherwise only the transaction hash is returned. -func (ec *Client) GetBlockByHash(ctx context.Context, blockHash common.Hash) (*types.BlockWithRowConsumption, error) { +// GetBlockByNumberOrHash returns the requested block +func (ec *Client) GetBlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.BlockWithRowConsumption, error) { var raw json.RawMessage - err := ec.c.CallContext(ctx, &raw, "scroll_getBlockByHash", blockHash, true) + var err error + if number, ok := blockNrOrHash.Number(); ok { + err = ec.c.CallContext(ctx, &raw, "scroll_getBlockByNumber", number, true) + } + if hash, ok := blockNrOrHash.Hash(); ok { + err = ec.c.CallContext(ctx, &raw, "scroll_getBlockByHash", hash, true) + } if err != nil { return nil, err } else if len(raw) == 0 { diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 917204409b..7c65cb0f53 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -881,6 +881,12 @@ web3._extend({ params: 2, inputFormatter: [null, function (val) { return !!val; }] }), + new web3._extend.Method({ + name: 'getBlockByNumber', + call: 'scroll_getBlockByNumber', + params: 2, + inputFormatter: [null, function (val) { return !!val; }] + }), ], properties: [ diff --git a/params/version.go b/params/version.go index 0d21d16a2f..e5cc4f104d 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 4 // Major version component of the current release VersionMinor = 3 // Minor version component of the current release - VersionPatch = 2 // Patch version component of the current release + VersionPatch = 3 // Patch version component of the current release VersionMeta = "sepolia" // Version metadata to append to the version string )