diff --git a/app/app.go b/app/app.go index b1ea0e8e0f..5bea30e7f4 100644 --- a/app/app.go +++ b/app/app.go @@ -367,6 +367,9 @@ func New( app.PaymentKeeper = *paymentmodulekeeper.NewKeeper( appCodec, + keys[paymentmoduletypes.StoreKey], + keys[paymentmoduletypes.MemStoreKey], + app.GetSubspace(paymentmoduletypes.ModuleName), ) paymentmod := paymentmodule.NewAppModule(appCodec, app.PaymentKeeper) diff --git a/go.mod b/go.mod index 67ddd7a09d..ee1834a89b 100644 --- a/go.mod +++ b/go.mod @@ -32,6 +32,7 @@ require ( github.com/regen-network/cosmos-proto v0.3.1 github.com/tendermint/tendermint v0.34.20 golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 + gopkg.in/yaml.v2 v2.4.0 ) require ( @@ -173,7 +174,6 @@ require ( google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.66.6 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect sigs.k8s.io/yaml v1.3.0 // indirect diff --git a/proto/payment/genesis.proto b/proto/payment/genesis.proto index 76c8bab730..aa0f34d34f 100644 --- a/proto/payment/genesis.proto +++ b/proto/payment/genesis.proto @@ -1,7 +1,12 @@ syntax = "proto3"; package payment; +import "gogoproto/gogo.proto"; +import "payment/params.proto"; + option go_package = "github.com/celestiaorg/celestia-app/x/payment/types"; // GenesisState defines the capability module's genesis state. -message GenesisState {} +message GenesisState { + Params params = 1 [(gogoproto.nullable) = false]; +} diff --git a/proto/payment/params.proto b/proto/payment/params.proto new file mode 100644 index 0000000000..8e0cf13159 --- /dev/null +++ b/proto/payment/params.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package payment; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/celestiaorg/celestia-app/x/payment/types"; + +// Params defines the parameters for the module. +message Params { + option (gogoproto.goproto_stringer) = false; + + uint32 min_square_size = 1 [(gogoproto.moretags) = "yaml:\"min_square_size\""]; + uint32 max_square_size = 2 [(gogoproto.moretags) = "yaml:\"max_square_size\""]; +} diff --git a/proto/payment/query.proto b/proto/payment/query.proto index ebdae3cc26..3c6c76d8a0 100644 --- a/proto/payment/query.proto +++ b/proto/payment/query.proto @@ -1,12 +1,25 @@ syntax = "proto3"; package payment; +import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; +import "payment/params.proto"; option go_package = "github.com/celestiaorg/celestia-app/x/payment/types"; // Query defines the gRPC querier service. service Query { + // Params queries the parameters of the module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/payment/params"; + } } +// QueryParamsRequest is the request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method. +message QueryParamsResponse { + Params params = 1 [(gogoproto.nullable) = false]; +} diff --git a/testutil/keeper/payment.go b/testutil/keeper/payment.go new file mode 100644 index 0000000000..1b0aba0571 --- /dev/null +++ b/testutil/keeper/payment.go @@ -0,0 +1,53 @@ +package keeper + +import ( + "testing" + + "github.com/celestiaorg/celestia-app/testutil" + "github.com/celestiaorg/celestia-app/x/payment/keeper" + "github.com/celestiaorg/celestia-app/x/payment/types" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + typesparams "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmdb "github.com/tendermint/tm-db" +) + +func PaymentKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { + storeKey := sdk.NewKVStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + + db := tmdb.NewMemDB() + stateStore := store.NewCommitMultiStore(db) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + paramsSubspace := typesparams.NewSubspace(cdc, + testutil.MakeTestCodec(), + storeKey, + memStoreKey, + "Payment", + ) + k := keeper.NewKeeper( + cdc, + storeKey, + memStoreKey, + paramsSubspace, + ) + + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) + + // Initialize params + k.SetParams(ctx, types.DefaultParams()) + + return k, ctx +} diff --git a/x/payment/client/cli/query.go b/x/payment/client/cli/query.go index 93113b2d6e..81f036a105 100644 --- a/x/payment/client/cli/query.go +++ b/x/payment/client/cli/query.go @@ -19,5 +19,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { RunE: client.ValidateCmd, } + cmd.AddCommand(CmdQueryParams()) + return cmd } diff --git a/x/payment/client/cli/query_params.go b/x/payment/client/cli/query_params.go new file mode 100644 index 0000000000..b6aeabfa11 --- /dev/null +++ b/x/payment/client/cli/query_params.go @@ -0,0 +1,34 @@ +package cli + +import ( + "context" + + "github.com/celestiaorg/celestia-app/x/payment/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" +) + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/payment/genesis.go b/x/payment/genesis.go index df9fdab9d0..e496c6e908 100644 --- a/x/payment/genesis.go +++ b/x/payment/genesis.go @@ -9,11 +9,12 @@ import ( // InitGenesis initializes the capability module's state from a provided genesis // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + k.SetParams(ctx, genState.Params) } // ExportGenesis returns the capability module's exported genesis. func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { genesis := types.DefaultGenesis() - + genesis.Params = k.GetParams(ctx) return genesis } diff --git a/x/payment/genesis_test.go b/x/payment/genesis_test.go new file mode 100644 index 0000000000..c5e5d8433c --- /dev/null +++ b/x/payment/genesis_test.go @@ -0,0 +1,22 @@ +package payment_test + +import ( + "testing" + + keepertest "github.com/celestiaorg/celestia-app/testutil/keeper" + "github.com/celestiaorg/celestia-app/x/payment" + "github.com/celestiaorg/celestia-app/x/payment/types" + "github.com/stretchr/testify/require" +) + +func TestGenesis(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + } + + k, ctx := keepertest.PaymentKeeper(t) + payment.InitGenesis(ctx, *k, genesisState) + got := payment.ExportGenesis(ctx, *k) + require.NotNil(t, got) + require.Equal(t, types.DefaultParams(), got.Params) +} diff --git a/x/payment/keeper/grpc_query.go b/x/payment/keeper/grpc_query.go new file mode 100644 index 0000000000..f5e93a4906 --- /dev/null +++ b/x/payment/keeper/grpc_query.go @@ -0,0 +1,7 @@ +package keeper + +import ( + "github.com/celestiaorg/celestia-app/x/payment/types" +) + +var _ types.QueryServer = Keeper{} diff --git a/x/payment/keeper/grpc_query_params.go b/x/payment/keeper/grpc_query_params.go new file mode 100644 index 0000000000..51930666a8 --- /dev/null +++ b/x/payment/keeper/grpc_query_params.go @@ -0,0 +1,19 @@ +package keeper + +import ( + "context" + + "github.com/celestiaorg/celestia-app/x/payment/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil +} diff --git a/x/payment/keeper/grpc_query_params_test.go b/x/payment/keeper/grpc_query_params_test.go new file mode 100644 index 0000000000..950adc390f --- /dev/null +++ b/x/payment/keeper/grpc_query_params_test.go @@ -0,0 +1,21 @@ +package keeper_test + +import ( + "testing" + + testkeeper "github.com/celestiaorg/celestia-app/testutil/keeper" + "github.com/celestiaorg/celestia-app/x/payment/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" +) + +func TestParamsQuery(t *testing.T) { + keeper, ctx := testkeeper.PaymentKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + params := types.DefaultParams() + keeper.SetParams(ctx, params) + + response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) + require.NoError(t, err) + require.Equal(t, &types.QueryParamsResponse{Params: params}, response) +} diff --git a/x/payment/keeper/keeper.go b/x/payment/keeper/keeper.go index e7b01884cd..1032de742d 100644 --- a/x/payment/keeper/keeper.go +++ b/x/payment/keeper/keeper.go @@ -10,7 +10,9 @@ import ( "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/x/payment/types" "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) const ( @@ -24,12 +26,27 @@ const ( // Keeper handles all the state changes for the payment module. type Keeper struct { - cdc codec.BinaryCodec + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + paramStore paramtypes.Subspace } -func NewKeeper(cdc codec.BinaryCodec) *Keeper { +func NewKeeper( + cdc codec.BinaryCodec, + storeKey, + memKey storetypes.StoreKey, + ps paramtypes.Subspace, +) *Keeper { + if !ps.HasKeyTable() { + ps = ps.WithKeyTable(types.ParamKeyTable()) + } + return &Keeper{ - cdc: cdc, + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + paramStore: ps, } } diff --git a/x/payment/keeper/params.go b/x/payment/keeper/params.go new file mode 100644 index 0000000000..3607bbf413 --- /dev/null +++ b/x/payment/keeper/params.go @@ -0,0 +1,31 @@ +package keeper + +import ( + "github.com/celestiaorg/celestia-app/x/payment/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// GetParams gets all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + return types.NewParams( + k.MinSquareSize(ctx), + k.MaxSquareSize(ctx), + ) +} + +// SetParams set the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramStore.SetParamSet(ctx, ¶ms) +} + +// MinSquareSize returns the MinSquareSize param +func (k Keeper) MinSquareSize(ctx sdk.Context) (res uint32) { + k.paramStore.Get(ctx, types.KeyMinSquareSize, &res) + return +} + +// MaxSquareSize returns the MaxSquareSize param +func (k Keeper) MaxSquareSize(ctx sdk.Context) (res uint32) { + k.paramStore.Get(ctx, types.KeyMaxSquareSize, &res) + return +} diff --git a/x/payment/keeper/params_test.go b/x/payment/keeper/params_test.go new file mode 100644 index 0000000000..eb5c44a75b --- /dev/null +++ b/x/payment/keeper/params_test.go @@ -0,0 +1,20 @@ +package keeper_test + +import ( + "testing" + + testkeeper "github.com/celestiaorg/celestia-app/testutil/keeper" + "github.com/celestiaorg/celestia-app/x/payment/types" + "github.com/stretchr/testify/require" +) + +func TestGetParams(t *testing.T) { + k, ctx := testkeeper.PaymentKeeper(t) + params := types.DefaultParams() + + k.SetParams(ctx, params) + + require.EqualValues(t, params, k.GetParams(ctx)) + require.EqualValues(t, params.MinSquareSize, k.MinSquareSize(ctx)) + require.EqualValues(t, params.MaxSquareSize, k.MaxSquareSize(ctx)) +} diff --git a/x/payment/module_simulation.go b/x/payment/module_simulation.go new file mode 100644 index 0000000000..cdb8f77bed --- /dev/null +++ b/x/payment/module_simulation.go @@ -0,0 +1,65 @@ +package payment + +import ( + "math/rand" + + paymentsimulation "github.com/celestiaorg/celestia-app/x/payment/simulation" + "github.com/celestiaorg/celestia-app/x/payment/types" + "github.com/cosmos/cosmos-sdk/baseapp" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/authz/codec" + "github.com/cosmos/cosmos-sdk/x/simulation" +) + +// avoid unused import issue +var ( + _ = paymentsimulation.FindAccount + _ = simappparams.StakePerAccount + _ = simulation.MsgEntryKind + _ = baseapp.Paramspace +) + +// GenerateGenesisState creates a randomized GenState of the module +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + accs := make([]string, len(simState.Accounts)) + for i, acc := range simState.Accounts { + accs[i] = acc.Address.String() + } + loanGenesis := types.GenesisState{ + Params: types.DefaultParams(), + } + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&loanGenesis) +} + +// ProposalContents doesn't return any content functions for governance proposals +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +// RandomizedParams creates randomized param changes for the simulator +func (am AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange { + paymentParams := types.DefaultParams() + return []simtypes.ParamChange{ + simulation.NewSimParamChange(types.ModuleName, string(types.KeyMinSquareSize), func(r *rand.Rand) string { + return string(codec.Amino.MustMarshalJSON(paymentParams.MinSquareSize)) + }), + simulation.NewSimParamChange(types.ModuleName, string(types.KeyMaxSquareSize), func(r *rand.Rand) string { + return string(codec.Amino.MustMarshalJSON(paymentParams.MaxSquareSize)) + }), + } +} + +// RegisterStoreDecoder registers a decoder +func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + operations := make([]simtypes.WeightedOperation, 0) + + // this line is used by starport scaffolding # simapp/module/operation + + return operations +} diff --git a/x/payment/simulation/simapp.go b/x/payment/simulation/simapp.go new file mode 100644 index 0000000000..92c437c0d1 --- /dev/null +++ b/x/payment/simulation/simapp.go @@ -0,0 +1,15 @@ +package simulation + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" +) + +// FindAccount find a specific address from an account list +func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { + creator, err := sdk.AccAddressFromBech32(address) + if err != nil { + panic(err) + } + return simtypes.FindAccount(accs, creator) +} diff --git a/x/payment/types/genesis.go b/x/payment/types/genesis.go index 094d1119cc..0785224ae9 100644 --- a/x/payment/types/genesis.go +++ b/x/payment/types/genesis.go @@ -5,11 +5,13 @@ const DefaultIndex uint64 = 1 // DefaultGenesis returns the default Capability genesis state func DefaultGenesis() *GenesisState { - return &GenesisState{} + return &GenesisState{ + Params: DefaultParams(), + } } // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { - return nil + return gs.Params.Validate() } diff --git a/x/payment/types/genesis.pb.go b/x/payment/types/genesis.pb.go index 3b25078113..a9ca50153d 100644 --- a/x/payment/types/genesis.pb.go +++ b/x/payment/types/genesis.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -24,6 +25,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the capability module's genesis state. type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -59,6 +61,13 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + func init() { proto.RegisterType((*GenesisState)(nil), "payment.GenesisState") } @@ -66,16 +75,19 @@ func init() { func init() { proto.RegisterFile("payment/genesis.proto", fileDescriptor_ded92bd505296f58) } var fileDescriptor_ded92bd505296f58 = []byte{ - // 135 bytes of a gzipped FileDescriptorProto + // 189 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2d, 0x48, 0xac, 0xcc, 0x4d, 0xcd, 0x2b, 0xd1, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0x62, 0x87, 0x0a, 0x2b, 0xf1, 0x71, 0xf1, 0xb8, 0x43, 0x64, 0x82, 0x4b, 0x12, 0x4b, - 0x52, 0x9d, 0x7c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, - 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x38, 0x3d, - 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0x39, 0x35, 0x27, 0xb5, 0xb8, 0x24, - 0x33, 0x31, 0xbf, 0x28, 0x1d, 0xce, 0xd6, 0x4d, 0x2c, 0x28, 0xd0, 0xaf, 0xd0, 0x87, 0xd9, 0x57, - 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0xb6, 0xce, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x12, - 0x51, 0x3e, 0xf3, 0x87, 0x00, 0x00, 0x00, + 0xc9, 0x17, 0x62, 0x87, 0x0a, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0xc5, 0xf4, 0x41, 0x2c, + 0x88, 0xb4, 0x94, 0x08, 0x4c, 0x57, 0x41, 0x62, 0x51, 0x62, 0x2e, 0x54, 0x93, 0x92, 0x2d, 0x17, + 0x8f, 0x3b, 0xc4, 0x94, 0xe0, 0x92, 0xc4, 0x92, 0x54, 0x21, 0x5d, 0x2e, 0x36, 0x88, 0xbc, 0x04, + 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x11, 0xbf, 0x1e, 0x54, 0x9b, 0x5e, 0x00, 0x58, 0xd8, 0x89, 0xe5, + 0xc4, 0x3d, 0x79, 0x86, 0x20, 0xa8, 0x22, 0x27, 0xdf, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, + 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, + 0x96, 0x63, 0x88, 0x32, 0x4e, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, + 0x4e, 0xcd, 0x49, 0x2d, 0x2e, 0xc9, 0x4c, 0xcc, 0x2f, 0x4a, 0x87, 0xb3, 0x75, 0x13, 0x0b, 0x0a, + 0xf4, 0x2b, 0xf4, 0x61, 0x8e, 0x2a, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x3b, 0xca, 0x18, + 0x10, 0x00, 0x00, 0xff, 0xff, 0x68, 0xc3, 0x75, 0x3c, 0xe2, 0x00, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -98,6 +110,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -118,6 +140,8 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -156,6 +180,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/payment/types/genesis_test.go b/x/payment/types/genesis_test.go index 56a870f7ff..4e7ad402d2 100644 --- a/x/payment/types/genesis_test.go +++ b/x/payment/types/genesis_test.go @@ -19,9 +19,14 @@ func TestGenesisState_Validate(t *testing.T) { valid: true, }, { - desc: "valid genesis state", - genState: &types.GenesisState{}, - valid: true, + desc: "valid genesis state", + genState: &types.GenesisState{ + Params: types.Params{ + MinSquareSize: 512, + MaxSquareSize: 1024, + }, + }, + valid: true, }, } { t.Run(tc.desc, func(t *testing.T) { diff --git a/x/payment/types/params.go b/x/payment/types/params.go new file mode 100644 index 0000000000..ec82857ed4 --- /dev/null +++ b/x/payment/types/params.go @@ -0,0 +1,99 @@ +package types + +import ( + "fmt" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "gopkg.in/yaml.v2" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +var ( + KeyMinSquareSize = []byte("MinSquareSize") + DefaultMinSquareSize uint32 = 1 +) + +var ( + KeyMaxSquareSize = []byte("MaxSquareSize") + DefaultMaxSquareSize uint32 = 128 +) + +// ParamKeyTable returns the param key table for the payment module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new Params instance +func NewParams( + minSquareSize uint32, + maxSquareSize uint32, +) Params { + return Params{ + MinSquareSize: minSquareSize, + MaxSquareSize: maxSquareSize, + } +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams( + DefaultMinSquareSize, + DefaultMaxSquareSize, + ) +} + +// ParamSetPairs gets the list of param key-value pairs +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyMinSquareSize, &p.MinSquareSize, validateMinSquareSize), + paramtypes.NewParamSetPair(KeyMaxSquareSize, &p.MaxSquareSize, validateMaxSquareSize), + } +} + +// Validate validates the set of params +func (p Params) Validate() error { + if err := validateMinSquareSize(p.MinSquareSize); err != nil { + return err + } + + if err := validateMaxSquareSize(p.MaxSquareSize); err != nil { + return err + } + + return nil +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} + +// validateMinSquareSize validates the MinSquareSize param +func validateMinSquareSize(v interface{}) error { + minSquareSize, ok := v.(uint32) + if !ok { + return fmt.Errorf("invalid parameter type: %T", v) + } + + if minSquareSize == 0 { + return fmt.Errorf("min square size cannot be 0") + } + + return nil +} + +// validateMaxSquareSize validates the MaxSquareSize param +func validateMaxSquareSize(v interface{}) error { + maxSquareSize, ok := v.(uint32) + if !ok { + return fmt.Errorf("invalid parameter type: %T", v) + } + + if maxSquareSize == 0 { + return fmt.Errorf("max square size cannot be 0") + } + + return nil +} diff --git a/x/payment/types/params.pb.go b/x/payment/types/params.pb.go new file mode 100644 index 0000000000..6b9de7bb7a --- /dev/null +++ b/x/payment/types/params.pb.go @@ -0,0 +1,338 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: payment/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the parameters for the module. +type Params struct { + MinSquareSize uint32 `protobuf:"varint,1,opt,name=min_square_size,json=minSquareSize,proto3" json:"min_square_size,omitempty" yaml:"min_square_size"` + MaxSquareSize uint32 `protobuf:"varint,2,opt,name=max_square_size,json=maxSquareSize,proto3" json:"max_square_size,omitempty" yaml:"max_square_size"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_12d54b052075926a, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMinSquareSize() uint32 { + if m != nil { + return m.MinSquareSize + } + return 0 +} + +func (m *Params) GetMaxSquareSize() uint32 { + if m != nil { + return m.MaxSquareSize + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "payment.Params") +} + +func init() { proto.RegisterFile("payment/params.proto", fileDescriptor_12d54b052075926a) } + +var fileDescriptor_12d54b052075926a = []byte{ + // 220 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x29, 0x48, 0xac, 0xcc, + 0x4d, 0xcd, 0x2b, 0xd1, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x62, 0x87, 0x8a, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0xc5, 0xf4, 0x41, 0x2c, 0x88, + 0xb4, 0xd2, 0x34, 0x46, 0x2e, 0xb6, 0x00, 0xb0, 0x7a, 0x21, 0x27, 0x2e, 0xfe, 0xdc, 0xcc, 0xbc, + 0xf8, 0xe2, 0xc2, 0xd2, 0xc4, 0xa2, 0xd4, 0xf8, 0xe2, 0xcc, 0xaa, 0x54, 0x09, 0x46, 0x05, 0x46, + 0x0d, 0x5e, 0x27, 0xa9, 0x4f, 0xf7, 0xe4, 0xc5, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0xd0, 0x14, + 0x28, 0x05, 0xf1, 0xe6, 0x66, 0xe6, 0x05, 0x83, 0x05, 0x82, 0x33, 0xab, 0x52, 0xc1, 0x66, 0x24, + 0x56, 0xa0, 0x98, 0xc1, 0x84, 0x61, 0x06, 0xaa, 0x02, 0x90, 0x19, 0x89, 0x15, 0x08, 0x33, 0xac, + 0x58, 0x66, 0x2c, 0x90, 0x67, 0x70, 0xf2, 0x3d, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, + 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, + 0x86, 0x28, 0xe3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe4, 0xd4, + 0x9c, 0xd4, 0xe2, 0x92, 0xcc, 0xc4, 0xfc, 0xa2, 0x74, 0x38, 0x5b, 0x37, 0xb1, 0xa0, 0x40, 0xbf, + 0x42, 0x1f, 0x16, 0x1a, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0xef, 0x1a, 0x03, 0x02, + 0x00, 0x00, 0xff, 0xff, 0x05, 0x68, 0x47, 0xac, 0x25, 0x01, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MaxSquareSize != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.MaxSquareSize)) + i-- + dAtA[i] = 0x10 + } + if m.MinSquareSize != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.MinSquareSize)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MinSquareSize != 0 { + n += 1 + sovParams(uint64(m.MinSquareSize)) + } + if m.MaxSquareSize != 0 { + n += 1 + sovParams(uint64(m.MaxSquareSize)) + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MinSquareSize", wireType) + } + m.MinSquareSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MinSquareSize |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxSquareSize", wireType) + } + m.MaxSquareSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxSquareSize |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/payment/types/query.pb.go b/x/payment/types/query.pb.go index 04022eb22e..9f454c3ebf 100644 --- a/x/payment/types/query.pb.go +++ b/x/payment/types/query.pb.go @@ -7,11 +7,16 @@ import ( context "context" fmt "fmt" _ "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -25,22 +30,116 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// QueryParamsRequest is the request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_0d907c42280cbd58, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Query/Params RPC method. +type QueryParamsResponse struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_0d907c42280cbd58, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "payment.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "payment.QueryParamsResponse") +} + func init() { proto.RegisterFile("payment/query.proto", fileDescriptor_0d907c42280cbd58) } var fileDescriptor_0d907c42280cbd58 = []byte{ - // 187 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x3c, 0xce, 0xb1, 0x8e, 0x82, 0x40, - 0x10, 0x06, 0x60, 0x28, 0xee, 0x48, 0x28, 0xef, 0x3a, 0x72, 0xd9, 0x07, 0xb8, 0x44, 0x26, 0xc8, - 0x1b, 0xd8, 0x5b, 0xd8, 0xda, 0xcd, 0x92, 0xc9, 0xba, 0x09, 0xec, 0xac, 0xec, 0x60, 0xe4, 0x2d, - 0x7c, 0x2c, 0x4b, 0x4a, 0x4b, 0x03, 0x2f, 0x62, 0x04, 0xb5, 0x9b, 0x4c, 0xbe, 0xff, 0xcf, 0x9f, - 0xfe, 0x7a, 0xec, 0x1b, 0x72, 0x02, 0xc7, 0x8e, 0xda, 0x3e, 0xf7, 0x2d, 0x0b, 0xff, 0x24, 0xaf, - 0x67, 0xf6, 0x67, 0x98, 0x4d, 0x4d, 0x80, 0xde, 0x02, 0x3a, 0xc7, 0x82, 0x62, 0xd9, 0x85, 0x85, - 0x65, 0xff, 0x15, 0x87, 0x86, 0x03, 0x68, 0x0c, 0xb4, 0xe4, 0xe1, 0x54, 0x68, 0x12, 0x2c, 0xc0, - 0xa3, 0xb1, 0x6e, 0xc6, 0x8b, 0x5d, 0x27, 0xe9, 0xd7, 0xee, 0x29, 0x36, 0xdb, 0xeb, 0xa8, 0xe2, - 0x61, 0x54, 0xf1, 0x7d, 0x54, 0xf1, 0x65, 0x52, 0xd1, 0x30, 0xa9, 0xe8, 0x36, 0xa9, 0x68, 0x5f, - 0x1a, 0x2b, 0x87, 0x4e, 0xe7, 0x15, 0x37, 0x50, 0x51, 0x4d, 0x41, 0x2c, 0x72, 0x6b, 0x3e, 0xf7, - 0x0a, 0xbd, 0x87, 0x33, 0xbc, 0x07, 0x4b, 0xef, 0x29, 0xe8, 0xef, 0xb9, 0xbe, 0x7c, 0x04, 0x00, - 0x00, 0xff, 0xff, 0x99, 0xff, 0xee, 0xed, 0xc8, 0x00, 0x00, 0x00, + // 291 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x4f, 0x4b, 0xc3, 0x30, + 0x18, 0xc6, 0x5b, 0xd1, 0x09, 0xf1, 0x30, 0xcc, 0x06, 0xca, 0x1c, 0x51, 0x76, 0x12, 0x61, 0x0d, + 0xdb, 0xbe, 0xc1, 0xf0, 0x2a, 0xe8, 0x8e, 0xe2, 0x25, 0x2d, 0x2f, 0xb1, 0xb0, 0xe6, 0xcd, 0x9a, + 0x54, 0xec, 0xd5, 0x4f, 0x20, 0xf8, 0xa5, 0x76, 0x1c, 0x78, 0xf1, 0x24, 0xd2, 0xfa, 0x41, 0x64, + 0x4d, 0x2c, 0x0c, 0xbd, 0xbd, 0x3c, 0x7f, 0x7e, 0x0f, 0x09, 0xe9, 0x69, 0x51, 0x66, 0xa0, 0x2c, + 0x5f, 0x15, 0x90, 0x97, 0x91, 0xce, 0xd1, 0x22, 0x3d, 0xf4, 0xe2, 0xa0, 0x2f, 0x51, 0x62, 0xa3, + 0xf1, 0xed, 0xe5, 0xec, 0xc1, 0x50, 0x22, 0xca, 0x25, 0x70, 0xa1, 0x53, 0x2e, 0x94, 0x42, 0x2b, + 0x6c, 0x8a, 0xca, 0x78, 0xf7, 0x2a, 0x41, 0x93, 0xa1, 0xe1, 0xb1, 0x30, 0xe0, 0xa8, 0xfc, 0x69, + 0x12, 0x83, 0x15, 0x13, 0xae, 0x85, 0x4c, 0x55, 0x13, 0xf6, 0xd9, 0xfe, 0xef, 0xba, 0x16, 0xb9, + 0xc8, 0x3c, 0x61, 0xd4, 0x27, 0xf4, 0x6e, 0xdb, 0xbb, 0x6d, 0xc4, 0x05, 0xac, 0x0a, 0x30, 0x76, + 0x74, 0x4d, 0x7a, 0x3b, 0xaa, 0xd1, 0xa8, 0x0c, 0xd0, 0x31, 0xe9, 0xb8, 0xf2, 0x69, 0x78, 0x11, + 0x5e, 0x1e, 0x4d, 0xbb, 0x91, 0x67, 0x46, 0x2e, 0x38, 0xdf, 0x5f, 0x7f, 0x9e, 0x07, 0x0b, 0x1f, + 0x9a, 0x02, 0x39, 0x68, 0x28, 0xf4, 0x81, 0x74, 0x5c, 0x80, 0x9e, 0xb5, 0x8d, 0xbf, 0xab, 0x83, + 0xe1, 0xff, 0xa6, 0x1b, 0x1f, 0x9d, 0xbc, 0xbc, 0x7f, 0xbf, 0xed, 0x1d, 0xd3, 0x2e, 0xdf, 0x7d, + 0xc8, 0xfc, 0x66, 0x5d, 0xb1, 0x70, 0x53, 0xb1, 0xf0, 0xab, 0x62, 0xe1, 0x6b, 0xcd, 0x82, 0x4d, + 0xcd, 0x82, 0x8f, 0x9a, 0x05, 0xf7, 0x33, 0x99, 0xda, 0xc7, 0x22, 0x8e, 0x12, 0xcc, 0x78, 0x02, + 0x4b, 0x30, 0x36, 0x15, 0x98, 0xcb, 0xf6, 0x1e, 0x0b, 0xad, 0xf9, 0x73, 0xcb, 0xb3, 0xa5, 0x06, + 0x13, 0x77, 0x9a, 0x8f, 0x99, 0xfd, 0x04, 0x00, 0x00, 0xff, 0xff, 0x13, 0xfe, 0x9d, 0xcc, 0xae, + 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -55,6 +154,8 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { + // Params queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) } type queryClient struct { @@ -65,22 +166,371 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/payment.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { + // Params queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. type UnimplementedQueryServer struct { } +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} + func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/payment.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "payment.Query", HandlerType: (*QueryServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{}, - Metadata: "payment/query.proto", + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "payment/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/payment/types/query.pb.gw.go b/x/payment/types/query.pb.gw.go new file mode 100644 index 0000000000..c8bf5a63fb --- /dev/null +++ b/x/payment/types/query.pb.gw.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: payment/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"payment", "params"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage +)