Skip to content

Commit

Permalink
write store config to app.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuvubk committed Jun 20, 2024
1 parent 974e3f9 commit 3ae993a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/v2/store/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`,
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
// bind flags to the Context's Viper so we can get pruning options.
vp := viper.New()
vp := serverv2.GetViperFromCmd(cmd)
if err := vp.BindPFlags(cmd.Flags()); err != nil {
return err
}
Expand Down
22 changes: 22 additions & 0 deletions server/v2/store/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package store

import (
pruningtypes "cosmossdk.io/store/pruning/types"
)

func DefaultConfig() *Config {
return &Config{
Pruning: pruningtypes.PruningOptionDefault,
AppDBBackend: "",
PruningKeepRecent: 0,
PruningInterval: 0,
}
}


type Config struct {
Pruning string `mapstructure:"pruning" toml:"pruning"`
AppDBBackend string `mapstructure:"app-db-backend" toml:"app-db-backend"`
PruningKeepRecent uint64 `mapstructure:"pruning-keep-recent" toml:"pruning-keep-recent"`
PruningInterval uint64 `mapstructure:"pruning-interval" toml:"pruning-interval"`
}
12 changes: 11 additions & 1 deletion server/v2/store/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
serverv2 "cosmossdk.io/server/v2"
)

type StoreComponent struct{}
type StoreComponent struct{
config *Config
}

func New() serverv2.ServerComponent[transaction.Tx] {
return StoreComponent{}
Expand Down Expand Up @@ -40,3 +42,11 @@ func (s StoreComponent) CLICommands(appCreator serverv2.AppCreator[transaction.T
},
}
}

func (g StoreComponent) Config() any {
if g.config == nil || g.config == (&Config{}) {
return DefaultConfig()
}

return g.config
}

0 comments on commit 3ae993a

Please sign in to comment.