Skip to content

Commit

Permalink
addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
holisticode committed Oct 25, 2022
1 parent 051b33f commit 0ab1f7d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
12 changes: 6 additions & 6 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var (
// populate default network config from embedded default directory
func init() {
// load genesis, updating validation start time
genesisMap, err := utils.LoadGenesisMap()
genesisMap, err := utils.LoadLocalGenesis()
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func init() {
}

// load network flags
flagsBytes, err := os.ReadFile(filepath.Join(constants.LocalConfigDir, "flags.json"))
flagsBytes, err := os.ReadFile(filepath.Join("..", constants.LocalConfigDir, "flags.json"))
if err != nil {
panic(err)
}
Expand All @@ -165,7 +165,7 @@ func init() {
}

// load chain config
cChainConfig, err := os.ReadFile(filepath.Join(constants.LocalConfigDir, "cchain_config.json"))
cChainConfig, err := os.ReadFile(filepath.Join("..", constants.LocalConfigDir, "cchain_config.json"))
if err != nil {
panic(err)
}
Expand All @@ -181,7 +181,7 @@ func init() {
}

for i := 0; i < len(defaultNetworkConfig.NodeConfigs); i++ {
flagsBytes, err := os.ReadFile(filepath.Join(constants.LocalConfigDir, fmt.Sprintf("node%d/flags.json", i+1)))
flagsBytes, err := os.ReadFile(filepath.Join("..", constants.LocalConfigDir, fmt.Sprintf("node%d/flags.json", i+1)))
if err != nil {
panic(err)
}
Expand All @@ -190,12 +190,12 @@ func init() {
panic(err)
}
defaultNetworkConfig.NodeConfigs[i].Flags = flags
stakingKey, err := os.ReadFile(filepath.Join(constants.LocalConfigDir, fmt.Sprintf("node%d/staking.key", i+1)))
stakingKey, err := os.ReadFile(filepath.Join("..", constants.LocalConfigDir, fmt.Sprintf("node%d/staking.key", i+1)))
if err != nil {
panic(err)
}
defaultNetworkConfig.NodeConfigs[i].StakingKey = string(stakingKey)
stakingCert, err := os.ReadFile(filepath.Join(constants.LocalConfigDir, fmt.Sprintf("node%d/staking.crt", i+1)))
stakingCert, err := os.ReadFile(filepath.Join("..", constants.LocalConfigDir, fmt.Sprintf("node%d/staking.crt", i+1)))
if err != nil {
panic(err)
}
Expand Down
11 changes: 10 additions & 1 deletion network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ const (

func init() {
var err error
cChainConfig, err = utils.LoadGenesisMap()
genesisMap, err := utils.LoadLocalGenesis()
if err != nil {
panic(err)
}
cChainConfigStr, ok := genesisMap["cChainGenesis"].(string)
if !ok {
panic(fmt.Errorf("expected cChainGenesis to be a string, but got %T", genesisMap["cChainGenesis"]))
}
cChainConfigBytes := []byte(cChainConfigStr)
err = json.Unmarshal(cChainConfigBytes, &cChainConfig)
if err != nil {
panic(err)
}
Expand Down
13 changes: 8 additions & 5 deletions utils/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"

"github.com/ava-labs/avalanche-network-runner/utils/constants"
coreth_params "github.com/ava-labs/coreth/params"
)

func LoadGenesisMap() (map[string]interface{}, error) {
genesis, err := os.ReadFile(constants.LocalGenesisFile)
// LoadLocalGenesis loads the local network genesis from disk
// and returns it as a map[string]interface{}
func LoadLocalGenesis() (map[string]interface{}, error) {
genesis, err := os.ReadFile(filepath.Join("..", constants.LocalGenesisFile))
if err != nil {
panic(err)
return nil, err
}
var genesisMap map[string]interface{}
if err = json.Unmarshal(genesis, &genesisMap); err != nil {
panic(err)
return nil, err
}

cChainGenesis := genesisMap["cChainGenesis"]
Expand All @@ -29,7 +32,7 @@ func LoadGenesisMap() (map[string]interface{}, error) {
cChainGenesisMap, ok := cChainGenesis.(map[string]interface{})
if !ok {
return nil, fmt.Errorf(
"expected field 'cChainGenesis' of genesisMap to be a map[string]interface{}, but it failed with type %T", cChainGenesisMap)
"expected field 'cChainGenesis' of genesisMap to be a map[string]interface{}, but it failed with type %T", cChainGenesis)
}
// set the `config` key to the actual coreth object
cChainGenesisMap["config"] = corethCChainGenesis
Expand Down

0 comments on commit 0ab1f7d

Please sign in to comment.