-
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 a
roller config export
command (#439)
- Loading branch information
1 parent
3bbf7dd
commit c38631b
Showing
6 changed files
with
214 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package export | ||
|
||
import ( | ||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
"github.com/dymensionxyz/roller/config" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func getBech32Prefix(rlpCfg config.RollappConfig) (string, error) { | ||
rollappSeqAddr, err := utils.GetAddressBinary(utils.KeyConfig{ | ||
Dir: filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp), | ||
ID: consts.KeysIds.RollappSequencer, | ||
}, rlpCfg.RollappBinary) | ||
if err != nil { | ||
return "", err | ||
} | ||
return strings.Split(rollappSeqAddr, "1")[0], 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package export | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
"github.com/dymensionxyz/roller/config" | ||
"github.com/dymensionxyz/roller/relayer" | ||
"github.com/spf13/cobra" | ||
"math/big" | ||
) | ||
|
||
func Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "export", | ||
Short: "Export the rollapp configurations jsons needed to list your rollapp.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
home := cmd.Flag(utils.FlagNames.Home).Value.String() | ||
rlpCfg, err := config.LoadConfigFromTOML(home) | ||
utils.PrettifyErrorIfExists(err) | ||
bech32, err := getBech32Prefix(rlpCfg) | ||
utils.PrettifyErrorIfExists(err) | ||
const defaultFaucetUrl = "https://discord.com/channels/956961633165529098/1125047988247593010" | ||
baseDenom := rlpCfg.Denom | ||
coinType := 118 | ||
if rlpCfg.VMType == config.EVM_ROLLAPP { | ||
coinType = 60 | ||
} | ||
rly := relayer.NewRelayer(rlpCfg.Home, rlpCfg.RollappID, rlpCfg.HubData.ID) | ||
srcChannel, hubChannel, err := rly.LoadChannels() | ||
if err != nil || srcChannel == "" || hubChannel == "" { | ||
utils.PrettifyErrorIfExists(errors.New("no relayer channel was found on your local machine. Please create a channel before listing your rollapp on the portal")) | ||
} | ||
networkJson := NetworkJson{ | ||
ChainId: rlpCfg.RollappID, | ||
ChainName: rlpCfg.RollappID, | ||
Rpc: "", | ||
Rest: "", | ||
Bech32Prefix: bech32, | ||
Currencies: []string{ | ||
baseDenom, | ||
}, | ||
NativeCurrency: baseDenom, | ||
StakeCurrency: baseDenom, | ||
FeeCurrency: baseDenom, | ||
CoinType: coinType, | ||
FaucetUrl: defaultFaucetUrl, | ||
Website: "", | ||
Logo: "", | ||
Ibc: IbcConfig{ | ||
HubChannel: hubChannel, | ||
Channel: srcChannel, | ||
Timeout: 172800000, | ||
}, | ||
Type: RollApp, | ||
Description: nil, | ||
Analytics: false, | ||
} | ||
if rlpCfg.VMType == config.EVM_ROLLAPP { | ||
evmID := config.GetEthID(rlpCfg.RollappID) | ||
hexEvmID, err := decimalToHexStr(evmID) | ||
utils.PrettifyErrorIfExists(err) | ||
networkJson.Evm = &EvmConfig{ | ||
ChainId: hexEvmID, | ||
Rpc: "", | ||
} | ||
} | ||
if rlpCfg.DA == config.Avail { | ||
networkJson.Da = Avail | ||
} else { | ||
networkJson.Da = Celestia | ||
} | ||
currency := Currency{ | ||
CoinDenom: baseDenom[1:], | ||
CoinMinimalDenom: baseDenom, | ||
CoinDecimals: rlpCfg.Decimals, | ||
Logo: "", | ||
} | ||
|
||
networkJsonString, err := json.MarshalIndent(networkJson, "", " ") | ||
utils.PrettifyErrorIfExists(err) | ||
currencyJsonString, err := json.MarshalIndent(currency, "", " ") | ||
utils.PrettifyErrorIfExists(err) | ||
println("💈 networks.json:") | ||
println(string(networkJsonString)) | ||
println() | ||
println("💈 tokens.json:") | ||
println(string(currencyJsonString)) | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func decimalToHexStr(decimalStr string) (string, error) { | ||
num := new(big.Int) | ||
num, ok := num.SetString(decimalStr, 10) | ||
if !ok { | ||
return "", fmt.Errorf("Failed to parse the decimal string: %s", decimalStr) | ||
} | ||
hexStr := fmt.Sprintf("0x%x", num) | ||
return hexStr, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package export | ||
|
||
type IbcConfig struct { | ||
HubChannel string `json:"hubChannel"` | ||
Channel string `json:"channel"` | ||
Timeout int `json:"timeout"` | ||
EnabledTokens []string `json:"enabledTokens,omitempty"` | ||
} | ||
|
||
type EvmConfig struct { | ||
ChainId string `json:"chainId"` | ||
Rpc string `json:"rpc"` | ||
} | ||
|
||
type NetworkType string | ||
|
||
const ( | ||
Hub NetworkType = "Hub" | ||
RollApp NetworkType = "RollApp" | ||
Regular NetworkType = "Regular" | ||
) | ||
|
||
type DataAvailability string | ||
|
||
const ( | ||
Celestia DataAvailability = "Celestia" | ||
Avail DataAvailability = "Avail" | ||
) | ||
|
||
type GasPriceSteps struct { | ||
Low int `json:"low"` | ||
Average int `json:"average"` | ||
High int `json:"high"` | ||
} | ||
|
||
type App struct { | ||
Name string `json:"name"` | ||
Url string `json:"url"` | ||
Logo string `json:"logo"` | ||
} | ||
|
||
type NetworkJson struct { | ||
ChainId string `json:"chainId"` | ||
ChainName string `json:"chainName"` | ||
Rpc string `json:"rpc"` | ||
Rest string `json:"rest"` | ||
Bech32Prefix string `json:"bech32Prefix"` | ||
Currencies []string `json:"currencies"` | ||
NativeCurrency string `json:"nativeCurrency"` | ||
StakeCurrency string `json:"stakeCurrency"` | ||
FeeCurrency string `json:"feeCurrency"` | ||
GasPriceSteps *GasPriceSteps `json:"gasPriceSteps,omitempty"` | ||
GasAdjustment *float64 `json:"gasAdjustment,omitempty"` | ||
CoinType int `json:"coinType"` | ||
ExplorerUrl *string `json:"explorerUrl,omitempty"` | ||
ExploreTxUrl *string `json:"exploreTxUrl,omitempty"` | ||
FaucetUrl string `json:"faucetUrl,omitempty"` | ||
Website string `json:"website,omitempty"` | ||
ValidatorsLogosStorageDir *string `json:"validatorsLogosStorageDir,omitempty"` | ||
Logo string `json:"logo"` | ||
Disabled *bool `json:"disabled,omitempty"` | ||
Custom *bool `json:"custom,omitempty"` | ||
Ibc IbcConfig `json:"ibc"` | ||
Evm *EvmConfig `json:"evm,omitempty"` | ||
Type NetworkType `json:"type"` | ||
Da DataAvailability `json:"da,omitempty"` | ||
Apps []App `json:"apps,omitempty"` | ||
Description *string `json:"description,omitempty"` | ||
IsValidator *bool `json:"isValidator,omitempty"` | ||
Analytics bool `json:"analytics"` | ||
} | ||
|
||
type Currency struct { | ||
CoinDenom string `json:"coinDenom"` | ||
CoinMinimalDenom string `json:"coinMinimalDenom"` | ||
CoinDecimals uint `json:"coinDecimals"` | ||
Logo string `json:"logo"` | ||
} |
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