Skip to content

Commit

Permalink
feat: it should be possible to run relayer for any rollapp when there…
Browse files Browse the repository at this point in the history
…'s an active IBC connection (#1042)
  • Loading branch information
artemijspavlovs authored Sep 26, 2024
1 parent 70fd554 commit d3e3913
Show file tree
Hide file tree
Showing 18 changed files with 1,077 additions and 729 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ body:
description: >
Please Attach here any relevant log files.
placeholder: >
Please Attach here any relevant log files or log output.
Please Attach here any relevant log files or log output.
- type: textarea
id: misc
attributes:
Expand Down
3 changes: 1 addition & 2 deletions cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package config
import (
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/config/export"
"github.com/dymensionxyz/roller/cmd/config/set"
"github.com/dymensionxyz/roller/cmd/config/show"
)
Expand All @@ -16,6 +15,6 @@ func Cmd() *cobra.Command {

cmd.AddCommand(show.Cmd())
cmd.AddCommand(set.Cmd())
cmd.AddCommand(export.Cmd())
// cmd.AddCommand(export.Cmd())
return cmd
}
219 changes: 110 additions & 109 deletions cmd/config/export/export.go
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
// }
2 changes: 1 addition & 1 deletion cmd/consts/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
DefaultCelestiaRPC = "http://mocha-4-consensus.mesa.newmetric.xyz:26657"

// https://docs.celestia.org/nodes/mocha-testnet#community-data-availability-da-grpc-endpoints-for-state-access
DefaultCelestiaStateNode = "rpc-mocha.pops.one"
DefaultCelestiaStateNode = "mocha-4-consensus.mesa.newmetric.xyz"
DefaultCelestiaNetwork = "mocha-4"
)

Expand Down
7 changes: 7 additions & 0 deletions cmd/consts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ type HubData = struct {
GAS_PRICE string `toml:"gas_price"`
}

type RollappData = struct {
ID string `toml:"id"`
ApiUrl string `toml:"api_url"`
RpcUrl string `toml:"rpc_url"`
GasPrice string `toml:"gas_price"`
}

type DaData = struct {
Backend DAType `toml:"backend"`
ID DaNetwork `toml:"id"`
Expand Down
7 changes: 4 additions & 3 deletions cmd/eibc/fulfill/rollapps/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"os"
"path/filepath"

"github.com/dymensionxyz/roller/cmd/consts"
eibcutils "github.com/dymensionxyz/roller/utils/eibc"
"github.com/dymensionxyz/roller/utils/filesystem"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"

"github.com/dymensionxyz/roller/cmd/consts"
eibcutils "github.com/dymensionxyz/roller/utils/eibc"
"github.com/dymensionxyz/roller/utils/filesystem"
)

func Cmd() *cobra.Command {
Expand Down
5 changes: 3 additions & 2 deletions cmd/eibc/funds/funds.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package funds
import (
"fmt"

"github.com/dymensionxyz/roller/utils/bash"
eibcutils "github.com/dymensionxyz/roller/utils/eibc"
"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/utils/bash"
eibcutils "github.com/dymensionxyz/roller/utils/eibc"
)

func Cmd() *cobra.Command {
Expand Down
Loading

0 comments on commit d3e3913

Please sign in to comment.