diff --git a/internal/utils/configfile.go b/internal/utils/configfile.go index 036f50358..6beb393f1 100644 --- a/internal/utils/configfile.go +++ b/internal/utils/configfile.go @@ -5,13 +5,16 @@ import ( "fmt" "strings" + "gopkg.in/ini.v1" + + "github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/p2p" - ini "gopkg.in/ini.v1" ) // WalletProfile contains a section and key value pair map type WalletProfile struct { Profile string + ChainID string Bootnodes []string Shards int RPCServer [][]p2p.Peer @@ -37,6 +40,17 @@ func ReadWalletProfile(iniBytes []byte, profile string) (*WalletProfile, error) } else { return nil, fmt.Errorf("can't find bootnode key") } + if sec.HasKey("chain_id") { + config.ChainID = sec.Key("chain_id").String() + } else { + // backward compatibility; use profile name to determine + switch strings.ToLower(strings.TrimSpace(profile)) { + case "main", "default": + config.ChainID = params.MainnetChainID.String() + default: + config.ChainID = params.TestnetChainID.String() + } + } if sec.HasKey("shards") { config.Shards = sec.Key("shards").MustInt() diff --git a/internal/utils/configfile_test.go b/internal/utils/configfile_test.go index 2e7a08d67..081fc1c93 100644 --- a/internal/utils/configfile_test.go +++ b/internal/utils/configfile_test.go @@ -5,6 +5,7 @@ import ( "reflect" "testing" + "github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/p2p" ) @@ -12,6 +13,7 @@ func TestReadWalletProfile(t *testing.T) { config := []*WalletProfile{ { Profile: "default", + ChainID: params.MainnetChainID.String(), Bootnodes: []string{"127.0.0.1:9000/abcd", "127.0.0.1:9999/daeg"}, Shards: 4, RPCServer: [][]p2p.Peer{ @@ -59,6 +61,7 @@ func TestReadWalletProfile(t *testing.T) { }, { Profile: "testnet", + ChainID: params.TestnetChainID.String(), Bootnodes: []string{"192.168.0.1:9990/abcd", "127.0.0.1:8888/daeg"}, Shards: 3, RPCServer: [][]p2p.Peer{