-
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.
- Loading branch information
1 parent
8619333
commit 66597b4
Showing
15 changed files
with
278 additions
and
72 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
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package start | ||
|
||
import ( | ||
"fmt" | ||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
"os/exec" | ||
"path/filepath" | ||
) | ||
|
||
func createIBCChannelIfNeeded(rollappConfig utils.RollappConfig) (string, error) { | ||
/** | ||
Creates an IBC channel between the hub and the client, and return the source channel ID. | ||
*/ | ||
createClientsCmd := getCreateClientsCmd(rollappConfig, rollappConfig.RollappID, rollappConfig.HubData.ID) | ||
fmt.Println("Creating clients...") | ||
if err := utils.ExecBashCmdWithOSOutput(createClientsCmd); err != nil { | ||
return "", err | ||
} | ||
dstConnectionId, err := GetDstConnectionIDFromYAMLFile(filepath.Join(rollappConfig.Home, consts.ConfigDirName.Relayer, | ||
"config", "config.yaml")) | ||
if err != nil { | ||
return "", err | ||
} | ||
if dstConnectionId == "" { | ||
createConnectionCmd := getCreateConnectionCmd(rollappConfig) | ||
fmt.Println("Creating connection...") | ||
if err := utils.ExecBashCmdWithOSOutput(createConnectionCmd); err != nil { | ||
return "", err | ||
} | ||
} | ||
srcChannelId, err := GetSourceChannelForConnection(dstConnectionId, rollappConfig) | ||
if err != nil { | ||
return "", err | ||
} | ||
if srcChannelId == "" { | ||
createChannelCmd := getCreateChannelCmd(rollappConfig) | ||
fmt.Println("Creating channel...") | ||
if err := utils.ExecBashCmdWithOSOutput(createChannelCmd); err != nil { | ||
return "", err | ||
} | ||
srcChannelId, err = GetSourceChannelForConnection(dstConnectionId, rollappConfig) | ||
if err != nil { | ||
return "", err | ||
} | ||
} | ||
return srcChannelId, nil | ||
} | ||
|
||
func getCreateChannelCmd(config utils.RollappConfig) *exec.Cmd { | ||
defaultRlyArgs := getRelayerDefaultArgs(config) | ||
args := []string{"tx", "channel", "--override"} | ||
args = append(args, defaultRlyArgs...) | ||
return exec.Command(consts.Executables.Relayer, args...) | ||
} | ||
|
||
func getCreateClientsCmd(rollappConfig utils.RollappConfig, srcId string, dstId string) *exec.Cmd { | ||
defaultRlyArgs := getRelayerDefaultArgs(rollappConfig) | ||
args := []string{"tx", "clients"} | ||
args = append(args, defaultRlyArgs...) | ||
return exec.Command(consts.Executables.Relayer, args...) | ||
} | ||
|
||
func getRelayerDefaultArgs(config utils.RollappConfig) []string { | ||
return []string{consts.DefaultRelayerPath, "--home", filepath.Join(config.Home, consts.ConfigDirName.Relayer)} | ||
} | ||
|
||
func getCreateConnectionCmd(config utils.RollappConfig) *exec.Cmd { | ||
defaultRlyArgs := getRelayerDefaultArgs(config) | ||
args := []string{"tx", "connection"} | ||
args = append(args, defaultRlyArgs...) | ||
return exec.Command(consts.Executables.Relayer, args...) | ||
} |
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,53 @@ | ||
package start | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
"os/exec" | ||
) | ||
|
||
func GetSourceChannelForConnection(dstConnectionID string, rollappConfig utils.RollappConfig) (string, error) { | ||
/** | ||
Returns the open source channel for the given destination connection ID. If no open channel exists, it returns an | ||
emtpy string. | ||
*/ | ||
commonDymdFlags := utils.GetCommonDymdFlags(rollappConfig) | ||
args := []string{"query", "ibc", "channel", "connections", dstConnectionID} | ||
args = append(args, commonDymdFlags...) | ||
cmd := exec.Command(consts.Executables.Dymension, args...) | ||
out, err := cmd.Output() | ||
if err != nil { | ||
return "", err | ||
} | ||
channelId, err := GetOpenStateChannelID(out) | ||
if err != nil { | ||
return "", err | ||
} | ||
return channelId, nil | ||
} | ||
|
||
type Channel struct { | ||
State string `json:"state"` | ||
Counterparty struct { | ||
ChannelID string `json:"channel_id"` | ||
} `json:"counterparty"` | ||
} | ||
|
||
type ChannelList struct { | ||
Channels []Channel `json:"channels"` | ||
} | ||
|
||
func GetOpenStateChannelID(jsonData []byte) (string, error) { | ||
var channels ChannelList | ||
if err := json.Unmarshal(jsonData, &channels); err != nil { | ||
return "", err | ||
} | ||
|
||
for _, channel := range channels.Channels { | ||
if channel.State == "STATE_OPEN" { | ||
return channel.Counterparty.ChannelID, nil | ||
} | ||
} | ||
return "", 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,38 @@ | ||
package start | ||
|
||
import ( | ||
"fmt" | ||
"gopkg.in/yaml.v2" | ||
"io/ioutil" | ||
) | ||
|
||
type RelayerConfigFile struct { | ||
Paths map[string]Path `yaml:"paths"` | ||
} | ||
|
||
type Path struct { | ||
Dst Destination `yaml:"dst"` | ||
} | ||
|
||
type Destination struct { | ||
ConnectionID string `yaml:"connection-id"` | ||
} | ||
|
||
func GetDstConnectionIDFromYAMLFile(filename string) (string, error) { | ||
/** | ||
Returns the destination connection ID if it been created already, an empty string otherwise. | ||
*/ | ||
data, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
return "", err | ||
} | ||
var config RelayerConfigFile | ||
err = yaml.Unmarshal(data, &config) | ||
if err != nil { | ||
return "", err | ||
} | ||
for _, path := range config.Paths { | ||
return path.Dst.ConnectionID, nil | ||
} | ||
return "", fmt.Errorf("No paths found in YAML data") | ||
} |
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.