Skip to content

Commit

Permalink
Added output formatting for roller register
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial committed Jun 14, 2023
1 parent 862aecb commit 74eeec8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/config/init/DALightClient.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
33 changes: 30 additions & 3 deletions cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}

Expand All @@ -74,13 +78,36 @@ 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",
"--from", consts.KeyNames.HubSequencer,
"--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)
}
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 74eeec8

Please sign in to comment.