-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add autocli app wiring + remote info support (#13281)
- Loading branch information
Showing
21 changed files
with
429 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package autocli | ||
|
||
import ( | ||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" | ||
"github.com/spf13/cobra" | ||
|
||
"cosmossdk.io/core/appmodule" | ||
) | ||
|
||
// HasAutoCLIConfig is an AppModule extension interface for declaring autocli module options. | ||
type HasAutoCLIConfig interface { | ||
appmodule.AppModule | ||
|
||
// AutoCLIOptions are the autocli module options for this module. | ||
AutoCLIOptions() *autocliv1.ModuleOptions | ||
} | ||
|
||
// HasCustomQueryCommand is an AppModule extension interface for declaring a custom query command. | ||
type HasCustomQueryCommand interface { | ||
appmodule.AppModule | ||
|
||
// GetQueryCmd returns a custom cobra query command for this module. | ||
GetQueryCmd() *cobra.Command | ||
} | ||
|
||
// HasCustomTxCommand is an AppModule extension interface for declaring a custom tx command. | ||
type HasCustomTxCommand interface { | ||
appmodule.AppModule | ||
|
||
// GetTxCmd returns a custom cobra tx command for this module. | ||
GetTxCmd() *cobra.Command | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
|
||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" | ||
) | ||
|
||
// AppQueryService implements the cosmos.app.v1alpha1.Query service | ||
type AppQueryService struct { | ||
appv1alpha1.UnimplementedQueryServer | ||
appConfig *appv1alpha1.Config | ||
} | ||
|
||
func NewAppQueryService(appConfig *appv1alpha1.Config) *AppQueryService { | ||
return &AppQueryService{appConfig: appConfig} | ||
} | ||
|
||
func (a *AppQueryService) Config(context.Context, *appv1alpha1.QueryConfigRequest) (*appv1alpha1.QueryConfigResponse, error) { | ||
return &appv1alpha1.QueryConfigResponse{Config: a.appConfig}, nil | ||
} | ||
|
||
var _ appv1alpha1.QueryServer = &AppQueryService{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
|
||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" | ||
"cosmossdk.io/core/appmodule" | ||
) | ||
|
||
// AutoCLIQueryService implements the cosmos.autocli.v1.Query service. | ||
type AutoCLIQueryService struct { | ||
autocliv1.UnimplementedQueryServer | ||
|
||
moduleOptions map[string]*autocliv1.ModuleOptions | ||
} | ||
|
||
func NewAutoCLIQueryService(appModules map[string]appmodule.AppModule) *AutoCLIQueryService { | ||
moduleOptions := map[string]*autocliv1.ModuleOptions{} | ||
for modName, mod := range appModules { | ||
if autoCliMod, ok := mod.(interface { | ||
AutoCLIOptions() *autocliv1.ModuleOptions | ||
}); ok { | ||
moduleOptions[modName] = autoCliMod.AutoCLIOptions() | ||
} | ||
} | ||
return &AutoCLIQueryService{ | ||
moduleOptions: moduleOptions, | ||
} | ||
} | ||
|
||
func (a AutoCLIQueryService) AppOptions(context.Context, *autocliv1.AppOptionsRequest) (*autocliv1.AppOptionsResponse, error) { | ||
return &autocliv1.AppOptionsResponse{ | ||
ModuleOptions: a.moduleOptions, | ||
}, nil | ||
} | ||
|
||
var _ autocliv1.QueryServer = &AutoCLIQueryService{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package services | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"context" | ||
"io" | ||
|
||
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" | ||
"github.com/cosmos/gogoproto/proto" | ||
"golang.org/x/exp/slices" | ||
protov2 "google.golang.org/protobuf/proto" | ||
"google.golang.org/protobuf/reflect/protodesc" | ||
"google.golang.org/protobuf/reflect/protoreflect" | ||
"google.golang.org/protobuf/reflect/protoregistry" | ||
"google.golang.org/protobuf/types/descriptorpb" | ||
) | ||
|
||
// ReflectionService implements the cosmos.reflection.v1 service. | ||
type ReflectionService struct { | ||
reflectionv1.UnimplementedReflectionServiceServer | ||
files *descriptorpb.FileDescriptorSet | ||
} | ||
|
||
func NewReflectionService() (*ReflectionService, error) { | ||
fds := &descriptorpb.FileDescriptorSet{} | ||
|
||
// load gogo proto file descriptors | ||
allFds := proto.AllFileDescriptors() | ||
haveFileDescriptor := map[string]bool{} | ||
for _, compressedBz := range allFds { | ||
rdr, err := gzip.NewReader(bytes.NewReader(compressedBz)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
bz, err := io.ReadAll(rdr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fd := &descriptorpb.FileDescriptorProto{} | ||
err = protov2.Unmarshal(bz, fd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fds.File = append(fds.File, fd) | ||
haveFileDescriptor[*fd.Name] = true | ||
} | ||
|
||
// load any protoregistry file descriptors not in gogo | ||
protoregistry.GlobalFiles.RangeFiles(func(fileDescriptor protoreflect.FileDescriptor) bool { | ||
if !haveFileDescriptor[fileDescriptor.Path()] { | ||
fds.File = append(fds.File, protodesc.ToFileDescriptorProto(fileDescriptor)) | ||
} | ||
return true | ||
}) | ||
|
||
slices.SortFunc(fds.File, func(x, y *descriptorpb.FileDescriptorProto) bool { | ||
return *x.Name < *y.Name | ||
}) | ||
|
||
return &ReflectionService{files: fds}, nil | ||
} | ||
|
||
func (r ReflectionService) FileDescriptors(_ context.Context, _ *reflectionv1.FileDescriptorsRequest) (*reflectionv1.FileDescriptorsResponse, error) { | ||
return &reflectionv1.FileDescriptorsResponse{ | ||
Files: r.files.File, | ||
}, nil | ||
} | ||
|
||
var _ reflectionv1.ReflectionServiceServer = &ReflectionService{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package runtime | ||
|
||
import ( | ||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" | ||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" | ||
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" | ||
|
||
"github.com/cosmos/cosmos-sdk/runtime/internal/services" | ||
) | ||
|
||
func (a *App) registerRuntimeServices() error { | ||
appv1alpha1.RegisterQueryServer(a.GRPCQueryRouter(), services.NewAppQueryService(a.appConfig)) | ||
autocliv1.RegisterQueryServer(a.GRPCQueryRouter(), services.NewAutoCLIQueryService(a.appModules)) | ||
|
||
reflectionSvc, err := services.NewReflectionService() | ||
if err != nil { | ||
return err | ||
} | ||
reflectionv1.RegisterReflectionServiceServer(a.GRPCQueryRouter(), reflectionSvc) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.