Skip to content

Commit

Permalink
Merged with main.
Browse files Browse the repository at this point in the history
  • Loading branch information
omritoptix committed Oct 30, 2023
2 parents fec09e5 + 93d9bf2 commit 99eaf9c
Show file tree
Hide file tree
Showing 32 changed files with 370 additions and 199 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,28 @@ jobs:
make build
make go-install
make cel-key
- name: Get the latest version of the cosmos sdk
run: |
if [ -d "./cosmos-sdk" ]; then
cd cosmos-sdk
git fetch --all
else
git clone https://github.com/cosmos/cosmos-sdk.git
cd cosmos-sdk
fi
git checkout tags/v0.47.5
- name: Build cosmos-sdk
run: |
cd ./cosmos-sdk
make build
- name: Create roller_bins archive folder structure
run: |
rm -rf roller_bins
mkdir roller_bins
mkdir roller_bins/lib
sudo cp ./celestia-node/cel-key ./roller_bins/lib/cel-key
sudo cp ./celestia-node/build/celestia ./roller_bins/lib/celestia
sudo cp ./cosmos-sdk/build/simd ./roller_bins/lib/simd
sudo cp -r /usr/local/bin/roller_bins/* ./roller_bins/lib/
sudo cp /usr/local/bin/roller ./roller_bins/roller
sudo cp /usr/local/bin/rollapp_evm ./roller_bins/rollapp_evm
Expand Down
14 changes: 9 additions & 5 deletions cmd/config/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"math/big"

"github.com/dymensionxyz/roller/cmd/utils"
Expand All @@ -22,7 +23,11 @@ func Cmd() *cobra.Command {
utils.PrettifyErrorIfExists(err)
bech32, err := getBech32Prefix(rlpCfg)
utils.PrettifyErrorIfExists(err)
const defaultFaucetUrl = "https://discord.com/channels/956961633165529098/1125047988247593010"
var faucetUrls = map[string]string{
consts.LocalHubID: "",
consts.StagingHubID: "https://discord.com/channels/956961633165529098/1125047988247593010",
consts.FroopylandHubID: "https://discord.com/channels/956961633165529098/1143231362468434022",
}
baseDenom := rlpCfg.Denom

coinType := 118
Expand Down Expand Up @@ -52,17 +57,16 @@ func Cmd() *cobra.Command {
},
},
CoinType: coinType,
FaucetUrl: defaultFaucetUrl,
FaucetUrl: faucetUrls[rlpCfg.HubData.ID],
Website: "",
Logo: logoDefaultPath,
Ibc: IbcConfig{
HubChannel: hubChannel,
Channel: srcChannel,
Timeout: 172800000,
},
Type: RollApp,
Description: nil,
Analytics: true,
Type: RollApp,
Analytics: true,
}
if rlpCfg.VMType == config.EVM_ROLLAPP {
evmID := config.GetEthID(rlpCfg.RollappID)
Expand Down
6 changes: 3 additions & 3 deletions cmd/config/export/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type NetworkJson struct {
ExplorerUrl *string `json:"explorerUrl,omitempty"`
ExploreTxUrl *string `json:"exploreTxUrl,omitempty"`
FaucetUrl string `json:"faucetUrl,omitempty"`
Website string `json:"website,omitempty"`
Website string `json:"website"`
ValidatorsLogosStorageDir *string `json:"validatorsLogosStorageDir,omitempty"`
Logo string `json:"logo"`
Disabled *bool `json:"disabled,omitempty"`
Expand All @@ -70,7 +70,7 @@ type NetworkJson struct {
Type NetworkType `json:"type"`
Da DataAvailability `json:"da,omitempty"`
Apps []App `json:"apps,omitempty"`
Description *string `json:"description,omitempty"`
IsValidator *bool `json:"isValidator,omitempty"`
Description string `json:"description"`
IsValidator *bool `json:"validator,omitempty"`
Analytics bool `json:"analytics"`
}
70 changes: 42 additions & 28 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package initconfig
import (
"fmt"
"math/rand"
"regexp"
"strings"
"time"

Expand All @@ -19,7 +20,7 @@ const (
)

func addFlags(cmd *cobra.Command) error {
cmd.Flags().StringP(FlagNames.HubID, "", FroopylandHubName, fmt.Sprintf("The ID of the Dymension hub. %s", getAvailableHubsMessage()))
cmd.Flags().StringP(FlagNames.HubID, "", consts.FroopylandHubName, fmt.Sprintf("The ID of the Dymension hub. %s", getAvailableHubsMessage()))
cmd.Flags().StringP(FlagNames.RollappBinary, "", consts.Executables.RollappEVM, "The rollapp binary. Should be passed only if you built a custom rollapp")
cmd.Flags().StringP(FlagNames.VMType, "", string(config.EVM_ROLLAPP), "The rollapp type [evm, sdk]. Defaults to evm")
cmd.Flags().StringP(FlagNames.TokenSupply, "", defaultTokenSupply, "The total token supply of the RollApp")
Expand All @@ -39,50 +40,58 @@ func addFlags(cmd *cobra.Command) error {
return nil
}

func GetInitConfig(initCmd *cobra.Command, args []string) (config.RollappConfig, error) {
cfg := config.RollappConfig{
RollerVersion: version.TrimVersionStr(version.BuildVersion),
}
cfg.Home = initCmd.Flag(utils.FlagNames.Home).Value.String()
cfg.RollappBinary = initCmd.Flag(FlagNames.RollappBinary).Value.String()
// Error is ignored because the flag is validated in the cobra preRun hook
func GetInitConfig(initCmd *cobra.Command, args []string) (*config.RollappConfig, error) {
home := initCmd.Flag(utils.FlagNames.Home).Value.String()
interactive, _ := initCmd.Flags().GetBool(FlagNames.Interactive)

//load initial config if exists
var cfg config.RollappConfig
//load from flags
cfg.Home = home
cfg.RollappBinary = initCmd.Flag(FlagNames.RollappBinary).Value.String()
cfg.VMType = config.VMType(initCmd.Flag(FlagNames.VMType).Value.String())
cfg.TokenSupply = initCmd.Flag(FlagNames.TokenSupply).Value.String()
decimals, _ := initCmd.Flags().GetUint(FlagNames.Decimals)
cfg.Decimals = decimals
cfg.DA = config.DAType(strings.ToLower(initCmd.Flag(FlagNames.DAType).Value.String()))
hubID := initCmd.Flag(FlagNames.HubID).Value.String()
if hub, ok := consts.Hubs[hubID]; ok {
cfg.HubData = hub
}
cfg.RollerVersion = version.TrimVersionStr(version.BuildVersion)

if len(args) > 0 {
cfg.RollappID = args[0]
}
if len(args) > 1 {
cfg.Denom = "u" + args[1]
}

if interactive {
if err := RunInteractiveMode(&cfg); err != nil {
return cfg, err
return nil, err
}
return formatBaseCfg(cfg, initCmd), nil
}

rollappId := args[0]
denom := args[1]
if !isLowercaseAlphabetical(rollappId) {
return cfg, fmt.Errorf("invalid rollapp id %s. %s", rollappId, validRollappIDMsg)
}
hubID := initCmd.Flag(FlagNames.HubID).Value.String()
tokenSupply := initCmd.Flag(FlagNames.TokenSupply).Value.String()
cfg.RollappID = rollappId
cfg.Denom = "u" + denom
cfg.HubData = Hubs[hubID]
cfg.TokenSupply = tokenSupply
cfg.DA = config.DAType(strings.ToLower(initCmd.Flag(FlagNames.DAType).Value.String()))
cfg.VMType = config.VMType(initCmd.Flag(FlagNames.VMType).Value.String())
return formatBaseCfg(cfg, initCmd), nil
return formatBaseCfg(cfg, initCmd)
}

func formatBaseCfg(cfg config.RollappConfig, initCmd *cobra.Command) config.RollappConfig {
func formatBaseCfg(cfg config.RollappConfig, initCmd *cobra.Command) (*config.RollappConfig, error) {
setDecimals(initCmd, &cfg)
formattedRollappId, err := generateRollappId(cfg)
if err != nil {
return cfg
return nil, err
}
cfg.RollappID = formattedRollappId
return cfg
return &cfg, nil
}

func generateRollappId(rlpCfg config.RollappConfig) (string, error) {
for {
RandEthId := generateRandEthId()
if rlpCfg.HubData.ID == consts.LocalHubID {
return fmt.Sprintf("%s_%s-1", rlpCfg.RollappID, RandEthId), nil
}
isUnique, err := isEthIdentifierUnique(RandEthId, rlpCfg)
if err != nil {
return "", err
Expand All @@ -109,5 +118,10 @@ func setDecimals(initCmd *cobra.Command, cfg *config.RollappConfig) {
}

func getAvailableHubsMessage() string {
return fmt.Sprintf("Acceptable values are '%s', '%s' or '%s'", FroopylandHubName, StagingHubName, LocalHubName)
return fmt.Sprintf("Acceptable values are '%s', '%s' or '%s'", consts.FroopylandHubName, consts.StagingHubName, consts.LocalHubName)
}

func isLowercaseAlphabetical(s string) bool {
match, _ := regexp.MatchString("^[a-z]+$", s)
return match
}
9 changes: 7 additions & 2 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func InitCmd() *cobra.Command {
return fmt.Errorf("invalid number of arguments. Expected 2, got %d", len(args))
}

if !isLowercaseAlphabetical(args[0]) {
return fmt.Errorf("invalid rollapp id %s. %s", args[0], validRollappIDMsg)
}

//TODO: parse the config here instead of GetInitConfig in Run command
// cmd.SetContextValue("mydata", data)

Expand Down Expand Up @@ -61,10 +65,11 @@ func runInit(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
initConfig, err := GetInitConfig(cmd, args)
initConfigPtr, err := GetInitConfig(cmd, args)
if err != nil {
return err
}
initConfig := *initConfigPtr
outputHandler := NewOutputHandler(noOutput)
defer outputHandler.StopSpinner()
utils.RunOnInterrupt(outputHandler.StopSpinner)
Expand Down Expand Up @@ -160,7 +165,7 @@ func runInit(cmd *cobra.Command, args []string) error {

/* ------------------------------ Initialize Local Hub ---------------------------- */
hub := cmd.Flag(FlagNames.HubID).Value.String()
if hub == LocalHubName {
if hub == consts.LocalHubName {
err := initLocalHub(initConfig)
utils.PrettifyErrorIfExists(err)
}
Expand Down
64 changes: 46 additions & 18 deletions cmd/config/init/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"os"
"strings"
"unicode"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/config"
"github.com/manifoldco/promptui"
)
Expand All @@ -14,26 +14,51 @@ func RunInteractiveMode(cfg *config.RollappConfig) error {
promptNetwork := promptui.Select{
Label: "Select your network",
Items: []string{"froopyland", "devnet", "local"},
CursorPos: func() int {
switch cfg.HubData.ID {
case consts.Hubs[consts.FroopylandHubName].ID:
return 0
case consts.Hubs[consts.StagingHubName].ID:
return 1
case consts.Hubs[consts.LocalHubName].ID:
return 2
default:
return 0
}
}(),
}
_, mode, err := promptNetwork.Run()
if err != nil {
return err
}
cfg.HubData = Hubs[mode]
cfg.VMType = config.EVM_ROLLAPP
cfg.HubData = consts.Hubs[mode]

promptExecutionEnv := promptui.Select{
Label: "Choose your rollapp execution environment",
Items: []string{"EVM rollapp", "custom EVM rollapp", "custom non-EVM rollapp"},
CursorPos: func() int {
if cfg.RollappBinary == consts.Executables.RollappEVM {
return 0
} else if cfg.VMType == config.EVM_ROLLAPP {
return 1
} else {
return 2
}
}(),
}
_, env, err := promptExecutionEnv.Run()
if err != nil {
return err
}

if env == "custom non-EVM rollapp" {
cfg.VMType = config.SDK_ROLLAPP
} else {
cfg.VMType = config.EVM_ROLLAPP
}

//if custom binary, get the binary path
if env != "EVM rollapp" {
if env == "custom non-EVM rollapp" {
cfg.VMType = config.SDK_ROLLAPP
}
promptBinaryPath := promptui.Prompt{
Label: "Set your runtime binary",
Default: cfg.RollappBinary,
Expand All @@ -51,7 +76,7 @@ func RunInteractiveMode(cfg *config.RollappConfig) error {
}
promptChainID := promptui.Prompt{
Label: "Enter your RollApp ID",
Default: "myrollapp",
Default: strings.Split(cfg.RollappID, "_")[0],
AllowEdit: true,
}
for {
Expand All @@ -69,7 +94,7 @@ func RunInteractiveMode(cfg *config.RollappConfig) error {

promptDenom := promptui.Prompt{
Label: "Specify your RollApp denom",
Default: "RAX",
Default: strings.TrimPrefix(cfg.Denom, "u"),
AllowEdit: true,
Validate: func(s string) error {
if !config.IsValidTokenSymbol(s) {
Expand All @@ -86,7 +111,7 @@ func RunInteractiveMode(cfg *config.RollappConfig) error {

promptTokenSupply := promptui.Prompt{
Label: "How many " + denom + " tokens do you wish to mint for Genesis?",
Default: "1000000000",
Default: cfg.TokenSupply,
Validate: config.VerifyTokenSupply,
}
supply, err := promptTokenSupply.Run()
Expand All @@ -99,18 +124,21 @@ func RunInteractiveMode(cfg *config.RollappConfig) error {
promptDAType := promptui.Select{
Label: "Choose your data layer",
Items: availableDAs,
CursorPos: func() int {
switch cfg.DA {
case config.Celestia:
return 0
case config.Avail:
return 1
case config.Local:
return 2
default:
return 0
}
}(),
}
_, da, _ := promptDAType.Run()
cfg.DA = config.DAType(strings.ToLower(da))

return nil
}

func isLowercaseAlphabetical(s string) bool {
for _, r := range s {
if !unicode.IsLetter(r) || !unicode.IsLower(r) {
return false
}
}
return true
}
5 changes: 1 addition & 4 deletions cmd/config/init/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func getSequencerKeysConfig(rollappConfig config.RollappConfig) []utils.KeyConfi
Dir: consts.ConfigDirName.HubKeys,
ID: consts.KeysIds.HubSequencer,
ChainBinary: consts.Executables.Dymension,
//Eventhough the hub can get evm signitures, we still use the native
//Eventhough the hub can get evm signatures, we still use the native
Type: config.SDK_ROLLAPP,
},
{
Expand Down Expand Up @@ -81,9 +81,6 @@ func createAddressBinary(keyConfig utils.KeyConfig, home string) (string, error)
"--keyring-dir", filepath.Join(home, keyConfig.Dir),
"--output", "json",
}
if keyConfig.ChainBinary == consts.Executables.Dymension {
args = append(args, "--algo", consts.AlgoTypes.Secp256k1)
}
createKeyCommand := exec.Command(keyConfig.ChainBinary, args...)
out, err := utils.ExecBashCommandWithStdout(createKeyCommand)
if err != nil {
Expand Down
Loading

0 comments on commit 99eaf9c

Please sign in to comment.