@@ -387,6 +387,7 @@ func (b *BlockChainAPI) GetBlockByHash(
387387// - When blockNr is -2 the chain latest block is returned.
388388// - When blockNr is -3 the chain finalized block is returned.
389389// - When blockNr is -4 the chain safe block is returned.
390+ // - When blockNr is -5 the chain earliest block is returned.
390391// - When fullTx is true all transactions in the block are returned, otherwise
391392// only the transaction hash is returned.
392393func (b * BlockChainAPI ) GetBlockByNumber (
@@ -405,7 +406,9 @@ func (b *BlockChainAPI) GetBlockByNumber(
405406
406407 height := uint64 (blockNumber )
407408 var err error
408- if blockNumber < 0 {
409+ if blockNumber == rpc .EarliestBlockNumber {
410+ height = 0
411+ } else if blockNumber <= rpc .PendingBlockNumber {
409412 height , err = b .blocks .LatestEVMHeight ()
410413 if err != nil {
411414 return handleError [* ethTypes.Block ](err , l , b .collector )
@@ -510,15 +513,18 @@ func (b *BlockChainAPI) GetBlockTransactionCountByNumber(
510513 return nil , err
511514 }
512515
513- if blockNumber < rpc .EarliestBlockNumber {
514- latestBlockNumber , err := b .blocks .LatestEVMHeight ()
516+ height := uint64 (blockNumber )
517+ var err error
518+ if blockNumber == rpc .EarliestBlockNumber {
519+ height = 0
520+ } else if blockNumber <= rpc .PendingBlockNumber {
521+ height , err = b .blocks .LatestEVMHeight ()
515522 if err != nil {
516523 return handleError [* hexutil.Uint ](err , l , b .collector )
517524 }
518- blockNumber = rpc .BlockNumber (latestBlockNumber )
519525 }
520526
521- block , err := b .blocks .GetByHeight (uint64 ( blockNumber ) )
527+ block , err := b .blocks .GetByHeight (height )
522528 if err != nil {
523529 return handleError [* hexutil.Uint ](err , l , b .collector )
524530 }
@@ -638,10 +644,15 @@ func (b *BlockChainAPI) GetLogs(
638644 latest := big .NewInt (int64 (h ))
639645
640646 // if special value, use latest block number
641- if from .Cmp (models .EarliestBlockNumber ) < 0 {
647+ if from .Cmp (models .EarliestBlockNumber ) == 0 {
648+ from = big .NewInt (0 )
649+ } else if from .Cmp (models .PendingBlockNumber ) < 0 {
642650 from = latest
643651 }
644- if to .Cmp (models .EarliestBlockNumber ) < 0 {
652+
653+ if to .Cmp (models .EarliestBlockNumber ) == 0 {
654+ to = big .NewInt (0 )
655+ } else if to .Cmp (models .PendingBlockNumber ) < 0 {
645656 to = latest
646657 }
647658
0 commit comments