mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 13:40:05 +00:00
a5cb53d690
* 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>
42 lines
871 B
Go
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
|
|
}
|