Skip to content

Commit

Permalink
save appCreator in store component
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuvubk committed Aug 6, 2024
1 parent de47370 commit 4735146
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
9 changes: 6 additions & 3 deletions server/v2/store/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import (
// StoreComponent manages store config
// and contains prune & snapshot commands
type StoreComponent[T transaction.Tx] struct {
config *Config
config *Config
// saving appCreator for only RestoreSnapshotCmd
appCreator serverv2.AppCreator[T]
}

func New[T transaction.Tx]() *StoreComponent[T] {
return &StoreComponent[T]{}
func New[T transaction.Tx](appCreator serverv2.AppCreator[T]) *StoreComponent[T] {
return &StoreComponent[T]{appCreator: appCreator}
}

func (s *StoreComponent[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logger) error {
Expand Down Expand Up @@ -54,6 +56,7 @@ func (s *StoreComponent[T]) CLICommands() serverv2.CLIConfig {
s.ListSnapshotsCmd(),
s.DumpArchiveCmd(),
s.LoadArchiveCmd(),
s.RestoreSnapshotCmd(s.appCreator),
},
}
}
Expand Down
10 changes: 1 addition & 9 deletions simapp/v2/simdv2/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func initRootCmd[T transaction.Tx](
offchain.OffChain(),
)

storeComponent := store.New[T]()
storeComponent := store.New[T](newApp)
// wire server commands
if err = serverv2.AddCommands(
rootCmd,
Expand All @@ -80,14 +80,6 @@ func initRootCmd[T transaction.Tx](
); err != nil {
panic(err)
}

// Add RestoreSnapshotCmd separately cause need appCreator
for _, cmd := range rootCmd.Commands() {
if cmd.Use == storeComponent.Name() {
cmd.AddCommand(storeComponent.RestoreSnapshotCmd(newApp))
break
}
}
}

// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter
Expand Down
4 changes: 2 additions & 2 deletions simapp/v2/simdv2/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func initTestnetFiles[T transaction.Tx](
cometbft.ServerOptions[T]{},
cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig),
)
storeServer := store.New[T]()
storeServer := store.New[T](newApp)
grpcServer := grpc.New[T](grpc.OverwriteDefaultConfig(grpcConfig))
server := serverv2.NewServer(log.NewNopLogger(), cometServer, grpcServer, storeServer)
err = server.WriteConfig(filepath.Join(nodeDir, "config"))
Expand All @@ -366,7 +366,7 @@ func initTestnetFiles[T transaction.Tx](
}

// Update viper root since root dir become rootdir/node/simd
client.GetViperFromCmd(cmd).Set(flags.FlagHome, nodeConfig.RootDir)
serverv2.GetViperFromCmd(cmd).Set(flags.FlagHome, nodeConfig.RootDir)

cmd.PrintErrf("Successfully initialized %d node directories\n", args.numValidators)
return nil
Expand Down

0 comments on commit 4735146

Please sign in to comment.