refactor: fetch CometInfo from service (#20238)
Co-authored-by: Marko <marko@baricevic.me>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
corecomet "cosmossdk.io/core/comet"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var _ corecomet.Service = &ContextAwareCometInfoService{}
|
||||
|
||||
// ContextAwareCometInfoService provides CometInfo which is embedded as a value in a Context.
|
||||
// This the legacy (server v1, baseapp) way of accessing CometInfo at the module level.
|
||||
type ContextAwareCometInfoService struct{}
|
||||
|
||||
func (c ContextAwareCometInfoService) CometInfo(ctx context.Context) corecomet.Info {
|
||||
return sdk.UnwrapSDKContext(ctx).CometInfo()
|
||||
}
|
||||
|
||||
func NewContextAwareCometInfoService() *ContextAwareCometInfoService {
|
||||
return &ContextAwareCometInfoService{}
|
||||
}
|
||||
@@ -35,7 +35,10 @@ func NewEnvironment(
|
||||
|
||||
type EnvOption func(*appmodule.Environment)
|
||||
|
||||
func EnvWithRouterService(queryServiceRouter *baseapp.GRPCQueryRouter, msgServiceRouter *baseapp.MsgServiceRouter) EnvOption {
|
||||
func EnvWithRouterService(
|
||||
queryServiceRouter *baseapp.GRPCQueryRouter,
|
||||
msgServiceRouter *baseapp.MsgServiceRouter,
|
||||
) EnvOption {
|
||||
return func(env *appmodule.Environment) {
|
||||
env.RouterService = NewRouterService(env.KVStoreService, queryServiceRouter, msgServiceRouter)
|
||||
}
|
||||
|
||||
+16
-2
@@ -16,6 +16,7 @@ import (
|
||||
stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/comet"
|
||||
"cosmossdk.io/core/genesis"
|
||||
"cosmossdk.io/core/store"
|
||||
"cosmossdk.io/depinject"
|
||||
@@ -101,6 +102,7 @@ func init() {
|
||||
ProvideModuleManager,
|
||||
ProvideAppVersionModifier,
|
||||
ProvideAddressCodec,
|
||||
ProvideCometService,
|
||||
),
|
||||
appconfig.Invoke(SetupAppBuilder),
|
||||
)
|
||||
@@ -172,7 +174,11 @@ func SetupAppBuilder(inputs AppInputs) {
|
||||
app.ModuleManager.RegisterLegacyAminoCodec(inputs.LegacyAmino)
|
||||
}
|
||||
|
||||
func ProvideInterfaceRegistry(addressCodec address.Codec, validatorAddressCodec address.ValidatorAddressCodec, customGetSigners []signing.CustomGetSigner) (codectypes.InterfaceRegistry, error) {
|
||||
func ProvideInterfaceRegistry(
|
||||
addressCodec address.Codec,
|
||||
validatorAddressCodec address.ValidatorAddressCodec,
|
||||
customGetSigners []signing.CustomGetSigner,
|
||||
) (codectypes.InterfaceRegistry, error) {
|
||||
signingOptions := signing.Options{
|
||||
AddressCodec: addressCodec,
|
||||
ValidatorAddressCodec: validatorAddressCodec,
|
||||
@@ -209,7 +215,11 @@ func storeKeyOverride(config *runtimev1alpha1.Module, moduleName string) *runtim
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProvideKVStoreKey(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) *storetypes.KVStoreKey {
|
||||
func ProvideKVStoreKey(
|
||||
config *runtimev1alpha1.Module,
|
||||
key depinject.ModuleKey,
|
||||
app *AppBuilder,
|
||||
) *storetypes.KVStoreKey {
|
||||
override := storeKeyOverride(config, key.Name())
|
||||
|
||||
var storeKeyName string
|
||||
@@ -275,6 +285,10 @@ func ProvideAppVersionModifier(app *AppBuilder) baseapp.AppVersionModifier {
|
||||
return app.app
|
||||
}
|
||||
|
||||
func ProvideCometService() comet.Service {
|
||||
return NewContextAwareCometInfoService()
|
||||
}
|
||||
|
||||
type AddressCodecInputs struct {
|
||||
depinject.In
|
||||
|
||||
|
||||
Reference in New Issue
Block a user