From eaa27286b8c9c8fac9b5bfe0b91819bf238c0427 Mon Sep 17 00:00:00 2001 From: Itay Date: Thu, 15 Jun 2023 10:27:38 +0200 Subject: [PATCH] feat: Add output formatting for `roller register` command (#62) --- cmd/config/init/DALightClient.go | 2 +- cmd/register/register.go | 33 +++++++++++++++++++++++++++++--- install.sh | 4 ++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/cmd/config/init/DALightClient.go b/cmd/config/init/DALightClient.go index 2179b982..20cda210 100644 --- a/cmd/config/init/DALightClient.go +++ b/cmd/config/init/DALightClient.go @@ -1,9 +1,9 @@ package initconfig import ( + "github.com/dymensionxyz/roller/cmd/consts" "os/exec" "path/filepath" - "github.com/dymensionxyz/roller/cmd/consts" ) func initializeLightNodeConfig(initConfig InitConfig) error { diff --git a/cmd/register/register.go b/cmd/register/register.go index c1ba1333..541b4b1a 100644 --- a/cmd/register/register.go +++ b/cmd/register/register.go @@ -8,12 +8,12 @@ import ( "fmt" - "strings" - + "encoding/json" initconfig "github.com/dymensionxyz/roller/cmd/config/init" "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" "github.com/spf13/cobra" + "strings" ) func RegisterCmd() *cobra.Command { @@ -26,6 +26,7 @@ func RegisterCmd() *cobra.Command { utils.PrettifyErrorIfExists(err) utils.PrettifyErrorIfExists(initconfig.VerifyUniqueRollappID(rollappConfig.RollappID, rollappConfig)) utils.PrettifyErrorIfExists(registerRollapp(rollappConfig)) + printRegisterOutput(rollappConfig) }, } addFlags(registerCmd) @@ -49,6 +50,9 @@ func registerRollapp(rollappConfig initconfig.InitConfig) error { if cmdExecErr != nil { return cmdExecErr } + if err := handleStdOut(stdout, rollappConfig); err != nil { + return err + } return nil } @@ -74,6 +78,25 @@ func handleStdErr(stderr bytes.Buffer, rollappConfig initconfig.InitConfig) erro return nil } +type Response struct { + RawLog string `json:"raw_log"` +} + +func handleStdOut(stdout bytes.Buffer, rollappConfig initconfig.InitConfig) error { + var response Response + + err := json.NewDecoder(&stdout).Decode(&response) + if err != nil { + return err + } + + if strings.Contains(response.RawLog, "fail") { + return errors.New(response.RawLog) + } + + return nil +} + func getRegisterRollappCmd(rollappConfig initconfig.InitConfig) *exec.Cmd { return exec.Command( consts.Executables.Dymension, "tx", "rollapp", "create-rollapp", @@ -81,6 +104,10 @@ func getRegisterRollappCmd(rollappConfig initconfig.InitConfig) *exec.Cmd { "--keyring-backend", "test", "--keyring-dir", filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp), rollappConfig.RollappID, "stamp1", "genesis-path/1", "3", "3", `{"Addresses":[]}`, "--output", "json", - "--node", rollappConfig.HubData.RPC_URL, "--yes", "--broadcast-mode", "block", + "--node", rollappConfig.HubData.RPC_URL, "--yes", "--broadcast-mode", "block", "--chain-id", rollappConfig.HubData.ID, ) } + +func printRegisterOutput(rollappConfig initconfig.InitConfig) { + fmt.Printf("💈 Rollapp '%s' has been successfully registered on the hub.\n", rollappConfig.RollappID) +} diff --git a/install.sh b/install.sh index 303571a1..4639b2fe 100755 --- a/install.sh +++ b/install.sh @@ -12,8 +12,8 @@ INTERNAL_DIR="/usr/local/bin/roller_bins" ROLLER_BIN_PATH="/usr/local/bin/roller" # Check if Roller binary already exists -if [ -f "$ROLLER_BIN_PATH" ]; then - sudo rm "$ROLLER_BIN_PATH" +if [ -f "$ROLLER_BIN_PATH" ] || [ -d "$INTERNAL_DIR" ]; then + sudo rm -f "$ROLLER_BIN_PATH" sudo rm -rf "$INTERNAL_DIR" fi