erigon-pulse/cmd/rpcdaemon/commands/rpc_getBlockNumber.go
Enrique Jose Avila Asapche a5cb53d690
safe and finalized blocks from eth_getBlockByNumber (#4436)
* added getFinalzed and getSafe block num

* added rpc finalized and safe block num

* getting nums

* returning nil

* returning nil

* added to helper.go

* removed repeated code

* added functions into rpchelper

* returning err

* simplified

* using previous latest getter

* getting pending block with filter/

* Fix plain state block number

* Fix test

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-06-14 11:07:46 +03:00

42 lines
871 B
Go

package commands
import (
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/rpc"
"github.com/ledgerwatch/erigon/turbo/rpchelper"
)
func getBlockNumber(number rpc.BlockNumber, tx kv.Tx, filters *rpchelper.Filters) (uint64, error) {
var blockNum uint64
latest, err := rpchelper.GetLatestBlockNumber(tx)
if err != nil {
return 0, err
}
switch number {
case rpc.LatestBlockNumber:
return latest, nil
case rpc.PendingBlockNumber:
pendingBlock := filters.LastPendingBlock()
if pendingBlock == nil {
return latest, nil
}
return pendingBlock.NumberU64(), nil
case rpc.EarliestBlockNumber:
blockNum = 0
case rpc.FinalizeBlockNumber:
return rpchelper.GetFinalizedBlockNumber(tx)
case rpc.SafeBlockNumber:
return rpchelper.GetSafeBlockNumber(tx)
default:
blockNum = uint64(number.Int64())
}
return blockNum, nil
}