Skip to content

Commit

Permalink
Implement gRPC Simulate endpoint (cosmos#7035)
Browse files Browse the repository at this point in the history
* Implement simulate endpoint

* Add GetProtoTx()

* Add signing in test

* Add txBuilderFromProto

* Remove stray println

* Update to master

* Merge master

* Fix tests

* Make tests pass

* Integrate in router

* Make proto-gen

* Fix lint

* Really fix lint

* Refactor to fix import cycles

* Rename builder -> wrapper

* Update proto/cosmos/base/reflection/v1beta1/reflection.proto

* Fix after merge

* t->w

Co-authored-by: Alexander Bezobchuk <[email protected]>
  • Loading branch information
amaury1093 and alexanderbez authored Aug 24, 2020
1 parent b6760ff commit 3d969a1
Show file tree
Hide file tree
Showing 26 changed files with 939 additions and 288 deletions.
27 changes: 21 additions & 6 deletions baseapp/grpcrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"google.golang.org/grpc/encoding/proto"

"github.com/cosmos/cosmos-sdk/client/grpc/reflection"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/client/grpc/simulate"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -19,7 +21,7 @@ var protoCodec = encoding.GetCodec(proto.Name)
// GRPCQueryRouter routes ABCI Query requests to GRPC handlers
type GRPCQueryRouter struct {
routes map[string]GRPCQueryHandler
interfaceRegistry types.InterfaceRegistry
interfaceRegistry codectypes.InterfaceRegistry
serviceData []serviceData
}

Expand Down Expand Up @@ -69,7 +71,7 @@ func (qrt *GRPCQueryRouter) RegisterService(sd *grpc.ServiceDesc, handler interf
return err
}
if qrt.interfaceRegistry != nil {
return types.UnpackInterfaces(i, qrt.interfaceRegistry)
return codectypes.UnpackInterfaces(i, qrt.interfaceRegistry)
}
return nil
}, nil)
Expand Down Expand Up @@ -97,14 +99,27 @@ func (qrt *GRPCQueryRouter) RegisterService(sd *grpc.ServiceDesc, handler interf
})
}

// SetInterfaceRegistry sets the interface registry for the router.
func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry types.InterfaceRegistry) {
// SetInterfaceRegistry sets the interface registry for the router. This will
// also register the interface reflection gRPC service.
func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry codectypes.InterfaceRegistry) {
qrt.interfaceRegistry = interfaceRegistry

// Once we have an interface registry, we can register the interface
// registry reflection gRPC service.
reflection.RegisterReflectionServiceServer(
qrt,
reflection.NewReflectionServiceServer(qrt.interfaceRegistry),
reflection.NewReflectionServiceServer(interfaceRegistry),
)
}

// RegisterSimulateService registers the simulate service on the gRPC router.
func (qrt *GRPCQueryRouter) RegisterSimulateService(
simulateFn simulate.BaseAppSimulateFn,
interfaceRegistry codectypes.InterfaceRegistry,
pubkeyCodec cryptotypes.PublicKeyCodec,
) {
simulate.RegisterSimulateServiceServer(
qrt,
simulate.NewSimulateServer(simulateFn, qrt.interfaceRegistry, pubkeyCodec),
)
}
50 changes: 27 additions & 23 deletions client/grpc/reflection/reflection.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

245 changes: 245 additions & 0 deletions client/grpc/reflection/reflection.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3d969a1

Please sign in to comment.