-
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.
Initialize and config the rollapp configuration from the init stage
- Loading branch information
1 parent
de1e2c0
commit abf1344
Showing
10 changed files
with
180 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
* | ||
!*/ | ||
!*.* | ||
*.exe | ||
*.exe | ||
/.vscode |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
package config | ||
|
||
import ( | ||
configInit "github.com/dymensionxyz/roller/cmd/config/init" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func ConfigCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "config", | ||
Short: "Commands for setting up and managing rollapp configuration files.", | ||
} | ||
cmd.AddCommand(configInit.InitCmd()) | ||
return cmd | ||
} |
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,29 @@ | ||
package init | ||
|
||
import ( | ||
"os" | ||
|
||
toml "github.com/pelletier/go-toml" | ||
) | ||
|
||
func setRollappAppConfig(appConfigFilePath string, denom string) { | ||
config, _ := toml.LoadFile(appConfigFilePath) | ||
config.Set("minimum-gas-prices", "0"+denom) | ||
config.Set("api.enable", "true") | ||
config.Set("api.address", "tcp://0.0.0.0:1417") | ||
config.Set("grpc.address", "0.0.0.0:8080") | ||
config.Set("grpc-web.address", "0.0.0.0:8081") | ||
file, _ := os.Create(appConfigFilePath) | ||
file.WriteString(config.String()) | ||
file.Close() | ||
} | ||
|
||
func setRollappTendermintConfig(tendermintConfigFilePath string) { | ||
config, _ := toml.LoadFile(tendermintConfigFilePath) | ||
config.Set("rpc.laddr", "tcp://0.0.0.0:26657") | ||
config.Set("p2p.laddr", "tcp://0.0.0.0:26657") | ||
config.Set("persistent_peers", "") | ||
file, _ := os.Create(tendermintConfigFilePath) | ||
file.WriteString(config.String()) | ||
file.Close() | ||
} |
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,84 @@ | ||
package init | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var flagNames = struct { | ||
LightNodeEndpoint string | ||
Denom string | ||
KeyPrefix string | ||
Decimals string | ||
RollappBinary string | ||
HubRPC string | ||
}{ | ||
LightNodeEndpoint: "light-node-endpoint", | ||
Denom: "denom", | ||
KeyPrefix: "key-prefix", | ||
Decimals: "decimals", | ||
RollappBinary: "rollapp-binary", | ||
HubRPC: "hub-rpc", | ||
} | ||
|
||
const denomFlagName = "denom" | ||
const hubRPC = "https://rpc-hub-35c.dymension.xyz:443" | ||
const lightNodeEndpointFlag = "light-node-endpoint" | ||
const hubSequencerKeyName = "hub_sequencer" | ||
|
||
const evmCoinType uint32 = 60 | ||
const rollappConfigDir string = ".rollapp" | ||
const relayerConfigDir string = ".relayer" | ||
const hubChainId string = "internal-devnet" | ||
const relayerKeysDirName string = "keys" | ||
const cosmosDefaultCointype uint32 = 118 | ||
const sequencerKeyName string = "rollapp_sequencer" | ||
|
||
func getDenom(denom string, chainId string) string { | ||
if denom == "" { | ||
return "u" + chainId[:3] | ||
} | ||
return denom | ||
} | ||
|
||
func getRollappBinaryPath(rollappBinaryPath string) string { | ||
if rollappBinaryPath == "" { | ||
rollappBinaryPath = "/usr/local/bin/rollapp_evm" | ||
} | ||
return rollappBinaryPath | ||
} | ||
|
||
func initializeRollappConfig(rollappExecutablePath string, chainId string, denom string) { | ||
initRollappCmd := exec.Command(rollappExecutablePath, "init", hubSequencerKeyName, "--chain-id", chainId, "--home", filepath.Join(os.Getenv("HOME"), rollappConfigDir)) | ||
err := initRollappCmd.Run() | ||
if err != nil { | ||
panic(err) | ||
} | ||
setRollappAppConfig(filepath.Join(os.Getenv("HOME"), rollappConfigDir, "config/app.toml"), denom) | ||
setRollappTendermintConfig(filepath.Join(os.Getenv("HOME"), rollappConfigDir, "config/config.toml")) | ||
} | ||
|
||
func InitCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "init <chain-id>", | ||
Short: "Initialize a rollapp configuration on your local machine", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
chainId := args[0] | ||
rollappBinaryPath := getRollappBinaryPath(cmd.Flag(flagNames.RollappBinary).Value.String()) | ||
denom := getDenom(cmd.Flag(flagNames.Denom).Value.String(), chainId) | ||
generateKeys(cmd.Flags().Changed(lightNodeEndpointFlag), chainId) | ||
initializeRollappConfig(rollappBinaryPath, chainId, denom) | ||
}, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
cmd.Flags().StringP(flagNames.HubRPC, "", hubRPC, "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("denom", "", "", "The rollapp token smallest denominator, for example `wei` in Ethereum.") | ||
cmd.Flags().StringP("key-prefix", "", "", "The `bech32` prefix of the rollapp keys.") | ||
cmd.Flags().StringP("rollapp-binary", "", "", "The rollapp binary. Should be passed only if you built a custom rollapp.") | ||
cmd.Flags().Int64P("decimals", "", 18, "The number of decimal places a rollapp token supports.") | ||
return cmd | ||
} |
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,46 @@ | ||
package init | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"path/filepath" | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/hd" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
) | ||
|
||
func createKey(relativePath string, keyId string, coinType ...uint32) (keyring.Info, error) { | ||
var coinTypeVal = cosmosDefaultCointype | ||
if len(coinType) != 0 { | ||
coinTypeVal = coinType[0] | ||
} | ||
rollappAppName := "rollapp" | ||
kr, err := keyring.New( | ||
rollappAppName, | ||
keyring.BackendTest, | ||
filepath.Join(os.Getenv("HOME"), relativePath), | ||
nil, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
bip44Params := hd.NewFundraiserParams(0, coinTypeVal, 0) | ||
info, _, err := kr.NewMnemonic(keyId, keyring.English, bip44Params.String(), "", hd.Secp256k1) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return info, nil | ||
} | ||
|
||
func generateKeys(createLightNode bool, chainId string) { | ||
const evmCoinType uint32 = 60 | ||
createKey(rollappConfigDir, hubSequencerKeyName) | ||
createKey(rollappConfigDir, sequencerKeyName, evmCoinType) | ||
relayerRollappDir := path.Join(relayerConfigDir, relayerKeysDirName, chainId) | ||
relayerHubDir := path.Join(relayerConfigDir, relayerKeysDirName, hubChainId) | ||
createKey(relayerHubDir, "relayer-hub-key") | ||
createKey(relayerRollappDir, "relayer-rollapp-key", evmCoinType) | ||
if createLightNode { | ||
createKey(".light_node", "my-celes-key") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.