Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client/v2): add autocli run + simapp example #13867

Merged
merged 43 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e5fb21f
feat(client/v2): add autocli run + simapp example
aaronc Nov 14, 2022
7da30d6
working simcli
aaronc Nov 14, 2022
d8ba54e
feat: add --grpc client option
aaronc Nov 28, 2022
3c1db4d
updates
aaronc Nov 28, 2022
2263135
default to TLS credentials
aaronc Nov 29, 2022
42f5ca2
add min version because of gosec lint
aaronc Nov 29, 2022
3ad4141
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/autoc…
aaronc Nov 30, 2022
33a5690
revert
aaronc Nov 30, 2022
b789624
integrate existing query cmd flags
aaronc Dec 1, 2022
2d60aa2
Merge branch 'aaronc/grpc-client-flag' into aaronc/autocli-simapp
aaronc Dec 5, 2022
4b40a9a
update go.mod
aaronc Dec 7, 2022
a4ffbf0
use depinject directly in simd
aaronc Dec 7, 2022
b866214
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/autoc…
aaronc Dec 7, 2022
c72bf5c
revert
aaronc Dec 7, 2022
ac3d37b
WIP on integrating with existing simd
aaronc Dec 7, 2022
f02c195
WIP on integrating with existing simd
aaronc Dec 7, 2022
2524014
WIP on integrating with existing simd
aaronc Dec 7, 2022
59f2461
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/autoc…
aaronc Dec 14, 2022
89d0307
cleanup
aaronc Dec 14, 2022
cffaf88
docs, cleanup
aaronc Dec 14, 2022
17e2139
docs
aaronc Dec 14, 2022
8de75bc
docs
aaronc Dec 14, 2022
ac99c30
fix
aaronc Dec 14, 2022
83868c5
improve support for non-depinject users
aaronc Dec 15, 2022
dfc597e
Merge remote-tracking branch 'origin' into aaronc/autocli-simapp
julienrbrt Dec 20, 2022
987a503
do not leak depinject outside app_v2 in simapp
julienrbrt Dec 20, 2022
d3091bc
go mod tidy
julienrbrt Dec 20, 2022
00de5fe
improve naming
julienrbrt Dec 20, 2022
784ab01
fix tests
julienrbrt Dec 20, 2022
64013ed
fix tests
julienrbrt Dec 20, 2022
460725c
updates
julienrbrt Dec 20, 2022
a6fa258
Merge branch 'main' into aaronc/autocli-simapp
julienrbrt Dec 20, 2022
64886ed
updates
julienrbrt Dec 20, 2022
49f6e12
updates
julienrbrt Dec 20, 2022
ee76b3e
clean-up
julienrbrt Dec 20, 2022
60e24d4
Merge branch 'main' into aaronc/autocli-simapp
julienrbrt Dec 21, 2022
b81c983
Merge branch 'main' into aaronc/autocli-simapp
julienrbrt Dec 21, 2022
877144a
clean-up
julienrbrt Dec 30, 2022
713a6f0
Merge branch 'main' into aaronc/autocli-simapp
julienrbrt Dec 30, 2022
137fac2
updates
julienrbrt Dec 30, 2022
15708c0
smaller diff
julienrbrt Dec 30, 2022
e4b0f07
Merge branch 'main' into aaronc/autocli-simapp
julienrbrt Dec 31, 2022
ba15575
merge fix
julienrbrt Dec 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/v2/autocli/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ type Builder struct {

// GetClientConn specifies how CLI commands will resolve a grpc.ClientConnInterface
// from a given context.
GetClientConn func(context.Context) grpc.ClientConnInterface
GetClientConn func(context.Context) (grpc.ClientConnInterface, error)
}
6 changes: 5 additions & 1 deletion client/v2/autocli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript

cmd.RunE = func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
clientConn := getClientConn(ctx)
clientConn, err := getClientConn(ctx)
if err != nil {
return err
}

