Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
chore: add initialization function for Config struct
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id committed Nov 27, 2023
1 parent bea935e commit 408de1d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
48 changes: 24 additions & 24 deletions cmd/blobstream/query/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,24 +519,24 @@ func tryToGetExistingConfig(cmd *cobra.Command, logger tmlog.Logger) (Config, er
orchConf, err := orchestrator.GetStartConfig(v, configPath)
if err == nil {
// it is an orchestrator, so we get the config from it
return Config{
coreGRPC: orchConf.CoreGRPC,
coreRPC: orchConf.CoreRPC,
targetNode: orchConf.Bootstrappers,
grpcInsecure: orchConf.GRPCInsecure,
}, nil
return *NewPartialConfig(
orchConf.CoreGRPC,
orchConf.CoreRPC,
orchConf.Bootstrappers,
orchConf.GRPCInsecure,
), nil
}

// assume this home is a relayer home directory
relConf, err := relayer.GetStartConfig(v, configPath)
if err == nil {
// it is a relayer, so we get the config from it
return Config{
coreGRPC: relConf.CoreGRPC,
coreRPC: relConf.CoreRPC,
targetNode: relConf.Bootstrappers,
grpcInsecure: relConf.GrpcInsecure,
}, nil
return *NewPartialConfig(
relConf.CoreGRPC,
relConf.CoreRPC,
relConf.Bootstrappers,
relConf.GrpcInsecure,
), nil
}
return Config{}, fmt.Errorf("the provided home directory is neither an orchestrator nor a relayer home directory")
}
Expand All @@ -549,12 +549,12 @@ func tryToGetExistingConfig(cmd *cobra.Command, logger tmlog.Logger) (Config, er
if err == nil {
// found orchestrator home, get the config from it
logger.Debug("using home", "home", orchHome)
return Config{
coreGRPC: orchConf.CoreGRPC,
coreRPC: orchConf.CoreRPC,
targetNode: orchConf.Bootstrappers,
grpcInsecure: orchConf.GRPCInsecure,
}, nil
return *NewPartialConfig(
orchConf.CoreGRPC,
orchConf.CoreRPC,
orchConf.Bootstrappers,
orchConf.GRPCInsecure,
), nil
}

// try to get the config from the relayer home directory
Expand All @@ -566,12 +566,12 @@ func tryToGetExistingConfig(cmd *cobra.Command, logger tmlog.Logger) (Config, er
if err == nil {
// found relayer home, so we get the config from it
logger.Debug("using home", "home", relHome)
return Config{
coreGRPC: relConf.CoreGRPC,
coreRPC: relConf.CoreRPC,
targetNode: relConf.Bootstrappers,
grpcInsecure: relConf.GrpcInsecure,
}, nil
return *NewPartialConfig(
relConf.CoreGRPC,
relConf.CoreRPC,
relConf.Bootstrappers,
relConf.GrpcInsecure,
), nil
}

return *DefaultConfig(), nil
Expand Down
9 changes: 9 additions & 0 deletions cmd/blobstream/query/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ type Config struct {
grpcInsecure bool
}

func NewPartialConfig(coreGRPC, coreRPC, targetNode string, grpcInsecure bool) *Config {
return &Config{
coreGRPC: coreGRPC,
coreRPC: coreRPC,
targetNode: targetNode,
grpcInsecure: grpcInsecure,
}
}

func DefaultConfig() *Config {
return &Config{
coreGRPC: "localhost:9090",
Expand Down

0 comments on commit 408de1d

Please sign in to comment.