feat(rpc): add scroll_getBlockByNumber (#413)

* add scroll_getBlockByNumber rpc api

* bump version

* fix

* bump version

* Update version.go

* Revert "Update version.go"

This reverts commit 1be1d9c4fdbb64254659ac193cffd23dbbacfb5e.

---------

Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
Co-authored-by: HAOYUatHZ <haoyu@protonmail.com>
This commit is contained in:
Nazarii Denha 2023-08-01 15:32:12 +02:00 committed by GitHub
parent 22fec5714e
commit 7b75f163b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 5 deletions

View file

@ -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
}

View file

@ -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 {

View file

@ -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:
[

View file

@ -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
)