-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add command to register rollapps (#50)
- Loading branch information
1 parent
81d00fe
commit aee609f
Showing
15 changed files
with
158 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package initconfig | ||
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
"github.com/pelletier/go-toml" | ||
) | ||
|
||
func WriteConfigToTOML(InitConfig InitConfig) error { | ||
tomlBytes, err := toml.Marshal(InitConfig) | ||
if err != nil { | ||
return err | ||
} | ||
err = ioutil.WriteFile(filepath.Join(InitConfig.Home, RollerConfigFileName), tomlBytes, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func LoadConfigFromTOML(root string) (InitConfig, error) { | ||
var config InitConfig | ||
tomlBytes, err := ioutil.ReadFile(filepath.Join(root, RollerConfigFileName)) | ||
if err != nil { | ||
return config, err | ||
} | ||
err = toml.Unmarshal(tomlBytes, &config) | ||
if err != nil { | ||
return config, err | ||
} | ||
|
||
return config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package consts | ||
|
||
var Executables = struct { | ||
Celestia string | ||
RollappEVM string | ||
Relayer string | ||
Dymension string | ||
}{ | ||
Celestia: "/usr/local/bin/roller_bins/celestia", | ||
RollappEVM: "/usr/local/bin/rollapp_evm", | ||
Relayer: "/usr/local/bin/roller_bins/rly", | ||
Dymension: "/usr/local/bin/roller_bins/dymd", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package register | ||
|
||
import ( | ||
"bytes" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
initconfig "github.com/dymensionxyz/roller/cmd/config/init" | ||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func RegisterCmd() *cobra.Command { | ||
registerCmd := &cobra.Command{ | ||
Use: "register", | ||
Short: "Registers the rollapp and the sequencer to the Dymension hub.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
home := cmd.Flag(initconfig.FlagNames.Home).Value.String() | ||
rollappConfig, err := initconfig.LoadConfigFromTOML(home) | ||
utils.PrettifyErrorIfExists(err) | ||
utils.PrettifyErrorIfExists(registerRollapp(rollappConfig)) | ||
}, | ||
} | ||
addFlags(registerCmd) | ||
return registerCmd | ||
} | ||
|
||
func addFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringP(initconfig.FlagNames.Home, "", utils.GetRollerRootDir(), "The directory of the roller config files") | ||
} | ||
|
||
func registerRollapp(rollappConfig initconfig.InitConfig) error { | ||
cmd := exec.Command( | ||
consts.Executables.Dymension, "tx", "rollapp", "create-rollapp", | ||
"--from", initconfig.KeyNames.HubSequencer, | ||
"--keyring-backend", "test", | ||
"--keyring-dir", filepath.Join(rollappConfig.Home, initconfig.ConfigDirName.Rollapp), | ||
rollappConfig.RollappID, "stamp1", "genesis-path/1", "3", "3", `{"Addresses":[]}`, "--output", "json", | ||
"--node", initconfig.HubData.RPC_URL, "--yes", "--broadcast-mode", "block", | ||
) | ||
var stdout bytes.Buffer | ||
var stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
error := cmd.Run() | ||
return error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
cmd/config/init/error_handler.go → cmd/utils/error_handling.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package initconfig | ||
package utils | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func getRollerRootDir() string { | ||
func GetRollerRootDir() string { | ||
return filepath.Join(os.Getenv("HOME"), ".roller") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.