Skip to content

Commit

Permalink
chore: Remove the configurable address prefix flag (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial authored Jun 4, 2023
1 parent c89328b commit e7f4d56
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 47 deletions.
12 changes: 5 additions & 7 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ var flagNames = struct {
Home string
LightNodeEndpoint string
Denom string
KeyPrefix string
Decimals string
RollappBinary string
HubRPC string
}{
Home: "home",
LightNodeEndpoint: "light-node-endpoint",
Denom: "denom",
KeyPrefix: "key-prefix",
Decimals: "decimals",
RollappBinary: "rollapp-binary",
HubRPC: "hub-rpc",
Expand All @@ -32,14 +30,14 @@ var keyNames = struct {
HubRelayer: "relayer-hub-key",
}

var keyPrefixes = struct {
Hub string
var addressPrefixes = struct {
Hub string
Rollapp string
DA string
DA string
}{
Rollapp: "rol",
Hub: "dym",
DA: "celestia",
Hub: "dym",
DA: "celestia",
}

var configDirName = struct {
Expand Down
50 changes: 20 additions & 30 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
)

type InitConfig struct {
Home string
RollappID string
RollappBinary string
Home string
RollappID string
RollappBinary string
CreateDALightNode bool
Denom string
HubID string
Decimals uint64
Denom string
HubID string
Decimals uint64
}

func InitCmd() *cobra.Command {
Expand All @@ -22,18 +22,17 @@ func InitCmd() *cobra.Command {
rollappId := args[0]
denom := args[1]
home := cmd.Flag(flagNames.Home).Value.String()
rollappKeyPrefix := getKeyPrefix(cmd, rollappId)
createLightNode := !cmd.Flags().Changed(lightNodeEndpointFlag)
rollappBinaryPath := getRollappBinaryPath(cmd)
decimals := getDecimals(cmd)
initConfig := InitConfig{
Home: home,
RollappID: rollappId,
RollappBinary: rollappBinaryPath,
Home: home,
RollappID: rollappId,
RollappBinary: rollappBinaryPath,
CreateDALightNode: createLightNode,
Denom: denom,
HubID: defaultHubId,
Decimals: decimals,
Denom: denom,
HubID: defaultHubId,
Decimals: decimals,
}

addresses := initializeKeys(initConfig)
Expand All @@ -48,15 +47,15 @@ func InitCmd() *cobra.Command {
}

if err := initializeRelayerConfig(ChainConfig{
ID: rollappId,
RPC: defaultRollappRPC,
Denom: denom,
KeyPrefix: rollappKeyPrefix,
ID: rollappId,
RPC: defaultRollappRPC,
Denom: denom,
AddressPrefix: addressPrefixes.Rollapp,
}, ChainConfig{
ID: defaultHubId,
RPC: cmd.Flag(flagNames.HubRPC).Value.String(),
Denom: "udym",
KeyPrefix: keyPrefixes.Hub,
ID: defaultHubId,
RPC: cmd.Flag(flagNames.HubRPC).Value.String(),
Denom: "udym",
AddressPrefix: addressPrefixes.Hub,
}, initConfig); err != nil {
panic(err)
}
Expand All @@ -79,7 +78,6 @@ func InitCmd() *cobra.Command {
func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP(flagNames.HubRPC, "", defaultHubRPC, "Dymension Hub rpc endpoint")
cmd.Flags().StringP(flagNames.LightNodeEndpoint, "", "", "The data availability light node endpoint. Runs an Arabica Celestia light node if not provided")
cmd.Flags().StringP(flagNames.KeyPrefix, "", "", "The `bech32` prefix of the rollapp keys. Defaults to the first three characters of the chain-id")
cmd.Flags().StringP(flagNames.RollappBinary, "", "", "The rollapp binary. Should be passed only if you built a custom rollapp")
cmd.Flags().Uint64P(flagNames.Decimals, "", 18, "The number of decimal places a rollapp token supports")
cmd.Flags().StringP(flagNames.Home, "", getRollerRootDir(), "The directory of the roller config files")
Expand Down Expand Up @@ -116,11 +114,3 @@ func getRollappBinaryPath(cmd *cobra.Command) string {
}
return rollappBinaryPath
}

func getKeyPrefix(cmd *cobra.Command, rollappID string) string {
keyPrefix := cmd.Flag(flagNames.KeyPrefix).Value.String()
if keyPrefix == "" {
return rollappID[:3]
}
return keyPrefix
}
10 changes: 5 additions & 5 deletions cmd/config/init/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,31 @@ func getDefaultKeysConfig(initConfig InitConfig) []KeyConfig {
dir: configDirName.Rollapp,
keyId: keyNames.HubSequencer,
coinType: cosmosDefaultCointype,
prefix: keyPrefixes.Hub,
prefix: addressPrefixes.Hub,
},
{
dir: configDirName.Rollapp,
keyId: keyNames.RollappSequencer,
coinType: evmCoinType,
prefix: keyPrefixes.Rollapp,
prefix: addressPrefixes.Rollapp,
},
{
dir: path.Join(configDirName.Relayer, relayerKeysDirName, initConfig.RollappID),
keyId: keyNames.HubRelayer,
coinType: cosmosDefaultCointype,
prefix: keyPrefixes.Hub,
prefix: addressPrefixes.Hub,
},
{
dir: path.Join(configDirName.Relayer, relayerKeysDirName, initConfig.HubID),
keyId: keyNames.RollappRelayer,
coinType: evmCoinType,
prefix: keyPrefixes.Rollapp,
prefix: addressPrefixes.Rollapp,
}, {

dir: path.Join(configDirName.DALightNode, relayerKeysDirName),
keyId: keyNames.DALightNode,
coinType: cosmosDefaultCointype,
prefix: keyPrefixes.DA,
prefix: addressPrefixes.DA,
},
}
}
10 changes: 5 additions & 5 deletions cmd/config/init/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type RelayerFileChainConfigValue struct {
}

type ChainConfig struct {
ID string
RPC string
Denom string
KeyPrefix string
ID string
RPC string
Denom string
AddressPrefix string
}

type RelayerChainConfig struct {
Expand Down Expand Up @@ -60,7 +60,7 @@ func getRelayerFileChainConfig(relayerChainConfig RelayerChainConfig) RelayerFil
Key: relayerChainConfig.KeyName,
ChainID: relayerChainConfig.ChainConfig.ID,
RpcAddr: relayerChainConfig.ChainConfig.RPC,
AccountPrefix: relayerChainConfig.ChainConfig.KeyPrefix,
AccountPrefix: relayerChainConfig.ChainConfig.AddressPrefix,
KeyringBackend: "test",
GasAdjustment: 1.2,
GasPrices: relayerChainConfig.GasPrices,
Expand Down

0 comments on commit e7f4d56

Please sign in to comment.