Skip to content

Commit

Permalink
Add proper support for Any in gRPC queries (cosmos#6594)
Browse files Browse the repository at this point in the history
* Add proper gRPC Any support via AnyUnpacker

* Wire up grpc query router AnyUnpacker
  • Loading branch information
aaronc authored Jul 3, 2020
1 parent 2e38043 commit 169ebaf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
33 changes: 23 additions & 10 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"io"
"os"

"github.com/cosmos/cosmos-sdk/codec/types"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
Expand Down Expand Up @@ -129,8 +131,9 @@ var _ App = (*SimApp)(nil)
// capabilities aren't needed for testing.
type SimApp struct {
*baseapp.BaseApp
cdc *codec.Codec
appCodec codec.Marshaler
cdc *codec.Codec
appCodec codec.Marshaler
interfaceRegistry types.InterfaceRegistry

invCheckPeriod uint

Expand Down Expand Up @@ -173,11 +176,15 @@ func NewSimApp(
) *SimApp {

// TODO: Remove cdc in favor of appCodec once all modules are migrated.
appCodec, cdc := MakeCodecs()
encodingConfig := MakeEncodingConfig()
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

bApp := baseapp.NewBaseApp(appName, logger, db, authtypes.DefaultTxDecoder(cdc), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetAppVersion(version.Version)
bApp.GRPCQueryRouter().SetAnyUnpacker(interfaceRegistry)

keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
Expand All @@ -189,13 +196,14 @@ func NewSimApp(
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

app := &SimApp{
BaseApp: bApp,
cdc: cdc,
appCodec: appCodec,
invCheckPeriod: invCheckPeriod,
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
BaseApp: bApp,
cdc: cdc,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
}

app.ParamsKeeper = initParamsKeeper(appCodec, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
Expand Down Expand Up @@ -456,6 +464,11 @@ func (app *SimApp) AppCodec() codec.Marshaler {
return app.appCodec
}

// InterfaceRegistry returns SimApp's InterfaceRegistry
func (app *SimApp) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
Expand Down
1 change: 1 addition & 0 deletions cmd/simcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
encodingConfig = simapp.MakeEncodingConfig()
initClientCtx = client.Context{}.
WithJSONMarshaler(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxGenerator(encodingConfig.TxGenerator).
WithCodec(encodingConfig.Amino).
WithInput(os.Stdin).
Expand Down

0 comments on commit 169ebaf

Please sign in to comment.