From 92c011a114e4db657c18a02e356147fceb86f0a5 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 2 Dec 2019 13:28:23 -0800 Subject: [PATCH] =?UTF-8?q?Factor=20out=20network=20type=20=E2=87=92=20cha?= =?UTF-8?q?in=20config=20lookup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node/node.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/node/node.go b/node/node.go index 1e3aee129..c24a6c924 100644 --- a/node/node.go +++ b/node/node.go @@ -407,13 +407,8 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, node.SelfPeer = host.GetSelfPeer() } - chainConfig := *params.TestnetChainConfig - switch node.NodeConfig.GetNetworkType() { - case nodeconfig.Mainnet: - chainConfig = *params.MainnetChainConfig - case nodeconfig.Pangaea: - chainConfig = *params.PangaeaChainConfig - } + networkType := node.NodeConfig.GetNetworkType() + chainConfig := ChainConfigForNetworkType(networkType) node.chainConfig = chainConfig collection := shardchain.NewCollection( @@ -457,7 +452,7 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, node.Consensus.SetBlockNum(blockchain.CurrentBlock().NumberU64() + 1) // 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 { // Setup one time smart contracts node.AddFaucetContractToPendingTransactions() @@ -488,6 +483,17 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, 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 // keys for consensus and drand func (node *Node) InitConsensusWithValidators() (err error) {