Upgrade to Stargate commits

This commit is contained in:
Alex Peters
2020-08-12 17:43:28 +02:00
parent ff37dc68f2
commit bcb00d6017
88 changed files with 16224 additions and 7775 deletions

View File

@@ -2,18 +2,23 @@ package wasm
import (
"encoding/json"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
"math/rand"
"github.com/CosmWasm/wasmd/x/wasm/client/cli"
"github.com/CosmWasm/wasmd/x/wasm/client/rest"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/CosmWasm/wasmd/x/wasm/internal/keeper"
"github.com/CosmWasm/wasmd/x/wasm/internal/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/gogo/protobuf/grpc"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
)
var (
@@ -24,28 +29,31 @@ var (
// AppModuleBasic defines the basic application module used by the wasm module.
type AppModuleBasic struct{}
func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) {
RegisterCodec(amino)
}
func (b AppModuleBasic) RegisterGRPCRoutes(context client.Context, serveMux *runtime.ServeMux) {
panic("implement me")
}
// Name returns the wasm module's name.
func (AppModuleBasic) Name() string {
return ModuleName
}
// RegisterCodec registers the wasm module's types for the given codec.
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
RegisterCodec(cdc)
}
// DefaultGenesis returns default genesis state as raw bytes for the wasm
// module.
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
return ModuleCdc.MustMarshalJSON(&GenesisState{
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
return cdc.MustMarshalJSON(&GenesisState{
Params: DefaultParams(),
})
}
// ValidateGenesis performs genesis state validation for the wasm module.
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
func (b AppModuleBasic) ValidateGenesis(marshaler codec.JSONMarshaler, config client.TxEncodingConfig, message json.RawMessage) error {
var data GenesisState
err := ModuleCdc.UnmarshalJSON(bz, &data)
err := marshaler.UnmarshalJSON(message, &data)
if err != nil {
return err
}
@@ -53,18 +61,23 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// RegisterRESTRoutes registers the REST routes for the wasm module.
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
rest.RegisterRoutes(ctx, rtr)
func (AppModuleBasic) RegisterRESTRoutes(cliCtx client.Context, rtr *mux.Router) {
rest.RegisterRoutes(cliCtx, rtr)
}
// GetTxCmd returns the root tx command for the wasm module.
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetTxCmd(cdc)
func (b AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd()
}
// GetQueryCmd returns no root query command for the wasm module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(cdc)
func (b AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}
// RegisterInterfaceTypes implements InterfaceModule
func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
//____________________________________________________________________________
@@ -75,6 +88,18 @@ type AppModule struct {
keeper Keeper
}
func (am AppModule) RegisterServices(configurator module.Configurator) {
types.RegisterQueryServer(configurator.QueryServer(), NewQuerier(am.keeper))
}
func (am AppModule) LegacyQuerierHandler(amino *codec.LegacyAmino) sdk.Querier {
return keeper.NewLegacyQuerier(am.keeper)
}
func (am AppModule) RegisterQueryService(server grpc.Server) {
types.RegisterQueryServer(server, NewQuerier(am.keeper))
}
// NewAppModule creates a new AppModule object
func NewAppModule(keeper Keeper) AppModule {
return AppModule{
@@ -92,13 +117,8 @@ func (AppModule) Name() string {
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}
// Route returns the message routing key for the wasm module.
func (AppModule) Route() string {
return RouterKey
}
// NewHandler returns an sdk.Handler for the wasm module.
func (am AppModule) NewHandler() sdk.Handler {
return NewHandler(am.keeper)
func (am AppModule) Route() sdk.Route {
return sdk.NewRoute(RouterKey, NewHandler(am.keeper))
}
// QuerierRoute returns the wasm module's querier route name.
@@ -106,16 +126,11 @@ func (AppModule) QuerierRoute() string {
return QuerierRoute
}
// NewQuerierHandler returns the wasm module sdk.Querier.
func (am AppModule) NewQuerierHandler() sdk.Querier {
return NewQuerier(am.keeper)
}
// InitGenesis performs genesis initialization for the wasm module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
ModuleCdc.MustUnmarshalJSON(data, &genesisState)
cdc.MustUnmarshalJSON(data, &genesisState)
if err := InitGenesis(ctx, am.keeper, genesisState); err != nil {
panic(err)
}
@@ -124,9 +139,9 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va
// ExportGenesis returns the exported genesis state as raw bytes for the wasm
// module.
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage {
gs := ExportGenesis(ctx, am.keeper)
return ModuleCdc.MustMarshalJSON(gs)
return cdc.MustMarshalJSON(gs)
}
// BeginBlock returns the begin blocker for the wasm module.
@@ -137,3 +152,30 @@ func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}
//____________________________________________________________________________
// AppModuleSimulation functions
// GenerateGenesisState creates a randomized GenState of the bank module.
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
}
// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}
// RandomizedParams creates randomized bank param changes for the simulator.
func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
return nil
}
// RegisterStoreDecoder registers a decoder for supply module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
}
// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return nil
}