2020-09-03 07:51:19 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages"
|
2020-11-22 21:25:26 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
2020-09-03 07:51:19 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/rpc"
|
|
|
|
)
|
|
|
|
|
2020-11-22 21:25:26 +00:00
|
|
|
func getBlockNumber(number rpc.BlockNumber, dbReader ethdb.Getter) (uint64, error) {
|
2020-09-03 07:51:19 +00:00
|
|
|
var blockNum uint64
|
|
|
|
var err error
|
|
|
|
if number == rpc.LatestBlockNumber || number == rpc.PendingBlockNumber {
|
|
|
|
blockNum, err = getLatestBlockNumber(dbReader)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
} else if number == rpc.EarliestBlockNumber {
|
|
|
|
blockNum = 0
|
|
|
|
} else {
|
|
|
|
blockNum = uint64(number.Int64())
|
|
|
|
}
|
|
|
|
|
|
|
|
return blockNum, nil
|
|
|
|
}
|
|
|
|
|
2020-11-22 21:25:26 +00:00
|
|
|
func getLatestBlockNumber(dbReader ethdb.Getter) (uint64, error) {
|
2020-12-21 11:01:37 +00:00
|
|
|
blockNum, err := stages.GetStageProgress(dbReader, stages.Execution)
|
2020-09-03 07:51:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, fmt.Errorf("getting latest block number: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return blockNum, nil
|
|
|
|
}
|