From f0ffc21734e5cda6e53b40ff283152f366a5ceae Mon Sep 17 00:00:00 2001 From: puneetmahajan Date: Thu, 28 Aug 2025 18:36:46 +0530 Subject: [PATCH 1/2] fix default home path, so it always picks from client --- app/app.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/app.go b/app/app.go index 6c495d20..bd81d804 100644 --- a/app/app.go +++ b/app/app.go @@ -6,18 +6,18 @@ package app import ( - "cosmossdk.io/client/v2/autocli" - "cosmossdk.io/core/appmodule" "encoding/json" "fmt" - "github.com/cosmos/cosmos-sdk/codec/address" "io" - stdlog "log" - "os" "path/filepath" "reflect" "strings" + "cosmossdk.io/client/v2/autocli" + clienthelpers "cosmossdk.io/client/v2/helpers" + "cosmossdk.io/core/appmodule" + "github.com/cosmos/cosmos-sdk/codec/address" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/log" @@ -75,12 +75,11 @@ var ( ) func init() { - userHomeDir, err := os.UserHomeDir() + var err error + DefaultNodeHome, err = clienthelpers.GetNodeHomeDirectory(".persistenceCore") if err != nil { - stdlog.Println("Failed to get home dir %2", err) + panic(err) } - - DefaultNodeHome = filepath.Join(userHomeDir, ".persistenceCore") } type Application struct { From e93c3511ae313a362c63c52304eb1b79c3782571 Mon Sep 17 00:00:00 2001 From: puneetmahajan Date: Thu, 28 Aug 2025 19:56:01 +0530 Subject: [PATCH 2/2] add temp dir which can be written and deleted after tempapp usage --- cmd/persistenceCore/cmd/root.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/cmd/persistenceCore/cmd/root.go b/cmd/persistenceCore/cmd/root.go index b516420a..5507a027 100644 --- a/cmd/persistenceCore/cmd/root.go +++ b/cmd/persistenceCore/cmd/root.go @@ -5,8 +5,8 @@ import ( "io" "os" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/snapshot" - "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/persistenceOne/persistenceCore/v13/app/constants" "cosmossdk.io/log" @@ -16,7 +16,6 @@ import ( cmtcfg "github.com/cometbft/cometbft/config" cmtcli "github.com/cometbft/cometbft/libs/cli" dbm "github.com/cosmos/cosmos-db" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" "github.com/cosmos/cosmos-sdk/client/flags" @@ -26,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" @@ -60,7 +60,19 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { WithHomeDir(app.DefaultNodeHome). WithViper("") - tempApp := app.NewApplication(log.NewNopLogger(), dbm.NewMemDB(), nil, true, sims.EmptyAppOptions{}, []wasm.Option{}) + tempDir := tempDir() + tempApp := app.NewApplication(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(tempDir), []wasm.Option{}) + defer func() { + if err := tempApp.Close(); err != nil { + panic(err) + } + if tempDir != app.DefaultNodeHome { + err := os.RemoveAll(tempDir) + if err != nil { + panic(err) + } + } + }() cobra.EnableCommandSorting = false @@ -295,3 +307,13 @@ func appExport( return persistenceApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) } + +// tempDir create a temporary directory to initialize the command line client +func tempDir() string { + dir, err := os.MkdirTemp("", "persistenceCore") + if err != nil { + panic("failed to create temp dir: " + err.Error()) + } + + return dir +}