diff --git a/cmd/rollapp/init/init.go b/cmd/rollapp/init/init.go index e8d9806d..4b8f3f15 100644 --- a/cmd/rollapp/init/init.go +++ b/cmd/rollapp/init/init.go @@ -65,8 +65,17 @@ func Cmd() *cobra.Command { WithDefaultText("select the node type you want to run"). WithOptions(envs). Show() + hd := consts.Hubs[env] + + isRollappRegistered, _ := rollapp.IsRollappRegistered(raID, hd) // TODO: check whether the rollapp exists + + if !isRollappRegistered { + pterm.Error.Printf("%s was not found as a registered rollapp", raID) + return + } + err = runInit(cmd, env, raID) if err != nil { fmt.Printf("failed to initialize the RollApp: %v\n", err) @@ -98,15 +107,11 @@ func Cmd() *cobra.Command { pterm.Error.Println("failed to calculate hash of genesis file: ", err) } - hd := consts.Hubs[env] - fmt.Println(genesis.ChainID) fmt.Println("hash of the downloaded file: ", hash) // nolint:ineffassign raHash, _ := getRollappGenesisHash(raID, hd) fmt.Println("hash of the rollapp: ", raHash) - - pterm.Success.Println("finished") }, } return cmd diff --git a/cmd/rollapp/init/utils.go b/cmd/rollapp/init/utils.go index 37185873..d3a07e13 100644 --- a/cmd/rollapp/init/utils.go +++ b/cmd/rollapp/init/utils.go @@ -95,6 +95,7 @@ func runInit(cmd *cobra.Command, env string, raID string) error { hd := consts.Hubs[env] rollerTomlData := map[string]string{ + "rollapp_id": raID, "rollapp_binary": strings.ToLower(consts.Executables.RollappEVM), "home": home, diff --git a/cmd/rollapp/run/run.go b/cmd/rollapp/run/run.go index 9b4546b7..970679fe 100644 --- a/cmd/rollapp/run/run.go +++ b/cmd/rollapp/run/run.go @@ -30,7 +30,6 @@ import ( "github.com/dymensionxyz/roller/utils/config" "github.com/dymensionxyz/roller/utils/config/tomlconfig" "github.com/dymensionxyz/roller/utils/errorhandling" - rollapputils "github.com/dymensionxyz/roller/utils/rollapp" sequencerutils "github.com/dymensionxyz/roller/utils/sequencer" ) @@ -56,21 +55,18 @@ func Cmd() *cobra.Command { return } - var raID string - if len(args) != 0 { - raID = args[0] - } else { - raID, _ = pterm.DefaultInteractiveTextInput.WithDefaultText( - "provide a rollapp ID that you want to run the node for", - ).Show() - } - home, err := globalutils.ExpandHomePath(cmd.Flag(utils.FlagNames.Home).Value.String()) if err != nil { pterm.Error.Println("failed to expand home directory") return } + rollerData, err := tomlconfig.LoadRollerConfig(home) + if err != nil { + pterm.Error.Println("failed to load roller config file", err) + return + } + hd, err := tomlconfig.LoadHubData(home) if err != nil { pterm.Error.Println("failed to load hub data from roller.toml") @@ -78,7 +74,7 @@ func Cmd() *cobra.Command { rollappConfig, err := tomlconfig.LoadRollappMetadataFromChain( home, - raID, + rollerData.RollappID, &hd, ) errorhandling.PrettifyErrorIfExists(err) @@ -137,7 +133,7 @@ func Cmd() *cobra.Command { rollappConfig.RollappID, ) - seq, err := rollapputils.GetRegisteredSequencers(rollappConfig.RollappID) + seq, err := sequencerutils.GetRegisteredSequencers(rollappConfig.RollappID) if err != nil { pterm.Error.Println("failed to retrieve registered sequencers: ", err) } diff --git a/utils/rollapp/rollapp.go b/utils/rollapp/rollapp.go index 3cbeeac9..b0006a9a 100644 --- a/utils/rollapp/rollapp.go +++ b/utils/rollapp/rollapp.go @@ -11,7 +11,6 @@ import ( "github.com/dymensionxyz/roller/cmd/consts" globalutils "github.com/dymensionxyz/roller/utils/bash" - sequencerutils "github.com/dymensionxyz/roller/utils/sequencer" ) func GetCurrentHeight() (*BlockInformation, error) { @@ -39,17 +38,8 @@ func getCurrentBlockCmd() *exec.Cmd { return cmd } -func GetInitialSequencerAddress(raID string) (string, error) { - cmd := exec.Command( - consts.Executables.Dymension, - "q", - "rollapp", - "show", - raID, - "-o", - "json", - ) - +func GetInitialSequencerAddress(raID string, hd consts.HubData) (string, error) { + cmd := GetShowRollappCmd(raID, hd) out, err := globalutils.ExecCommandWithStdout(cmd) if err != nil { fmt.Println(err) @@ -61,8 +51,8 @@ func GetInitialSequencerAddress(raID string) (string, error) { return ra.Rollapp.InitialSequencer, nil } -func IsInitialSequencer(addr, raID string) (bool, error) { - initSeqAddr, err := GetInitialSequencerAddress(raID) +func IsInitialSequencer(addr, raID string, hd consts.HubData) (bool, error) { + initSeqAddr, err := GetInitialSequencerAddress(raID, hd) if err != nil { return false, err } @@ -76,33 +66,33 @@ func IsInitialSequencer(addr, raID string) (bool, error) { return false, nil } -func GetRegisteredSequencers( - raID string, -) (*sequencerutils.Sequencers, error) { - var seq sequencerutils.Sequencers - cmd := exec.Command( - consts.Executables.Dymension, - "q", - "sequencer", - "show-sequencers-by-rollapp", - raID, - "--output", "json", - ) - - out, err := globalutils.ExecCommandWithStdout(cmd) - if err != nil { - return nil, err - } - - err = json.Unmarshal(out.Bytes(), &seq) +// TODO: most of rollapp utility functions should be tied to an entity +func IsRollappRegistered(raID string, hd consts.HubData) (bool, error) { + cmd := GetShowRollappCmd(raID, hd) + _, err := globalutils.ExecCommandWithStdout(cmd) if err != nil { - return nil, err + // tODO: handle NotFound error + return false, err } - return &seq, nil + return true, nil } type BlockInformation struct { BlockId tmtypes.BlockID `json:"block_id"` Block tmtypes.Block `json:"block"` } + +func GetShowRollappCmd(raID string, hd consts.HubData) *exec.Cmd { + cmd := exec.Command( + consts.Executables.Dymension, + "q", + "rollapp", + "show", + raID, + "-o", "json", + "--node", hd.RPC_URL, + ) + + return cmd +} diff --git a/utils/sequencer/sequencer.go b/utils/sequencer/sequencer.go index 3e5f710c..0eec0ae2 100644 --- a/utils/sequencer/sequencer.go +++ b/utils/sequencer/sequencer.go @@ -164,3 +164,29 @@ func GetLatestSnapshot(raID string) (*SnapshotInfo, error) { return latestSnapshot, nil } + +func GetRegisteredSequencers( + raID string, +) (*Sequencers, error) { + var seq Sequencers + cmd := exec.Command( + consts.Executables.Dymension, + "q", + "sequencer", + "show-sequencers-by-rollapp", + raID, + "--output", "json", + ) + + out, err := bash.ExecCommandWithStdout(cmd) + if err != nil { + return nil, err + } + + err = json.Unmarshal(out.Bytes(), &seq) + if err != nil { + return nil, err + } + + return &seq, nil +}