Skip to content

Commit

Permalink
fix: Set rollapp default listen addr to 0.0.0.0:26657 (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial authored Aug 2, 2023
1 parent 45a93ba commit 3661623
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions cmd/config/init/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,74 @@ import (

func initializeRollappConfig(initConfig config.RollappConfig) error {
home := filepath.Join(initConfig.Home, consts.ConfigDirName.Rollapp)

initRollappCmd := exec.Command(initConfig.RollappBinary, "init", consts.KeysIds.HubSequencer, "--chain-id",
initConfig.RollappID, "--home", home)
_, err := utils.ExecBashCommandWithStdout(initRollappCmd)
if err != nil {
return err
}

seqPubKey, err := utils.GetSequencerPubKey(initConfig)
if err != nil {
return err
}

setGentxCmd := exec.Command(initConfig.RollappBinary, "gentx_seq",
"--pubkey", seqPubKey, "--from", consts.KeysIds.RollappSequencer, "--keyring-backend", "test", "--home", home)
_, err = utils.ExecBashCommandWithStdout(setGentxCmd)
if err != nil {
return err
}

err = setRollappAppConfig(filepath.Join(initConfig.Home, consts.ConfigDirName.Rollapp, "config", "app.toml"),
initConfig.Denom)
if err != nil {
if err = setRollappConfig(initConfig); err != nil {
return err
}
return nil
}

if err = sequencer.SetDefaultDymintConfig(initConfig); err != nil {
func setRollappConfig(rlpCfg config.RollappConfig) error {
if err := setAppConfig(rlpCfg); err != nil {
return err
}
if err := setTMConfig(rlpCfg); err != nil {
return err
}
if err := sequencer.SetDefaultDymintConfig(rlpCfg); err != nil {
return err
}
return nil
}

func setRollappAppConfig(appConfigFilePath string, denom string) error {
config, err := toml.LoadFile(appConfigFilePath)
func setAppConfig(rlpCfg config.RollappConfig) error {
appConfigFilePath := filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp, "config", "app.toml")
appCfg, err := toml.LoadFile(appConfigFilePath)
if err != nil {
return fmt.Errorf("failed to load %s: %v", appConfigFilePath, err)
}

config.Set("minimum-gas-prices", "0"+denom)
config.Set("api.enable", "true")
config.Set("rpc.laddr", "tcp://0.0.0.0:26657")
if config.Has("json-rpc") {
config.Set("json-rpc.address", "0.0.0.0:8545")
config.Set("json-rpc.ws-address", "0.0.0.0:8546")
appCfg.Set("minimum-gas-prices", "0"+rlpCfg.Denom)
appCfg.Set("api.enable", "true")

if appCfg.Has("json-rpc") {
appCfg.Set("json-rpc.address", "0.0.0.0:8545")
appCfg.Set("json-rpc.ws-address", "0.0.0.0:8546")
}
file, err := os.Create(appConfigFilePath)
return writeTomlTreeToFile(appCfg, appConfigFilePath)
}

func setTMConfig(rlpCfg config.RollappConfig) error {
configFilePath := filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp, "config", "config.toml")
var tomlCfg, err = toml.LoadFile(configFilePath)
if err != nil {
return fmt.Errorf("failed to load %s: %v", configFilePath, err)
}
tomlCfg.Set("rpc.laddr", "tcp://0.0.0.0:26657")
return writeTomlTreeToFile(tomlCfg, configFilePath)
}

func writeTomlTreeToFile(tomlConfig *toml.Tree, path string) error {
file, err := os.Create(path)
if err != nil {
return err
}
_, err = file.WriteString(config.String())
_, err = file.WriteString(tomlConfig.String())
if err != nil {
return err
}
Expand Down

0 comments on commit 3661623

Please sign in to comment.