cosmos-sdk/server/v2/store/server.go
Aaron Craelius 5c90246b3f
feat(log): remove core dependency and update core interface to be dependency free (#21045)
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
2024-07-26 11:00:27 +00:00

77 lines
1.4 KiB
Go

package store
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"cosmossdk.io/core/transaction"
"cosmossdk.io/log"
serverv2 "cosmossdk.io/server/v2"
)
// StoreComponent manages store config
// and contains prune & snapshot commands
type StoreComponent[T transaction.Tx] struct {
config *Config
}
func New[T transaction.Tx]() *StoreComponent[T] {
return &StoreComponent[T]{}
}
func (s *StoreComponent[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logger) error {
cfg := DefaultConfig()
if v != nil {
if err := v.Sub(s.Name()).Unmarshal(&cfg); err != nil {
return fmt.Errorf("failed to unmarshal config: %w", err)
}
}
s.config = cfg
return nil
}
func (s *StoreComponent[T]) Name() string {
return "store"
}
func (s *StoreComponent[T]) Start(ctx context.Context) error {
return nil
}
func (s *StoreComponent[T]) Stop(ctx context.Context) error {
return nil
}
func (s *StoreComponent[T]) GetCommands() []*cobra.Command {
return []*cobra.Command{
s.PrunesCmd(),
}
}
func (s *StoreComponent[T]) GetTxs() []*cobra.Command {
return nil
}
func (s *StoreComponent[T]) GetQueries() []*cobra.Command {
return nil
}
func (s *StoreComponent[T]) CLICommands() serverv2.CLIConfig {
return serverv2.CLIConfig{
Commands: []*cobra.Command{
s.PrunesCmd(),
},
}
}
func (g *StoreComponent[T]) Config() any {
if g.config == nil || g.config == (&Config{}) {
return DefaultConfig()
}
return g.config
}