Skip to content

Commit

Permalink
refactor: decouple code
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs committed Nov 27, 2024
1 parent 8bfed05 commit 2ce9d08
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
16 changes: 9 additions & 7 deletions cmd/relayer/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ func Cmd() *cobra.Command {
relayerLogFilePath := logging.GetRelayerLogPath(home)
relayerLogger := logging.GetLogger(relayerLogFilePath)
rly.SetLogger(relayerLogger)
err = rly.Config.Load(rly.ConfigFilePath)
if err != nil {
pterm.Error.Println("failed to load relayer config: ", err)
return
}

rollappChainData, err := rollapp.PopulateRollerConfigWithRaMetadataFromChain(
home,
Expand All @@ -68,6 +63,13 @@ func Cmd() *cobra.Command {
}
pterm.Info.Println("rollapp chain data validation passed")

var rlyCfg relayer.Config
err = rlyCfg.Load(rly.ConfigFilePath)
if err != nil {
pterm.Error.Println("failed to load relayer config: ", err)
return
}

// err = installRelayerDependencies(home, raID, *hd)
// if err != nil {
// pterm.Error.Println("failed to install relayer dependencies: ", err)
Expand All @@ -89,9 +91,9 @@ func Cmd() *cobra.Command {
return
}

if rly.Config.GetPath() == nil {
if rlyCfg.GetPath() == nil {
pterm.Error.Println("no existing path")
if err := rly.Config.CreatePath(*rollappChainData); err != nil {
if err := rlyCfg.CreatePath(*rollappChainData); err != nil {
pterm.Error.Printf("failed to create relayer IBC path: %v\n", err)
return
}
Expand Down
1 change: 0 additions & 1 deletion cmd/relayer/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func Cmd() *cobra.Command {
*raData,
*hd,
)
rly.Config = &rlyCfg

bytes, err := os.ReadFile(rly.StatusFilePath())
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions relayer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ type Paths struct {
} `yaml:"hub-rollapp"`
}

func (c *Config) Load(rlyConfigPath string) error {
fmt.Println("loading config from", rlyConfigPath)
data, err := os.ReadFile(rlyConfigPath)
if err != nil {
return err
}

err = yaml.Unmarshal(data, c)
if err != nil {
return err
}

return nil
}

func (c *Config) GetPath() *Paths {
if c.Paths == nil || c.Paths.HubRollapp == nil {
return nil
Expand Down
18 changes: 0 additions & 18 deletions relayer/relayer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"os"
"path/filepath"

yaml "gopkg.in/yaml.v3"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/roller"
)
Expand All @@ -31,8 +29,6 @@ type Relayer struct {
SrcClientID string
DstClientID string

Config *Config

logger *log.Logger
}

Expand Down Expand Up @@ -86,17 +82,3 @@ type ConnectionChannels struct {
Src string
Dst string
}

func (c *Config) Load(rlyConfigPath string) error {
data, err := os.ReadFile(rlyConfigPath)
if err != nil {
return err
}

err = yaml.Unmarshal(data, c)
if err != nil {
return err
}

return nil
}

0 comments on commit 2ce9d08

Please sign in to comment.