mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
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:
parent
22fec5714e
commit
7b75f163b0
4 changed files with 26 additions and 5 deletions
10
eth/api.go
10
eth/api.go
|
|
@ -698,3 +698,13 @@ func (api *ScrollAPI) GetBlockByHash(ctx context.Context, hash common.Hash, full
|
||||||
}
|
}
|
||||||
return nil, err
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -357,11 +357,16 @@ func (r *rpcRowConsumption) UnmarshalJSON(input []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockByHash returns the requested block. When fullTx is true all transactions in the block are returned in full
|
// GetBlockByNumberOrHash returns the requested block
|
||||||
// detail, otherwise only the transaction hash is returned.
|
func (ec *Client) GetBlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.BlockWithRowConsumption, error) {
|
||||||
func (ec *Client) GetBlockByHash(ctx context.Context, blockHash common.Hash) (*types.BlockWithRowConsumption, error) {
|
|
||||||
var raw json.RawMessage
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if len(raw) == 0 {
|
} else if len(raw) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -881,6 +881,12 @@ web3._extend({
|
||||||
params: 2,
|
params: 2,
|
||||||
inputFormatter: [null, function (val) { return !!val; }]
|
inputFormatter: [null, function (val) { return !!val; }]
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'getBlockByNumber',
|
||||||
|
call: 'scroll_getBlockByNumber',
|
||||||
|
params: 2,
|
||||||
|
inputFormatter: [null, function (val) { return !!val; }]
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
properties:
|
properties:
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 4 // Major version component of the current release
|
VersionMajor = 4 // Major version component of the current release
|
||||||
VersionMinor = 3 // Minor 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
|
VersionMeta = "sepolia" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue