Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions cmd/cylinder/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/hex"
"fmt"
"os"
"path"
"path/filepath"
Expand All @@ -15,6 +16,7 @@ import (

"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -90,7 +92,7 @@ func createPersistentPreRunE(rootCmd *cobra.Command, ctx *context.Context) func(
cmd *cobra.Command,
args []string,
) error {
return func(_ *cobra.Command, _ []string) error {
return func(c *cobra.Command, _ []string) error {
// create home directory
home, err := rootCmd.PersistentFlags().GetString(flags.FlagHome)
if err != nil {
Expand Down Expand Up @@ -142,7 +144,27 @@ func createPersistentPreRunE(rootCmd *cobra.Command, ctx *context.Context) func(
}
*ctx = *newCtx

return initConfig(ctx, rootCmd)
if err := initConfig(ctx, rootCmd); err != nil {
return err
}

// set up client context if nodeURI is provided
if ctx.Config.NodeURI != "" {
clientCtx := client.GetClientContextFromCmd(c)

newClient, err := client.NewClientFromNode(ctx.Config.NodeURI)
if err != nil {
return fmt.Errorf("couldn't get client from nodeURI: %v", err)
}

clientCtx = clientCtx.WithNodeURI(ctx.Config.NodeURI).WithClient(newClient)

if err := client.SetCmdClientContext(c, clientCtx); err != nil {
return err
}
}

return nil
}
}

Expand Down
28 changes: 26 additions & 2 deletions yoda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -88,7 +89,8 @@ func Main() {
runCmd(ctx),
version.NewVersionCommand(),
)
rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {

rootCmd.PersistentPreRunE = func(c *cobra.Command, _ []string) error {
home, err := rootCmd.PersistentFlags().GetString(flags.FlagHome)
if err != nil {
return err
Expand Down Expand Up @@ -131,8 +133,30 @@ func Main() {
if err != nil {
return err
}
return initConfig(ctx)

// read config
if err := initConfig(ctx); err != nil {
return err
}

// set up client context if nodeURI is provided
if cfg.NodeURI != "" {
clientCtx := client.GetClientContextFromCmd(c)

newClient, err := client.NewClientFromNode(cfg.NodeURI)
if err != nil {
return fmt.Errorf("couldn't get client from nodeURI: %v", err)
}

clientCtx = clientCtx.WithNodeURI(cfg.NodeURI).WithClient(newClient)
if err := client.SetCmdClientContext(c, clientCtx); err != nil {
return err
}
}

return nil
}

rootCmd.PersistentFlags().String(flags.FlagHome, DefaultYodaHome, "home directory")
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
Loading