-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: it should be possible to run relayer for any rollapp when there…
…'s an active IBC connection (#1042)
- Loading branch information
1 parent
70fd554
commit d3e3913
Showing
18 changed files
with
1,077 additions
and
729 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,112 @@ | ||
package export | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
"github.com/dymensionxyz/roller/relayer" | ||
"github.com/dymensionxyz/roller/utils/config" | ||
"github.com/dymensionxyz/roller/utils/config/tomlconfig" | ||
"github.com/dymensionxyz/roller/utils/errorhandling" | ||
) | ||
|
||
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 := tomlconfig.LoadRollerConfig(home) | ||
errorhandling.PrettifyErrorIfExists(err) | ||
bech32, err := getBech32Prefix(rlpCfg) | ||
errorhandling.PrettifyErrorIfExists(err) | ||
faucetUrls := map[string]string{ | ||
consts.LocalHubID: "", | ||
consts.TestnetHubID: "https://discord.com/channels/956961633165529098/1196803789911498763", | ||
consts.MainnetHubID: "", | ||
} | ||
baseDenom := rlpCfg.Denom | ||
|
||
coinType := 60 | ||
if rlpCfg.VMType == consts.WASM_ROLLAPP { | ||
coinType = 118 | ||
} | ||
|
||
rly := relayer.NewRelayer(rlpCfg.Home, rlpCfg.RollappID, rlpCfg.HubData.ID) | ||
_, _, err = rly.LoadActiveChannel() | ||
if err != nil || rly.SrcChannel == "" || rly.DstChannel == "" { | ||
errorhandling.PrettifyErrorIfExists( | ||
errors.New( | ||
"failed to export rollapp json." + | ||
" Please verify that the rollapp is running on your local machine and a relayer channel has been established", | ||
), | ||
) | ||
} | ||
logoDefaultPath := fmt.Sprintf("/logos/%s.png", rlpCfg.RollappID) | ||
networkJson := NetworkJson{ | ||
ChainId: rlpCfg.RollappID, | ||
ChainName: rlpCfg.RollappID, | ||
Rpc: "", | ||
Rest: "", | ||
Bech32Prefix: bech32, | ||
Currencies: []Currency{ | ||
{ | ||
DisplayDenom: baseDenom[1:], | ||
BaseDenom: baseDenom, | ||
Decimals: rlpCfg.Decimals, | ||
Logo: logoDefaultPath, | ||
CurrencyType: "main", | ||
}, | ||
}, | ||
CoinType: coinType, | ||
FaucetUrl: faucetUrls[rlpCfg.HubData.ID], | ||
Website: "", | ||
Logo: logoDefaultPath, | ||
Ibc: IbcConfig{ | ||
HubChannel: rly.SrcChannel, | ||
Channel: rly.DstChannel, | ||
Timeout: 172800000, | ||
}, | ||
Type: RollApp, | ||
Analytics: true, | ||
} | ||
if rlpCfg.VMType == consts.EVM_ROLLAPP { | ||
evmID := config.GetEthID(rlpCfg.RollappID) | ||
hexEvmID, err := decimalToHexStr(evmID) | ||
errorhandling.PrettifyErrorIfExists(err) | ||
networkJson.Evm = &EvmConfig{ | ||
ChainId: hexEvmID, | ||
Rpc: "", | ||
} | ||
} | ||
if rlpCfg.DA.Backend == consts.Avail { | ||
networkJson.Da = Avail | ||
} else { | ||
networkJson.Da = Celestia | ||
} | ||
|
||
networkJsonString, err := json.MarshalIndent(networkJson, "", " ") | ||
errorhandling.PrettifyErrorIfExists(err) | ||
println("💈 networks.json:") | ||
println(string(networkJsonString)) | ||
}, | ||
} | ||
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 | ||
} | ||
// | ||
// import ( | ||
// "encoding/json" | ||
// "errors" | ||
// "fmt" | ||
// "math/big" | ||
// | ||
// "github.com/spf13/cobra" | ||
// | ||
// "github.com/dymensionxyz/roller/cmd/consts" | ||
// "github.com/dymensionxyz/roller/cmd/utils" | ||
// "github.com/dymensionxyz/roller/relayer" | ||
// "github.com/dymensionxyz/roller/utils/config" | ||
// "github.com/dymensionxyz/roller/utils/config/tomlconfig" | ||
// "github.com/dymensionxyz/roller/utils/errorhandling" | ||
// ) | ||
// | ||
// 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 := tomlconfig.LoadRollerConfig(home) | ||
// errorhandling.PrettifyErrorIfExists(err) | ||
// bech32, err := getBech32Prefix(rlpCfg) | ||
// errorhandling.PrettifyErrorIfExists(err) | ||
// faucetUrls := map[string]string{ | ||
// consts.LocalHubID: "", | ||
// consts.TestnetHubID: "https://discord.com/channels/956961633165529098/1196803789911498763", | ||
// consts.MainnetHubID: "", | ||
// } | ||
// baseDenom := rlpCfg.Denom | ||
// | ||
// coinType := 60 | ||
// if rlpCfg.VMType == consts.WASM_ROLLAPP { | ||
// coinType = 118 | ||
// } | ||
// | ||
// rly := relayer.NewRelayer(rlpCfg.Home, rlpCfg.RollappID, rlpCfg.HubData.ID) | ||
// _, _, err = rly.LoadActiveChannel() | ||
// if err != nil || rly.SrcChannel == "" || rly.DstChannel == "" { | ||
// errorhandling.PrettifyErrorIfExists( | ||
// errors.New( | ||
// "failed to export rollapp json." + | ||
// " Please verify that the rollapp is running on your local machine and a relayer channel has been established", | ||
// ), | ||
// ) | ||
// } | ||
// logoDefaultPath := fmt.Sprintf("/logos/%s.png", rlpCfg.RollappID) | ||
// networkJson := NetworkJson{ | ||
// ChainId: rlpCfg.RollappID, | ||
// ChainName: rlpCfg.RollappID, | ||
// Rpc: "", | ||
// Rest: "", | ||
// Bech32Prefix: bech32, | ||
// Currencies: []Currency{ | ||
// { | ||
// DisplayDenom: baseDenom[1:], | ||
// BaseDenom: baseDenom, | ||
// Decimals: rlpCfg.Decimals, | ||
// Logo: logoDefaultPath, | ||
// CurrencyType: "main", | ||
// }, | ||
// }, | ||
// CoinType: coinType, | ||
// FaucetUrl: faucetUrls[rlpCfg.HubData.ID], | ||
// Website: "", | ||
// Logo: logoDefaultPath, | ||
// Ibc: IbcConfig{ | ||
// HubChannel: rly.SrcChannel, | ||
// Channel: rly.DstChannel, | ||
// Timeout: 172800000, | ||
// }, | ||
// Type: RollApp, | ||
// Analytics: true, | ||
// } | ||
// if rlpCfg.VMType == consts.EVM_ROLLAPP { | ||
// evmID := config.GetEthID(rlpCfg.RollappID) | ||
// hexEvmID, err := decimalToHexStr(evmID) | ||
// errorhandling.PrettifyErrorIfExists(err) | ||
// networkJson.Evm = &EvmConfig{ | ||
// ChainId: hexEvmID, | ||
// Rpc: "", | ||
// } | ||
// } | ||
// if rlpCfg.DA.Backend == consts.Avail { | ||
// networkJson.Da = Avail | ||
// } else { | ||
// networkJson.Da = Celestia | ||
// } | ||
// | ||
// networkJsonString, err := json.MarshalIndent(networkJson, "", " ") | ||
// errorhandling.PrettifyErrorIfExists(err) | ||
// println("💈 networks.json:") | ||
// println(string(networkJsonString)) | ||
// }, | ||
// } | ||
// 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
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
Oops, something went wrong.