refactor(core,server): make commands not rely on server context (#20422)

Co-authored-by: Hieu Vu <72878483+hieuvubk@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
Marko
2024-05-28 13:07:36 +00:00
committed by GitHub
co-authored by Hieu Vu Julien Robert
parent 1b47dc91a3
commit e6e1a853de
31 changed files with 268 additions and 132 deletions
+7 -1
View File
@@ -24,6 +24,7 @@ import (
"github.com/spf13/viper"
"golang.org/x/sync/errgroup"
corectx "cosmossdk.io/core/context"
corelog "cosmossdk.io/core/log"
"cosmossdk.io/log"
"cosmossdk.io/store"
@@ -46,6 +47,7 @@ import (
const ServerContextKey = sdk.ContextKey("server.context")
// Context server context
// Deprecated: Do not use since we use viper to track all config
type Context struct {
Viper *viper.Viper
Config *cmtcfg.Config
@@ -224,7 +226,11 @@ func SetCmdServerContext(cmd *cobra.Command, serverCtx *Context) error {
cmdCtx = cmd.Context()
}
cmd.SetContext(context.WithValue(cmdCtx, ServerContextKey, serverCtx))
cmdCtx = context.WithValue(cmdCtx, ServerContextKey, serverCtx)
cmdCtx = context.WithValue(cmdCtx, corectx.ViperContextKey{}, serverCtx.Viper)
cmdCtx = context.WithValue(cmdCtx, corectx.LoggerContextKey{}, serverCtx.Logger)
cmd.SetContext(cmdCtx)
return nil
}