input, err := binder.BuildMessage(args)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions client/v2/autocli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func testExec(t *testing.T, args ...string) *testClientConn {
out: &bytes.Buffer{},
}
b := &Builder{
GetClientConn: func(ctx context.Context) grpc.ClientConnInterface {
return conn
GetClientConn: func(ctx context.Context) (grpc.ClientConnInterface, error) {
return conn, nil
},
}
cmd, err := b.BuildModuleQueryCommand("test", testCmdDesc)
Expand Down
78 changes: 78 additions & 0 deletions client/v2/autocli/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package autocli

import (
"context"
"fmt"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
"github.com/spf13/cobra"
"google.golang.org/grpc"
)

type AppConfig struct {
depinject.In

Modules map[string]appmodule.AppModule
ModuleOptions map[string]*autocliv1.ModuleOptions `optional:"true"`
}

func Run(cfg AppConfig) error {
cmd, err := RootCmd(cfg)
if err != nil {
return err
}

return cmd.Execute()
}

type contextKey string

const grpcEndpointContextKey = contextKey("grpc")

func RootCmd(cfg AppConfig) (*cobra.Command, error) {
builder := &Builder{
GetClientConn: func(ctx context.Context) (grpc.ClientConnInterface, error) {
grpcEndpoint, ok := ctx.Value(grpcEndpointContextKey).(string)
if !ok || grpcEndpoint == "" {
return nil, fmt.Errorf("no gRPC endpoint configured")
}

return grpc.Dial(grpcEndpoint)
},
}

moduleOptions := cfg.ModuleOptions
if moduleOptions == nil {
moduleOptions = map[string]*autocliv1.ModuleOptions{}

for name, module := range cfg.Modules {
if module, ok := module.(HasAutoCLIConfig); ok {
moduleOptions[name] = module.AutoCLIOptions()
}
}
Fixed Show fixed Hide fixed
}

customQueryCmds := map[string]*cobra.Command{}
for name, module := range cfg.Modules {
if module, ok := module.(HasCustomQueryCommand); ok {
customQueryCmds[name] = module.GetQueryCmd()
}
}
Fixed Show fixed Hide fixed

queryCmd, err := builder.BuildQueryCommand(moduleOptions, customQueryCmds)
if err != nil {
return nil, err
}

rootCmd := &cobra.Command{}
var grpcEndpoint string
rootCmd.PersistentFlags().StringVar(&grpcEndpoint, "grpc", "", "the gRPC endpoint of the node to connect with")
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
cmd.SetContext(context.WithValue(cmd.Context(), grpcEndpointContextKey, grpcEndpointContextKey))
return nil
}
rootCmd.AddCommand(queryCmd)
return rootCmd, nil
}
File renamed without changes.
8 changes: 8 additions & 0 deletions runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package runtime
import (
"fmt"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
abci "github.com/tendermint/tendermint/abci/types"

runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime/services"
"github.com/cosmos/cosmos-sdk/std"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -33,6 +35,7 @@ func init() {
ProvideTransientStoreKey,
ProvideMemoryStoreKey,
ProvideDeliverTx,
ProvideAutoCLIModuleOptions,
),
appmodule.Invoke(SetupAppBuilder),
)
Expand Down Expand Up @@ -142,3 +145,8 @@ func ProvideDeliverTx(appBuilder *AppBuilder) func(abci.RequestDeliverTx) abci.R
return appBuilder.app.BaseApp.DeliverTx(tx)
}
}

// ProvideAutoCLIModuleOptions provides the autocli module options discovered by the app.
func ProvideAutoCLIModuleOptions(app *AppBuilder) map[string]*autocliv1.ModuleOptions {
return services.NewAutoCLIQueryService(app.app.ModuleManager.Modules).ModuleOptions
}
6 changes: 3 additions & 3 deletions runtime/services/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type AutoCLIQueryService struct {
autocliv1.UnimplementedQueryServer

moduleOptions map[string]*autocliv1.ModuleOptions
ModuleOptions map[string]*autocliv1.ModuleOptions
}

func NewAutoCLIQueryService(appModules map[string]interface{}) *AutoCLIQueryService {
Expand Down Expand Up @@ -52,13 +52,13 @@ func NewAutoCLIQueryService(appModules map[string]interface{}) *AutoCLIQueryServ
}
}
return &AutoCLIQueryService{
moduleOptions: moduleOptions,
ModuleOptions: moduleOptions,
}
}

func (a AutoCLIQueryService) AppOptions(context.Context, *autocliv1.AppOptionsRequest) (*autocliv1.AppOptionsResponse, error) {
return &autocliv1.AppOptionsResponse{
ModuleOptions: a.moduleOptions,
ModuleOptions: a.ModuleOptions,
}, nil
}

Expand Down