add eth_chainId JSON-RPC endpoint
This commit is contained in:
parent
9d590e15bc
commit
f8b9d9475e
@ -167,6 +167,19 @@ func (pea *PublicEthAPI) GetBlockByHash(ctx context.Context, hash common.Hash, f
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
|
||||||
|
func (api *PublicEthAPI) ChainId() (hexutil.Uint64, error) {
|
||||||
|
chainID := new(big.Int)
|
||||||
|
block, err := api.B.CurrentBlock()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if config := api.B.Config.ChainConfig; config.IsEIP155(block.Number()) {
|
||||||
|
chainID = config.ChainID
|
||||||
|
}
|
||||||
|
return (hexutil.Uint64)(chainID.Uint64()), nil
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Uncles
|
Uncles
|
||||||
|
@ -202,9 +202,9 @@ func (b *Backend) GetTd(blockHash common.Hash) (*big.Int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CurrentBlock returns the current block
|
// CurrentBlock returns the current block
|
||||||
func (b *Backend) CurrentBlock() *types.Block {
|
func (b *Backend) CurrentBlock() (*types.Block, error) {
|
||||||
block, _ := b.BlockByNumber(context.Background(), rpc.LatestBlockNumber)
|
block, err := b.BlockByNumber(context.Background(), rpc.LatestBlockNumber)
|
||||||
return block
|
return block, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockByNumberOrHash returns block by number or hash
|
// BlockByNumberOrHash returns block by number or hash
|
||||||
|
@ -867,7 +867,11 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
|
|||||||
if args.To != nil {
|
if args.To != nil {
|
||||||
to = rpc.BlockNumber(*args.To)
|
to = rpc.BlockNumber(*args.To)
|
||||||
} else {
|
} else {
|
||||||
to = rpc.BlockNumber(r.backend.CurrentBlock().Number().Int64())
|
block, err := r.backend.CurrentBlock()
|
||||||
|
if err != nil {
|
||||||
|
return []*Block{}, nil
|
||||||
|
}
|
||||||
|
to = rpc.BlockNumber(block.Number().Int64())
|
||||||
}
|
}
|
||||||
if to < from {
|
if to < from {
|
||||||
return []*Block{}, nil
|
return []*Block{}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user