feat: add basic autocli config to every module (#13786)
* feat: add autocli configs to every module * auto-discover config * tests + gov, auth config tweaks * docs * Update x/auth/autocli.go Co-authored-by: Julien Robert <julien@rbrt.fr> * Update x/auth/autocli.go Co-authored-by: Julien Robert <julien@rbrt.fr> * cleanup Co-authored-by: Julien Robert <julien@rbrt.fr> Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
This commit is contained in:
co-authored by
Julien Robert
Amaury
parent
4f7d9ea233
commit
bcdf81cbaf
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
gogogrpc "github.com/cosmos/gogoproto/grpc"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
)
|
||||
@@ -22,6 +24,31 @@ func NewAutoCLIQueryService(appModules map[string]module.AppModule) *AutoCLIQuer
|
||||
AutoCLIOptions() *autocliv1.ModuleOptions
|
||||
}); ok {
|
||||
moduleOptions[modName] = autoCliMod.AutoCLIOptions()
|
||||
} else {
|
||||
// try to auto-discover options based on the last msg and query
|
||||
// services registered for the module
|
||||
cfg := &autocliConfigurator{}
|
||||
mod.RegisterServices(cfg)
|
||||
modOptions := &autocliv1.ModuleOptions{}
|
||||
haveServices := false
|
||||
|
||||
if cfg.msgServer.serviceName != "" {
|
||||
haveServices = true
|
||||
modOptions.Tx = &autocliv1.ServiceCommandDescriptor{
|
||||
Service: cfg.msgServer.serviceName,
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.queryServer.serviceName != "" {
|
||||
haveServices = true
|
||||
modOptions.Query = &autocliv1.ServiceCommandDescriptor{
|
||||
Service: cfg.queryServer.serviceName,
|
||||
}
|
||||
}
|
||||
|
||||
if haveServices {
|
||||
moduleOptions[modName] = modOptions
|
||||
}
|
||||
}
|
||||
}
|
||||
return &AutoCLIQueryService{
|
||||
@@ -35,4 +62,27 @@ func (a AutoCLIQueryService) AppOptions(context.Context, *autocliv1.AppOptionsRe
|
||||
}, nil
|
||||
}
|
||||
|
||||
// autocliConfigurator allows us to call RegisterServices and introspect the services
|
||||
type autocliConfigurator struct {
|
||||
msgServer autocliServiceRegistrar
|
||||
queryServer autocliServiceRegistrar
|
||||
}
|
||||
|
||||
func (a *autocliConfigurator) MsgServer() gogogrpc.Server { return &a.msgServer }
|
||||
|
||||
func (a *autocliConfigurator) QueryServer() gogogrpc.Server { return &a.queryServer }
|
||||
|
||||
func (a *autocliConfigurator) RegisterMigration(string, uint64, module.MigrationHandler) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// autocliServiceRegistrar is used to capture the service name for registered services
|
||||
type autocliServiceRegistrar struct {
|
||||
serviceName string
|
||||
}
|
||||
|
||||
func (a *autocliServiceRegistrar) RegisterService(sd *grpc.ServiceDesc, _ interface{}) {
|
||||
a.serviceName = sd.ServiceName
|
||||
}
|
||||
|
||||
var _ autocliv1.QueryServer = &AutoCLIQueryService{}
|
||||
|
||||
Reference in New Issue
Block a user