Make wallet config support chain_id

pull/1627/head
Eugene Kim 5 years ago
parent 63af4767a1
commit f35664b448
  1. 16
      internal/utils/configfile.go
  2. 3
      internal/utils/configfile_test.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()

@ -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{

Loading…
Cancel
Save