erigon-pulse/cmd/rpcdaemon/commands/get_chain_config.go
Alex Sharov 77a4b3305d
rawdb to return errors: part 1 (#1286)
* ReadBlockByNumber and ReadChainConfig return error

* Let's make rawdb package to return error. But by small steps.
High-level methods need to move first:

ReadBlockByNumber
ReadChainConfig
ReadBlockByHash
ReadHeaderByHash
WriteChainConfig
WriteDatabaseVersion
WriteBlock
DeleteTd
WriteTd
ReadTd
2020-10-24 07:57:09 +01:00

26 lines
675 B
Go

package commands
import (
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/core/rawdb"
"github.com/ledgerwatch/turbo-geth/params"
)
func getChainConfig(db rawdb.DatabaseReader) (*params.ChainConfig, error) {
cfg, _, err := getChainConfigWithGenesis(db)
return cfg, err
}
func getChainConfigWithGenesis(db rawdb.DatabaseReader) (*params.ChainConfig, common.Hash, error) {
genesis, err := rawdb.ReadBlockByNumber(db, 0)
if err != nil {
return nil, common.Hash{}, err
}
genesisHash := genesis.Hash()
cc, err := rawdb.ReadChainConfig(db, genesisHash)
if err != nil {
return nil, common.Hash{}, err
}
return cc, genesisHash, nil
}