Factor out network type ⇒ chain config lookup

pull/1939/head
Eugene Kim 5 years ago
parent 311091e7c5
commit 92c011a114
  1. 22
      node/node.go

@ -407,13 +407,8 @@ func New(host p2p.Host, consensusObj *consensus.Consensus,
node.SelfPeer = host.GetSelfPeer() node.SelfPeer = host.GetSelfPeer()
} }
chainConfig := *params.TestnetChainConfig networkType := node.NodeConfig.GetNetworkType()
switch node.NodeConfig.GetNetworkType() { chainConfig := ChainConfigForNetworkType(networkType)
case nodeconfig.Mainnet:
chainConfig = *params.MainnetChainConfig
case nodeconfig.Pangaea:
chainConfig = *params.PangaeaChainConfig
}
node.chainConfig = chainConfig node.chainConfig = chainConfig
collection := shardchain.NewCollection( collection := shardchain.NewCollection(
@ -457,7 +452,7 @@ func New(host p2p.Host, consensusObj *consensus.Consensus,
node.Consensus.SetBlockNum(blockchain.CurrentBlock().NumberU64() + 1) node.Consensus.SetBlockNum(blockchain.CurrentBlock().NumberU64() + 1)
// Add Faucet contract to all shards, so that on testnet, we can demo wallet in explorer // Add Faucet contract to all shards, so that on testnet, we can demo wallet in explorer
if node.NodeConfig.GetNetworkType() != nodeconfig.Mainnet { if networkType != nodeconfig.Mainnet {
if node.isFirstTime { if node.isFirstTime {
// Setup one time smart contracts // Setup one time smart contracts
node.AddFaucetContractToPendingTransactions() node.AddFaucetContractToPendingTransactions()
@ -488,6 +483,17 @@ func New(host p2p.Host, consensusObj *consensus.Consensus,
return &node return &node
} }
func ChainConfigForNetworkType(t nodeconfig.NetworkType) params.ChainConfig {
switch t {
case nodeconfig.Mainnet:
return *params.MainnetChainConfig
case nodeconfig.Pangaea:
return *params.PangaeaChainConfig
default:
return *params.TestnetChainConfig
}
}
// InitConsensusWithValidators initialize shard state from latest epoch and update committee pub // InitConsensusWithValidators initialize shard state from latest epoch and update committee pub
// keys for consensus and drand // keys for consensus and drand
func (node *Node) InitConsensusWithValidators() (err error) { func (node *Node) InitConsensusWithValidators() (err error) {

Loading…
Cancel
Save