Skip to content

Commit

Permalink
configurable homedir in ClientCtx, remove global var
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed Oct 28, 2024
1 parent 6272619 commit e7603cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
12 changes: 0 additions & 12 deletions simapp/v2/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
_ "embed"
"fmt"

clienthelpers "cosmossdk.io/client/v2/helpers"
"cosmossdk.io/core/registry"
"cosmossdk.io/core/server"
"cosmossdk.io/core/transaction"
Expand All @@ -27,9 +26,6 @@ import (
_ "github.com/cosmos/cosmos-sdk/x/genutil"
)

// DefaultNodeHome default home directories for the application daemon
var DefaultNodeHome string

// SimApp extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
Expand All @@ -47,14 +43,6 @@ type SimApp[T transaction.Tx] struct {
StakingKeeper *stakingkeeper.Keeper
}

func init() {
var err error
DefaultNodeHome, err = clienthelpers.GetNodeHomeDirectory(".simappv2")
if err != nil {
panic(err)
}
}

// AppConfig returns the default app config.
func AppConfig() depinject.Config {
return depinject.Configs(
Expand Down
10 changes: 8 additions & 2 deletions simapp/v2/simdv2/cmd/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (

"cosmossdk.io/core/address"
"cosmossdk.io/core/registry"
"cosmossdk.io/simapp/v2"
"cosmossdk.io/runtime/v2"
serverv2 "cosmossdk.io/server/v2"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
Expand All @@ -18,6 +19,7 @@ import (

// ProvideClientContext is a depinject Provider function which assembles and returns a client.Context.
func ProvideClientContext(
configMap runtime.GlobalConfig,
appCodec codec.Codec,
interfaceRegistry codectypes.InterfaceRegistry,
txConfigOpts tx.ConfigOptions,
Expand All @@ -31,6 +33,10 @@ func ProvideClientContext(
if !ok {
panic("registry.AminoRegistrar must be an *codec.LegacyAmino instance for legacy ClientContext")
}
homeDir, ok := configMap[serverv2.FlagHome].(string)
if !ok {
panic("server.ConfigMap must contain a string value for serverv2.FlagHome")
}

clientCtx := client.Context{}.
WithCodec(appCodec).
Expand All @@ -41,7 +47,7 @@ func ProvideClientContext(
WithAddressCodec(addressCodec).
WithValidatorAddressCodec(validatorAddressCodec).
WithConsensusAddressCodec(consensusAddressCodec).
WithHomeDir(simapp.DefaultNodeHome).
WithHomeDir(homeDir).
WithViper("") // uses by default the binary name as prefix

// Read the config to overwrite the default values with the values from the config file
Expand Down

0 comments on commit e7603cf

Please sign in to comment.