Skip to content

Commit

Permalink
Make app runnable without creating default home dir
Browse files Browse the repository at this point in the history
  • Loading branch information
roy-dydx committed Feb 9, 2024
1 parent 4820ea7 commit e0ad073
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions protocol/cmd/dydxprotocold/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ const (
// TODO(DEC-1097): improve `cmd/` by adding tests, custom app configs, custom init cmd, and etc.
func NewRootCmd(
option *RootCmdOption,
homeDir string,
) *cobra.Command {
return NewRootCmdWithInterceptors(
option,
homeDir,
func(serverCtxPtr *server.Context) {

},
Expand All @@ -80,7 +78,6 @@ func NewRootCmd(

func NewRootCmdWithInterceptors(
option *RootCmdOption,
homeDir string,
serverCtxInterceptor func(serverCtxPtr *server.Context),
appConfigInterceptor func(string, *DydxAppConfig) (string, *DydxAppConfig),
appInterceptor func(app *dydxapp.App) *dydxapp.App,
Expand All @@ -106,7 +103,7 @@ func NewRootCmdWithInterceptors(
WithInput(os.Stdin).
WithAccountRetriever(types.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastSync).
WithHomeDir(homeDir).
WithHomeDir(tempDir()).
WithViper(EnvPrefix)

rootCmd := &cobra.Command{
Expand Down Expand Up @@ -164,6 +161,7 @@ func NewRootCmdWithInterceptors(
if err != nil {
panic(err)
}
initClientCtx.HomeDir = ""
if err := autoCliOpts(tempApp, initClientCtx).EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}
Expand Down Expand Up @@ -423,3 +421,13 @@ func appExport(

return dydxApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
}

var tempDir = func() string {
dir, err := os.MkdirTemp("", "dydxprotocol")
if err != nil {
dir = dydxapp.DefaultNodeHome
}
defer os.RemoveAll(dir)

return dir
}
2 changes: 1 addition & 1 deletion protocol/cmd/dydxprotocold/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
config.SetupConfig()

option := cmd.GetOptionWithCustomStartCmd()
rootCmd := cmd.NewRootCmd(option, app.DefaultNodeHome)
rootCmd := cmd.NewRootCmd(option)

cmd.AddTendermintSubcommands(rootCmd)
cmd.AddInitCmdPostRunE(rootCmd)
Expand Down

0 comments on commit e0ad073

Please sign in to comment.