From 980ae0e3d1d05075832ffbbc8514de28364b83d5 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 29 May 2024 21:25:29 +0300 Subject: [PATCH] feat: msgupdateparams implementaion --- app/keepers/keepers.go | 8 + go.mod | 1 + go.sum | 1 - proto/buf.lock | 4 +- proto/sgenetwork/sge/bet/tx.proto | 32 +- proto/sgenetwork/sge/house/tx.proto | 30 + proto/sgenetwork/sge/market/tx.proto | 29 + proto/sgenetwork/sge/orderbook/tx.proto | 39 ++ proto/sgenetwork/sge/ovm/tx.proto | 31 + proto/sgenetwork/sge/reward/tx.proto | 29 + proto/sgenetwork/sge/subaccount/tx.proto | 34 +- x/bet/handler.go | 4 + x/bet/keeper/keeper.go | 11 + x/bet/keeper/msg_server_params.go | 27 + x/bet/simulation/proposals.go | 50 ++ x/bet/simulation/proposals_test.go | 49 ++ x/bet/types/codec.go | 2 + x/bet/types/messages_params.go | 43 ++ x/bet/types/tx.pb.go | 431 ++++++++++++- x/house/handler.go | 4 +- x/house/keeper/keeper.go | 10 + x/house/keeper/msg_server_params.go | 27 + x/house/simulation/proposals.go | 47 ++ x/house/simulation/proposals_test.go | 46 ++ x/house/types/codec.go | 2 + x/house/types/messages_params.go | 43 ++ x/house/types/tx.pb.go | 470 +++++++++++++-- x/market/handler.go | 4 + x/market/keeper/keeper.go | 10 + x/market/keeper/msg_server_params.go | 27 + x/market/simulation/proposals.go | 43 ++ x/market/simulation/proposals_test.go | 42 ++ x/market/types/codec.go | 6 +- x/market/types/messages_params.go | 43 ++ x/market/types/tx.pb.go | 449 +++++++++++++- x/orderbook/handler.go | 32 + x/orderbook/keeper/keeper.go | 10 + x/orderbook/keeper/msg_server.go | 17 + x/orderbook/keeper/msg_server_params.go | 27 + x/orderbook/keeper/msg_server_test.go | 19 + x/orderbook/module.go | 1 + x/orderbook/simulation/proposals.go | 46 ++ x/orderbook/simulation/proposals_test.go | 45 ++ x/orderbook/types/codec.go | 12 +- x/orderbook/types/messages_params.go | 43 ++ x/orderbook/types/tx.pb.go | 598 +++++++++++++++++++ x/ovm/handler.go | 4 + x/ovm/keeper/keeper.go | 10 + x/ovm/keeper/msg_server_params.go | 27 + x/ovm/simulation/proposals.go | 43 ++ x/ovm/simulation/proposals_test.go | 42 ++ x/ovm/types/codec.go | 2 + x/ovm/types/messages_params.go | 43 ++ x/ovm/types/tx.pb.go | 449 +++++++++++++- x/reward/handler.go | 3 + x/reward/keeper/keeper.go | 10 + x/reward/keeper/msg_server_params.go | 27 + x/reward/simulation/proposals.go | 43 ++ x/reward/simulation/proposals_test.go | 42 ++ x/reward/types/codec.go | 2 + x/reward/types/messages_params.go | 43 ++ x/reward/types/tx.pb.go | 474 +++++++++++++-- x/subaccount/handler.go | 6 +- x/subaccount/keeper/export_test.go | 5 + x/subaccount/keeper/keeper.go | 10 + x/subaccount/keeper/keeper_test.go | 2 +- x/subaccount/keeper/msg_server.go | 6 +- x/subaccount/keeper/msg_server_balance.go | 6 +- x/subaccount/keeper/msg_server_bet.go | 14 +- x/subaccount/keeper/msg_server_house.go | 22 +- x/subaccount/keeper/msg_server_params.go | 27 + x/subaccount/keeper/msg_server_subaccount.go | 2 +- x/subaccount/keeper/msg_server_test.go | 2 +- x/subaccount/module.go | 2 +- x/subaccount/simulation/proposals.go | 45 ++ x/subaccount/simulation/proposals_test.go | 44 ++ x/subaccount/types/codec.go | 2 + x/subaccount/types/messages_params.go | 43 ++ x/subaccount/types/tx.pb.go | 478 +++++++++++++-- 79 files changed, 4748 insertions(+), 210 deletions(-) create mode 100644 proto/sgenetwork/sge/orderbook/tx.proto create mode 100644 x/bet/keeper/msg_server_params.go create mode 100644 x/bet/simulation/proposals.go create mode 100644 x/bet/simulation/proposals_test.go create mode 100644 x/bet/types/messages_params.go create mode 100644 x/house/keeper/msg_server_params.go create mode 100644 x/house/simulation/proposals.go create mode 100644 x/house/simulation/proposals_test.go create mode 100644 x/house/types/messages_params.go create mode 100644 x/market/keeper/msg_server_params.go create mode 100644 x/market/simulation/proposals.go create mode 100644 x/market/simulation/proposals_test.go create mode 100644 x/market/types/messages_params.go create mode 100644 x/orderbook/handler.go create mode 100644 x/orderbook/keeper/msg_server.go create mode 100644 x/orderbook/keeper/msg_server_params.go create mode 100644 x/orderbook/keeper/msg_server_test.go create mode 100644 x/orderbook/simulation/proposals.go create mode 100644 x/orderbook/simulation/proposals_test.go create mode 100644 x/orderbook/types/messages_params.go create mode 100644 x/orderbook/types/tx.pb.go create mode 100644 x/ovm/keeper/msg_server_params.go create mode 100644 x/ovm/simulation/proposals.go create mode 100644 x/ovm/simulation/proposals_test.go create mode 100644 x/ovm/types/messages_params.go create mode 100644 x/reward/keeper/msg_server_params.go create mode 100644 x/reward/simulation/proposals.go create mode 100644 x/reward/simulation/proposals_test.go create mode 100644 x/reward/types/messages_params.go create mode 100644 x/subaccount/keeper/export_test.go create mode 100644 x/subaccount/keeper/msg_server_params.go create mode 100644 x/subaccount/simulation/proposals.go create mode 100644 x/subaccount/simulation/proposals_test.go create mode 100644 x/subaccount/types/messages_params.go diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index ed642a07..11a32241 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -475,6 +475,7 @@ func NewAppKeeper( appKeepers.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(&appKeepers.WasmKeeper) appKeepers.Ics20WasmHooks.ContractKeeper = &appKeepers.WasmKeeper + authority := authtypes.NewModuleAddress(govtypes.ModuleName).String() // // SGE keepers \\\\ appKeepers.OrderbookKeeper = orderbookmodulekeeper.NewKeeper( @@ -486,6 +487,7 @@ func NewAppKeeper( AccountKeeper: appKeepers.AccountKeeper, FeeGrantKeeper: appKeepers.FeeGrantKeeper, }, + authority, ) appKeepers.OVMKeeper = ovmmodulekeeper.NewKeeper( @@ -493,6 +495,7 @@ func NewAppKeeper( appKeepers.keys[ovmmoduletypes.StoreKey], appKeepers.keys[ovmmoduletypes.MemStoreKey], appKeepers.GetSubspace(ovmmoduletypes.ModuleName), + authority, ) appKeepers.MarketKeeper = marketmodulekeeper.NewKeeper( @@ -500,6 +503,7 @@ func NewAppKeeper( appKeepers.keys[marketmoduletypes.StoreKey], appKeepers.keys[marketmoduletypes.MemStoreKey], appKeepers.GetSubspace(marketmoduletypes.ModuleName), + authority, ) appKeepers.MarketKeeper.SetOVMKeeper(appKeepers.OVMKeeper) appKeepers.MarketKeeper.SetOrderbookKeeper(appKeepers.OrderbookKeeper) @@ -509,6 +513,7 @@ func NewAppKeeper( appKeepers.keys[betmoduletypes.StoreKey], appKeepers.keys[betmoduletypes.MemStoreKey], appKeepers.GetSubspace(betmoduletypes.ModuleName), + authority, ) appKeepers.BetKeeper.SetMarketKeeper(appKeepers.MarketKeeper) appKeepers.BetKeeper.SetOrderbookKeeper(appKeepers.OrderbookKeeper) @@ -527,6 +532,7 @@ func NewAppKeeper( housemodulekeeper.SdkExpectedKeepers{ AuthzKeeper: appKeepers.AuthzKeeper, }, + authority, ) appKeepers.OrderbookKeeper.SetHouseKeeper(appKeepers.HouseKeeper) @@ -540,6 +546,7 @@ func NewAppKeeper( appKeepers.BetKeeper, appKeepers.OrderbookKeeper, appKeepers.HouseKeeper, + authority, ) appKeepers.RewardKeeper = rewardmodulekeeper.NewKeeper( @@ -555,6 +562,7 @@ func NewAppKeeper( BankKeeper: appKeepers.BankKeeper, AccountKeeper: appKeepers.AccountKeeper, }, + authority, ) // ** Hooks ** \\ diff --git a/go.mod b/go.mod index 44044b6d..fa67301a 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de google.golang.org/grpc v1.63.2 gopkg.in/yaml.v2 v2.4.0 + gotest.tools/v3 v3.5.1 mvdan.cc/gofumpt v0.5.0 ) diff --git a/go.sum b/go.sum index 459ce2ea..fc0d003a 100644 --- a/go.sum +++ b/go.sum @@ -2273,7 +2273,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= diff --git a/proto/buf.lock b/proto/buf.lock index 83c7a202..32d482eb 100644 --- a/proto/buf.lock +++ b/proto/buf.lock @@ -19,8 +19,8 @@ deps: - remote: buf.build owner: googleapis repository: googleapis - commit: 1f6ed065c9f04b5cb843d6e7603d6454 - digest: shake256:7149cf5e9955c692d381e557830555d4e93f205a0f1b8e2dfdae46d029369aa3fc1980e35df0d310f7cc3b622f93e19ad276769a283a967dd3065ddfd3a40e13 + commit: f0e53af8f2fc4556b94f482688b57223 + digest: shake256:de26a277fc28b8b411ecf58729d78d32fcf15090ffd998a4469225b17889bfb51442eaab04bb7a8d88d203ecdf0a9febd4ffd52c18ed1c2229160c7bd353ca95 - remote: buf.build owner: protocolbuffers repository: wellknowntypes diff --git a/proto/sgenetwork/sge/bet/tx.proto b/proto/sgenetwork/sge/bet/tx.proto index ec52db9f..89fe2032 100644 --- a/proto/sgenetwork/sge/bet/tx.proto +++ b/proto/sgenetwork/sge/bet/tx.proto @@ -1,15 +1,25 @@ syntax = "proto3"; package sgenetwork.sge.bet; +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; import "sgenetwork/sge/bet/wager.proto"; +import "sgenetwork/sge/bet/params.proto"; option go_package = "github.com/sge-network/sge/x/bet/types"; // Msg defines the Msg service. service Msg { - // Wager defines a method to place a bet with the given data. rpc Wager(MsgWager) returns (MsgWagerResponse); + + // UpdateParams defines a governance operation for updating the x/bet module + // parameters. The authority is defined in the keeper. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) { + option (cosmos_proto.method_added_in) = "sge-network 1.7.1"; + } } // MsgWager defines a message to place a bet with the given data. @@ -23,3 +33,23 @@ message MsgWager { // MsgWagerResponse is the returning value in the response // of MsgWagerResponse request. message MsgWagerResponse { WagerProps props = 1; } + +// MsgUpdateParams is the Msg/UpdateParams request type. +message MsgUpdateParams { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // params defines the x/bet parameters. + Params params = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +message MsgUpdateParamsResponse { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; +} \ No newline at end of file diff --git a/proto/sgenetwork/sge/house/tx.proto b/proto/sgenetwork/sge/house/tx.proto index 9d218a28..ad34ea40 100644 --- a/proto/sgenetwork/sge/house/tx.proto +++ b/proto/sgenetwork/sge/house/tx.proto @@ -2,7 +2,11 @@ syntax = "proto3"; package sgenetwork.sge.house; import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; import "sgenetwork/sge/house/withdraw.proto"; +import "sgenetwork/sge/house/params.proto"; option go_package = "github.com/sge-network/sge/x/house/types"; @@ -16,6 +20,12 @@ service Msg { // Withdraw defines a method for performing a withdrawal of tokens of unused // amount corresponding to a deposit. rpc Withdraw(MsgWithdraw) returns (MsgWithdrawResponse); + + // UpdateParams defines a governance operation for updating the x/house module + // parameters. The authority is defined in the keeper. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) { + option (cosmos_proto.method_added_in) = "sge-network 1.7.1"; + } } // MsgDeposit defines a SDK message for performing a deposit of coins to become @@ -104,3 +114,23 @@ message MsgWithdrawResponse { uint64 participation_index = 3 [ (gogoproto.moretags) = "yaml:\"participation_index\"" ]; } + +// MsgUpdateParams is the Msg/UpdateParams request type. +message MsgUpdateParams { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // params defines the x/bet parameters. + Params params = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +message MsgUpdateParamsResponse { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; +} \ No newline at end of file diff --git a/proto/sgenetwork/sge/market/tx.proto b/proto/sgenetwork/sge/market/tx.proto index 7ed2d7c2..1496317e 100644 --- a/proto/sgenetwork/sge/market/tx.proto +++ b/proto/sgenetwork/sge/market/tx.proto @@ -2,7 +2,11 @@ syntax = "proto3"; package sgenetwork.sge.market; import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; import "sgenetwork/sge/market/market.proto"; +import "sgenetwork/sge/market/params.proto"; option go_package = "github.com/sge-network/sge/x/market/types"; @@ -14,6 +18,11 @@ service Msg { rpc Resolve(MsgResolve) returns (MsgResolveResponse); // Update defines a method to update a market. rpc Update(MsgUpdate) returns (MsgUpdateResponse); + // UpdateParams defines a governance operation for updating the x/market + // module parameters. The authority is defined in the keeper. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) { + option (cosmos_proto.method_added_in) = "sge-network 1.7.1"; + } } // MsgAdd is the message type for adding the market into the @@ -65,3 +74,23 @@ message MsgUpdateResponse { // data is the data of market Market data = 2 [ (gogoproto.nullable) = true ]; } + +// MsgUpdateParams is the Msg/UpdateParams request type. +message MsgUpdateParams { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // params defines the x/bet parameters. + Params params = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +message MsgUpdateParamsResponse { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; +} \ No newline at end of file diff --git a/proto/sgenetwork/sge/orderbook/tx.proto b/proto/sgenetwork/sge/orderbook/tx.proto new file mode 100644 index 00000000..79efdd5e --- /dev/null +++ b/proto/sgenetwork/sge/orderbook/tx.proto @@ -0,0 +1,39 @@ +syntax = "proto3"; +package sgenetwork.sge.orderbook; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; +import "sgenetwork/sge/orderbook/params.proto"; + +option go_package = "github.com/sge-network/sge/x/orderbook/types"; + +// Msg defines the Msg service. +service Msg { + // UpdateParams defines a governance operation for updating the x/market + // module parameters. The authority is defined in the keeper. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) { + option (cosmos_proto.method_added_in) = "sge-network 1.7.1"; + } +} + +// MsgUpdateParams is the Msg/UpdateParams request type. +message MsgUpdateParams { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // params defines the x/bet parameters. + Params params = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +message MsgUpdateParamsResponse { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; +} \ No newline at end of file diff --git a/proto/sgenetwork/sge/ovm/tx.proto b/proto/sgenetwork/sge/ovm/tx.proto index 4e51c2e7..eaeadfd3 100644 --- a/proto/sgenetwork/sge/ovm/tx.proto +++ b/proto/sgenetwork/sge/ovm/tx.proto @@ -1,6 +1,12 @@ syntax = "proto3"; package sgenetwork.sge.ovm; +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; +import "sgenetwork/sge/ovm/params.proto"; + option go_package = "github.com/sge-network/sge/x/ovm/types"; // Msg defines the Msg service. @@ -13,6 +19,11 @@ service Msg { // allowed public keys. rpc VotePubkeysChange(MsgVotePubkeysChangeRequest) returns (MsgVotePubkeysChangeResponse); + // UpdateParams defines a governance operation for updating the x/ovm module + // parameters. The authority is defined in the keeper. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) { + option (cosmos_proto.method_added_in) = "sge-network 1.7.1"; + } } // MsgPubkeysChangeProposalRequest is the type of request for modification of @@ -43,3 +54,23 @@ message MsgVotePubkeysChangeRequest { // MsgVotePubkeysChangeResponse is the type of response vote for public keys // modification. message MsgVotePubkeysChangeResponse { bool success = 1; } + +// MsgUpdateParams is the Msg/UpdateParams request type. +message MsgUpdateParams { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // params defines the x/bet parameters. + Params params = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +message MsgUpdateParamsResponse { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; +} \ No newline at end of file diff --git a/proto/sgenetwork/sge/reward/tx.proto b/proto/sgenetwork/sge/reward/tx.proto index 391480bf..cb925270 100644 --- a/proto/sgenetwork/sge/reward/tx.proto +++ b/proto/sgenetwork/sge/reward/tx.proto @@ -3,6 +3,10 @@ syntax = "proto3"; package sgenetwork.sge.reward; import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; +import "sgenetwork/sge/reward/params.proto"; option go_package = "github.com/sge-network/sge/x/reward/types"; @@ -20,6 +24,11 @@ service Msg { rpc WithdrawFunds(MsgWithdrawFunds) returns (MsgWithdrawFundsResponse); // GrantReward is method to allocate rewards rpc GrantReward(MsgGrantReward) returns (MsgGrantRewardResponse); + // UpdateParams defines a governance operation for updating the x/ovm module + // parameters. The authority is defined in the keeper. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) { + option (cosmos_proto.method_added_in) = "sge-network 1.7.1"; + } } // MsgCreatePromoter is msg to create a promoter. @@ -117,3 +126,23 @@ message MsgWithdrawFunds { // MsgWithdrawFundsResponse withdraw funds message response type. message MsgWithdrawFundsResponse {} + +// MsgUpdateParams is the Msg/UpdateParams request type. +message MsgUpdateParams { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // params defines the x/bet parameters. + Params params = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +message MsgUpdateParamsResponse { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; +} \ No newline at end of file diff --git a/proto/sgenetwork/sge/subaccount/tx.proto b/proto/sgenetwork/sge/subaccount/tx.proto index f5abc264..ebaba891 100644 --- a/proto/sgenetwork/sge/subaccount/tx.proto +++ b/proto/sgenetwork/sge/subaccount/tx.proto @@ -1,10 +1,14 @@ syntax = "proto3"; package sgenetwork.sge.subaccount; +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; import "sgenetwork/sge/subaccount/balance.proto"; +import "sgenetwork/sge/subaccount/params.proto"; import "sgenetwork/sge/house/tx.proto"; import "sgenetwork/sge/bet/tx.proto"; -import "gogoproto/gogo.proto"; option go_package = "github.com/sge-network/sge/x/subaccount/types"; @@ -30,6 +34,12 @@ service Msg { // HouseWithdraw defines a method for withdrawing funds from a market. rpc HouseWithdraw(MsgHouseWithdraw) returns (MsgHouseWithdrawResponse); + + // UpdateParams defines a governance operation for updating the x/subaccount + // module parameters. The authority is defined in the keeper. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) { + option (cosmos_proto.method_added_in) = "sge-network 1.7.1"; + } } // MsgCreate defines the Msg/Create request type. @@ -103,4 +113,24 @@ message MsgHouseWithdraw { sge.house.MsgWithdraw msg = 1; } // MsgHouseWithdrawResponse wraps the MsgHouseWithdrawResponse message. We need // it in order not to have double interface registration conflicts. -message MsgHouseWithdrawResponse { sge.house.MsgWithdrawResponse response = 1; } \ No newline at end of file +message MsgHouseWithdrawResponse { sge.house.MsgWithdrawResponse response = 1; } + +// MsgUpdateParams is the Msg/UpdateParams request type. +message MsgUpdateParams { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // params defines the x/bet parameters. + Params params = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +message MsgUpdateParamsResponse { + option (cosmos_proto.message_added_in) = "sge-network 1.7.1"; +} \ No newline at end of file diff --git a/x/bet/handler.go b/x/bet/handler.go index d340d1af..fba87cea 100644 --- a/x/bet/handler.go +++ b/x/bet/handler.go @@ -22,6 +22,10 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgWager: res, err := msgServer.Wager(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgUpdateParams: + res, err := msgServer.UpdateParams(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) return nil, sdkerrors.Wrap(sdkerrtypes.ErrUnknownRequest, errMsg) diff --git a/x/bet/keeper/keeper.go b/x/bet/keeper/keeper.go index 37e14353..7129df83 100644 --- a/x/bet/keeper/keeper.go +++ b/x/bet/keeper/keeper.go @@ -21,6 +21,10 @@ type Keeper struct { marketKeeper types.MarketKeeper orderbookKeeper types.OrderbookKeeper ovmKeeper types.OVMKeeper + + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string } // NewKeeper creates new keeper object @@ -29,6 +33,7 @@ func NewKeeper( storeKey, memKey storetypes.StoreKey, ps paramtypes.Subspace, + authority string, ) *Keeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { @@ -40,6 +45,7 @@ func NewKeeper( storeKey: storeKey, memKey: memKey, paramstore: ps, + authority: authority, } } @@ -62,3 +68,8 @@ func (k *Keeper) SetOVMKeeper(ovmKeeper types.OVMKeeper) { func (Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } + +// GetAuthority returns the x/bet module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} diff --git a/x/bet/keeper/msg_server_params.go b/x/bet/keeper/msg_server_params.go new file mode 100644 index 00000000..d3be132e --- /dev/null +++ b/x/bet/keeper/msg_server_params.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/sge-network/sge/x/bet/types" +) + +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if k.GetAuthority() != req.Authority { + return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + } + + if err := req.Params.Validate(); err != nil { + return nil, err + } + + k.SetParams(ctx, req.Params) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/bet/simulation/proposals.go b/x/bet/simulation/proposals.go new file mode 100644 index 00000000..b8e12cd3 --- /dev/null +++ b/x/bet/simulation/proposals.go @@ -0,0 +1,50 @@ +package simulation + +import ( + "math/rand" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/sge-network/sge/x/bet/types" +) + +// Simulation operation weights constants +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.BatchSettlementCount = uint32(r.Intn(10000)) + params.MaxBetByUidQueryCount = uint32(r.Intn(1000)) + params.Constraints = types.Constraints{ + MinAmount: sdkmath.NewInt(int64(r.Intn(1000))), + Fee: sdkmath.NewInt(int64(r.Intn(99))), + } + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/bet/simulation/proposals_test.go b/x/bet/simulation/proposals_test.go new file mode 100644 index 00000000..9dd7cce6 --- /dev/null +++ b/x/bet/simulation/proposals_test.go @@ -0,0 +1,49 @@ +package simulation_test + +import ( + "fmt" + "math/rand" + "testing" + + sdkmath "cosmossdk.io/math" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sge-network/sge/x/bet/simulation" + "github.com/sge-network/sge/x/bet/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + require.Equal(t, len(weightedProposalMsgs), 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + require.True(t, ok) + + fmt.Println(msgUpdateParams) + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + require.Equal(t, uint32(2540), msgUpdateParams.Params.BatchSettlementCount) + require.Equal(t, uint32(456), msgUpdateParams.Params.MaxBetByUidQueryCount) + require.Equal(t, types.Constraints{ + MinAmount: sdkmath.NewInt(300), + Fee: sdkmath.NewInt(59), + }, msgUpdateParams.Params.Constraints) +} diff --git a/x/bet/types/codec.go b/x/bet/types/codec.go index 1aec2d62..16f7f480 100644 --- a/x/bet/types/codec.go +++ b/x/bet/types/codec.go @@ -12,12 +12,14 @@ import ( // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgWager{}, "bet/Wager") + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "bet/MsgUpdateParams") } // RegisterInterfaces registers the module interface types func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgWager{}, + &MsgUpdateParams{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/bet/types/messages_params.go b/x/bet/types/messages_params.go new file mode 100644 index 00000000..aa88b732 --- /dev/null +++ b/x/bet/types/messages_params.go @@ -0,0 +1,43 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // typeMsgUpdateParams is type of message MsgUpdateParams + typeMsgUpdateParams = "bet_update_params" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +// Route returns the module's message router key. +func (*MsgUpdateParams) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgUpdateParams) Type() string { return typeMsgUpdateParams } + +// GetSigners returns the expected signers for a MsgUpdateParams message. +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgUpdateParams) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// ValidateBasic does a sanity check on the provided data. +func (msg *MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "invalid authority address") + } + + if err := msg.Params.Validate(); err != nil { + return err + } + + return nil +} diff --git a/x/bet/types/tx.pb.go b/x/bet/types/tx.pb.go index 41b3a93d..c65e92a8 100644 --- a/x/bet/types/tx.pb.go +++ b/x/bet/types/tx.pb.go @@ -6,6 +6,10 @@ package types import ( context "context" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" grpc "google.golang.org/grpc" @@ -128,30 +132,139 @@ func (m *MsgWagerResponse) GetProps() *WagerProps { return nil } +// MsgUpdateParams is the Msg/UpdateParams request type. +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/bet parameters. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_3fc41486184bd76d, []int{2} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_3fc41486184bd76d, []int{3} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgWager)(nil), "sgenetwork.sge.bet.MsgWager") proto.RegisterType((*MsgWagerResponse)(nil), "sgenetwork.sge.bet.MsgWagerResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "sgenetwork.sge.bet.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "sgenetwork.sge.bet.MsgUpdateParamsResponse") } func init() { proto.RegisterFile("sgenetwork/sge/bet/tx.proto", fileDescriptor_3fc41486184bd76d) } var fileDescriptor_3fc41486184bd76d = []byte{ - // 238 bytes of a gzipped FileDescriptorProto + // 446 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2e, 0x4e, 0x4f, 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0x2f, 0x4e, 0x4f, 0xd5, 0x4f, 0x4a, 0x2d, 0xd1, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x42, 0x48, 0xea, 0x15, 0xa7, 0xa7, 0xea, - 0x25, 0xa5, 0x96, 0x48, 0xc9, 0x61, 0xd1, 0x50, 0x9e, 0x98, 0x9e, 0x5a, 0x04, 0xd1, 0xa3, 0x14, - 0xc5, 0xc5, 0xe1, 0x5b, 0x9c, 0x1e, 0x0e, 0x12, 0x11, 0x92, 0xe0, 0x62, 0x4f, 0x2e, 0x4a, 0x4d, - 0x2c, 0xc9, 0x2f, 0x92, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0x71, 0x85, 0x4c, 0xb8, 0x58, - 0x0b, 0x8a, 0xf2, 0x0b, 0x8a, 0x25, 0x98, 0x14, 0x18, 0x35, 0xb8, 0x8d, 0xe4, 0xf4, 0x30, 0x6d, - 0xd2, 0x03, 0x9b, 0x11, 0x00, 0x52, 0x15, 0x04, 0x51, 0xac, 0xe4, 0xc1, 0x25, 0x00, 0x33, 0x3b, - 0x28, 0xb5, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x15, 0x61, 0x12, 0x23, 0x09, 0x26, 0x19, 0x05, 0x71, - 0x31, 0xfb, 0x16, 0xa7, 0x0b, 0x79, 0x73, 0xb1, 0x42, 0x5c, 0x2a, 0x83, 0x4d, 0x1b, 0xcc, 0x2e, - 0x29, 0x15, 0x7c, 0xb2, 0x30, 0x97, 0x38, 0x39, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, - 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, - 0x1c, 0x43, 0x94, 0x5a, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0x2e, 0x28, 0xcc, - 0x74, 0x91, 0xc3, 0xaf, 0x02, 0x12, 0xe4, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x20, 0x34, - 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xbd, 0xa6, 0x56, 0x07, 0x95, 0x01, 0x00, 0x00, + 0x25, 0xa5, 0x96, 0x48, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0xa5, 0xf5, 0x41, 0x2c, 0x88, 0x4a, + 0x29, 0xc9, 0xe4, 0xfc, 0xe2, 0xdc, 0xfc, 0xe2, 0x78, 0x88, 0x04, 0x84, 0x03, 0x95, 0x12, 0x87, + 0xf0, 0xf4, 0x73, 0x8b, 0xd3, 0xf5, 0xcb, 0x0c, 0x41, 0x14, 0x54, 0x42, 0x30, 0x31, 0x37, 0x33, + 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0x85, 0xe4, 0xb0, 0xb8, 0xa6, 0x3c, 0x31, 0x3d, 0xb5, 0x08, 0x2a, + 0x2f, 0x8f, 0x45, 0xbe, 0x20, 0xb1, 0x28, 0x31, 0x17, 0x6a, 0x99, 0x52, 0x14, 0x17, 0x87, 0x6f, + 0x71, 0x7a, 0x38, 0x48, 0x8b, 0x90, 0x04, 0x17, 0x7b, 0x72, 0x51, 0x6a, 0x62, 0x49, 0x7e, 0x91, + 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x8c, 0x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9b, 0x8b, + 0x15, 0x12, 0x19, 0x32, 0xd8, 0x9c, 0x05, 0x0b, 0x4e, 0x29, 0x15, 0x7c, 0xb2, 0xf0, 0xc0, 0x2e, + 0xe7, 0xe2, 0x41, 0x09, 0x32, 0x65, 0x1c, 0xba, 0x90, 0x15, 0x49, 0x69, 0x13, 0xa1, 0x08, 0x66, + 0x83, 0x92, 0xe8, 0x29, 0x6c, 0xbe, 0x71, 0x72, 0x38, 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, 0xb5, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x24, + 0x7d, 0xe0, 0xc4, 0x59, 0x01, 0xc9, 0x4c, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0xe4, 0x69, + 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x89, 0x41, 0x5e, 0x1f, 0x6f, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -168,6 +281,9 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // Wager defines a method to place a bet with the given data. Wager(ctx context.Context, in *MsgWager, opts ...grpc.CallOption) (*MsgWagerResponse, error) + // UpdateParams defines a governance operation for updating the x/bet module + // parameters. The authority is defined in the keeper. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -187,10 +303,22 @@ func (c *msgClient) Wager(ctx context.Context, in *MsgWager, opts ...grpc.CallOp return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.bet.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // Wager defines a method to place a bet with the given data. Wager(context.Context, *MsgWager) (*MsgWagerResponse, error) + // UpdateParams defines a governance operation for updating the x/bet module + // parameters. The authority is defined in the keeper. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -200,6 +328,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) Wager(ctx context.Context, req *MsgWager) (*MsgWagerResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Wager not implemented") } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -223,6 +354,24 @@ func _Msg_Wager_Handler(srv interface{}, ctx context.Context, dec func(interface return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.bet.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "sgenetwork.sge.bet.Msg", HandlerType: (*MsgServer)(nil), @@ -231,6 +380,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "Wager", Handler: _Msg_Wager_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "sgenetwork/sge/bet/tx.proto", @@ -313,6 +466,69 @@ func (m *MsgWagerResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) 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 = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -354,6 +570,30 @@ func (m *MsgWagerResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -564,6 +804,171 @@ func (m *MsgWagerResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) 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 ErrIntOverflowTx + } + 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + 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 := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) 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 ErrIntOverflowTx + } + 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/house/handler.go b/x/house/handler.go index d30821f6..f91f412d 100644 --- a/x/house/handler.go +++ b/x/house/handler.go @@ -22,10 +22,12 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgDeposit: res, err := msgServer.Deposit(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) - case *types.MsgWithdraw: res, err := msgServer.Withdraw(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgUpdateParams: + res, err := msgServer.UpdateParams(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) diff --git a/x/house/keeper/keeper.go b/x/house/keeper/keeper.go index f35c0b5d..1609658f 100644 --- a/x/house/keeper/keeper.go +++ b/x/house/keeper/keeper.go @@ -16,6 +16,9 @@ type Keeper struct { authzKeeper types.AuthzKeeper orderbookKeeper types.OrderbookKeeper ovmKeeper types.OVMKeeper + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string } // SdkExpectedKeepers contains expected keepers parameter needed by NewKeeper @@ -31,6 +34,7 @@ func NewKeeper( ovmKeeper types.OVMKeeper, ps paramtypes.Subspace, expectedKeepers SdkExpectedKeepers, + authority string, ) *Keeper { // set KeyTable if it is not already set if !ps.HasKeyTable() { @@ -44,5 +48,11 @@ func NewKeeper( ovmKeeper: ovmKeeper, paramstore: ps, authzKeeper: expectedKeepers.AuthzKeeper, + authority: authority, } } + +// GetAuthority returns the x/house module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} diff --git a/x/house/keeper/msg_server_params.go b/x/house/keeper/msg_server_params.go new file mode 100644 index 00000000..1890752c --- /dev/null +++ b/x/house/keeper/msg_server_params.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/sge-network/sge/x/house/types" +) + +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if k.GetAuthority() != req.Authority { + return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + } + + if err := req.Params.Validate(); err != nil { + return nil, err + } + + k.SetParams(ctx, req.Params) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/house/simulation/proposals.go b/x/house/simulation/proposals.go new file mode 100644 index 00000000..b0664565 --- /dev/null +++ b/x/house/simulation/proposals.go @@ -0,0 +1,47 @@ +package simulation + +import ( + "math/rand" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/sge-network/sge/x/house/types" +) + +// Simulation operation weights constants +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.MaxWithdrawalCount = uint64(r.Intn(10000)) + params.HouseParticipationFee = sdkmath.LegacyNewDecFromIntWithPrec(sdkmath.NewInt(int64(r.Intn(1000))), 2) + params.MinDeposit = sdkmath.NewInt(int64(r.Intn(1000))) + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/house/simulation/proposals_test.go b/x/house/simulation/proposals_test.go new file mode 100644 index 00000000..6d2de8dd --- /dev/null +++ b/x/house/simulation/proposals_test.go @@ -0,0 +1,46 @@ +package simulation_test + +import ( + "fmt" + "math/rand" + "testing" + + sdkmath "cosmossdk.io/math" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sge-network/sge/x/house/simulation" + "github.com/sge-network/sge/x/house/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + require.Equal(t, len(weightedProposalMsgs), 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + require.True(t, ok) + + fmt.Println(msgUpdateParams) + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + require.Equal(t, uint64(2540), msgUpdateParams.Params.MaxWithdrawalCount) + require.Equal(t, sdkmath.LegacyNewDecWithPrec(456, 2), msgUpdateParams.Params.HouseParticipationFee) + require.Equal(t, sdkmath.NewInt(300), msgUpdateParams.Params.MinDeposit) +} diff --git a/x/house/types/codec.go b/x/house/types/codec.go index 01718d61..d428622f 100644 --- a/x/house/types/codec.go +++ b/x/house/types/codec.go @@ -14,6 +14,7 @@ import ( func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgDeposit{}, "house/Deposit") legacy.RegisterAminoMsg(cdc, &MsgWithdraw{}, "house/Withdraw") + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "house/MsgUpdateParams") } // RegisterInterfaces registers the x/house interfaces types with the interface registry @@ -21,6 +22,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgDeposit{}, &MsgWithdraw{}, + &MsgUpdateParams{}, ) registry.RegisterImplementations( (*authz.Authorization)(nil), diff --git a/x/house/types/messages_params.go b/x/house/types/messages_params.go new file mode 100644 index 00000000..ba6bb187 --- /dev/null +++ b/x/house/types/messages_params.go @@ -0,0 +1,43 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // typeMsgUpdateParams is type of message MsgUpdateParams + typeMsgUpdateParams = "house_update_params" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +// Route returns the module's message router key. +func (*MsgUpdateParams) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgUpdateParams) Type() string { return typeMsgUpdateParams } + +// GetSigners returns the expected signers for a MsgUpdateParams message. +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgUpdateParams) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// ValidateBasic does a sanity check on the provided data. +func (msg *MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "invalid authority address") + } + + if err := msg.Params.Validate(); err != nil { + return err + } + + return nil +} diff --git a/x/house/types/tx.pb.go b/x/house/types/tx.pb.go index faf8b263..5a36adcb 100644 --- a/x/house/types/tx.pb.go +++ b/x/house/types/tx.pb.go @@ -7,6 +7,9 @@ import ( context "context" cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" @@ -247,50 +250,157 @@ func (m *MsgWithdrawResponse) GetParticipationIndex() uint64 { return 0 } +// MsgUpdateParams is the Msg/UpdateParams request type. +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/bet parameters. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_0764ff859f434eaf, []int{4} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_0764ff859f434eaf, []int{5} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgDeposit)(nil), "sgenetwork.sge.house.MsgDeposit") proto.RegisterType((*MsgDepositResponse)(nil), "sgenetwork.sge.house.MsgDepositResponse") proto.RegisterType((*MsgWithdraw)(nil), "sgenetwork.sge.house.MsgWithdraw") proto.RegisterType((*MsgWithdrawResponse)(nil), "sgenetwork.sge.house.MsgWithdrawResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "sgenetwork.sge.house.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "sgenetwork.sge.house.MsgUpdateParamsResponse") } func init() { proto.RegisterFile("sgenetwork/sge/house/tx.proto", fileDescriptor_0764ff859f434eaf) } var fileDescriptor_0764ff859f434eaf = []byte{ - // 524 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x54, 0xc1, 0x6a, 0xdb, 0x40, - 0x10, 0xd5, 0xca, 0xae, 0x13, 0x6f, 0x20, 0x85, 0x4d, 0x5a, 0x5c, 0x95, 0x68, 0x53, 0xb5, 0x07, - 0x07, 0x5a, 0x09, 0x52, 0x7a, 0x49, 0x6f, 0x22, 0x17, 0x1f, 0x44, 0x41, 0x10, 0x5a, 0x7a, 0x09, - 0x8a, 0xb4, 0xc8, 0x8b, 0x23, 0xad, 0xd0, 0xae, 0xb1, 0xf3, 0x07, 0x3d, 0xf6, 0x13, 0x42, 0x3f, - 0xa2, 0xdf, 0x90, 0x53, 0xf1, 0xb1, 0xf4, 0x20, 0x8a, 0x7c, 0x29, 0x85, 0x5e, 0xfc, 0x05, 0xc5, - 0x2b, 0xc9, 0x56, 0x8b, 0x4d, 0xa8, 0x0f, 0x25, 0xb7, 0xd5, 0xcc, 0x9b, 0xd1, 0xbc, 0xb7, 0x6f, - 0x07, 0x1e, 0xf0, 0x90, 0xc4, 0x44, 0x8c, 0x58, 0x3a, 0xb0, 0x78, 0x48, 0xac, 0x3e, 0x1b, 0x72, - 0x62, 0x89, 0xb1, 0x99, 0xa4, 0x4c, 0x30, 0xb4, 0xbf, 0x4c, 0x9b, 0x3c, 0x24, 0xa6, 0x4c, 0x6b, - 0xfb, 0x21, 0x0b, 0x99, 0x04, 0x58, 0xf3, 0x53, 0x81, 0xd5, 0x9e, 0xae, 0x6c, 0x35, 0xa2, 0xa2, - 0x1f, 0xa4, 0xde, 0xa8, 0x00, 0x19, 0x13, 0x00, 0xa1, 0xc3, 0xc3, 0x53, 0x92, 0x30, 0x4e, 0x05, - 0x7a, 0x0e, 0xb7, 0xfc, 0x94, 0x78, 0x82, 0xa5, 0x1d, 0x70, 0x08, 0xba, 0x6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0x3d, 0x7e, 0x66, 0xae, 0xf2, 0xa8, 0x59, 0x31, 0xf5, 0x2e, 0x1d, 0x16, 0x10, 0xfb, 0xfe, - 0x2c, 0xc3, 0x3b, 0xc5, 0x7f, 0xe6, 0xb5, 0x86, 0x2b, 0x5b, 0xd4, 0x4c, 0x71, 0x6f, 0x33, 0x53, - 0xb4, 0xd6, 0x98, 0xe2, 0x0b, 0x80, 0x7b, 0x35, 0xbd, 0x17, 0xae, 0x38, 0x82, 0x6a, 0xe9, 0x86, - 0xa6, 0xfd, 0x28, 0xcf, 0xb0, 0x2a, 0xa5, 0x53, 0x69, 0x30, 0xcb, 0x70, 0xbb, 0x98, 0x8f, 0x06, - 0x86, 0xab, 0xd2, 0xe0, 0x6e, 0x89, 0x7e, 0xfc, 0x19, 0xc0, 0x86, 0xc3, 0x43, 0x74, 0x06, 0xb7, - 0xaa, 0xc7, 0x7b, 0xb8, 0x5a, 0xf9, 0xe5, 0x5b, 0xd0, 0xba, 0xb7, 0x21, 0x16, 0xba, 0xbc, 0x83, - 0xdb, 0x0b, 0x6f, 0x3e, 0x59, 0x5b, 0x55, 0x41, 0xb4, 0xa3, 0x5b, 0x21, 0x55, 0x67, 0xdb, 0xbe, - 0xc9, 0x75, 0x30, 0xc9, 0x75, 0xf0, 0x3d, 0xd7, 0xc1, 0xc7, 0xa9, 0xae, 0x4c, 0xa6, 0xba, 0xf2, - 0x75, 0xaa, 0x2b, 0xef, 0xbb, 0x21, 0x15, 0xfd, 0xe1, 0x85, 0xe9, 0xb3, 0x68, 0xbe, 0xb0, 0x5e, - 0xd4, 0x97, 0xd7, 0xb8, 0xda, 0x84, 0x57, 0x09, 0xe1, 0x17, 0x2d, 0xb9, 0xbc, 0x5e, 0xfe, 0x0e, - 0x00, 0x00, 0xff, 0xff, 0x17, 0xd2, 0x1d, 0xcc, 0x2e, 0x05, 0x00, 0x00, + // 703 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x55, 0x4f, 0x4f, 0xd4, 0x4c, + 0x18, 0xdf, 0x96, 0x7d, 0x17, 0x76, 0x78, 0x03, 0xa1, 0xc0, 0xcb, 0xb2, 0xaf, 0xb4, 0x50, 0x34, + 0x01, 0xe2, 0xb6, 0x82, 0x51, 0x93, 0xf5, 0x60, 0x6c, 0xb8, 0xec, 0x61, 0xa3, 0xa9, 0x21, 0x1a, + 0x2f, 0x64, 0xd8, 0x4e, 0xba, 0x93, 0xa5, 0x9d, 0xa6, 0x33, 0x2b, 0x10, 0x6f, 0x9e, 0x3c, 0xfa, + 0x11, 0x88, 0x27, 0x6f, 0x92, 0xc8, 0x87, 0x20, 0x1e, 0x0c, 0xe1, 0x64, 0x3c, 0x34, 0x66, 0x39, + 0x60, 0x4c, 0xbc, 0xec, 0x27, 0x30, 0x3b, 0x9d, 0xee, 0x2e, 0xa4, 0x1b, 0x94, 0x83, 0xf1, 0xd2, + 0xce, 0x3c, 0xcf, 0xef, 0x37, 0xcf, 0xff, 0x19, 0x30, 0x47, 0x5d, 0xe4, 0x23, 0xb6, 0x43, 0xc2, + 0x86, 0x49, 0x5d, 0x64, 0xd6, 0x49, 0x93, 0x22, 0x93, 0xed, 0x1a, 0x41, 0x48, 0x18, 0x51, 0xa6, + 0x7a, 0x6a, 0x83, 0xba, 0xc8, 0xe0, 0xea, 0xe2, 0x94, 0x4b, 0x5c, 0xc2, 0x01, 0x66, 0x67, 0x15, + 0x63, 0x8b, 0xb3, 0x35, 0x42, 0x3d, 0x42, 0x37, 0x63, 0x45, 0xbc, 0x11, 0xaa, 0x99, 0x78, 0x67, + 0x7a, 0xd4, 0x35, 0x5f, 0xac, 0x76, 0x7e, 0x42, 0x31, 0x01, 0x3d, 0xec, 0x13, 0x93, 0x7f, 0x85, + 0x68, 0x31, 0xd5, 0xa3, 0x1d, 0xcc, 0xea, 0x4e, 0x08, 0x77, 0x04, 0x68, 0x21, 0x15, 0x14, 0xc0, + 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xc6, 0x3d, 0x63, 0xf5, + 0xd5, 0xd9, 0xc1, 0x4a, 0xcf, 0x8a, 0x7e, 0x0b, 0xcc, 0x5c, 0x70, 0x38, 0xa9, 0x42, 0x79, 0x3a, + 0x95, 0xbf, 0xf6, 0x41, 0x06, 0x43, 0x55, 0xea, 0x2a, 0x1b, 0x60, 0x38, 0xb9, 0xa0, 0xe6, 0xd3, + 0x5d, 0xeb, 0xcd, 0x7b, 0x71, 0xe9, 0x32, 0x44, 0xb7, 0xf6, 0xcf, 0xc0, 0x48, 0x77, 0xfe, 0x16, + 0x06, 0xb2, 0x12, 0x48, 0x71, 0xf9, 0x52, 0x48, 0xf7, 0xe4, 0x97, 0xe0, 0xdf, 0x73, 0x85, 0xb9, + 0x31, 0x90, 0xda, 0x0f, 0x2b, 0x96, 0x7e, 0x09, 0x96, 0x58, 0xd1, 0xa7, 0x3f, 0xa6, 0x65, 0xcd, + 0xb2, 0x8e, 0x5a, 0xaa, 0x74, 0xdc, 0x52, 0xa5, 0xaf, 0x2d, 0x55, 0x7a, 0x73, 0xaa, 0x66, 0x8e, + 0x4f, 0xd5, 0xcc, 0xe7, 0x53, 0x35, 0xf3, 0x7c, 0xc9, 0xc5, 0xac, 0xde, 0xdc, 0x32, 0x6a, 0xc4, + 0x33, 0xfb, 0x78, 0xfc, 0x6d, 0xd8, 0x4d, 0x1e, 0xb5, 0xbd, 0x00, 0xd1, 0xad, 0x1c, 0x7f, 0x1d, + 0x6e, 0xff, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x4c, 0x02, 0x7e, 0x9d, 0xf9, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -312,6 +422,9 @@ type MsgClient interface { // Withdraw defines a method for performing a withdrawal of tokens of unused // amount corresponding to a deposit. Withdraw(ctx context.Context, in *MsgWithdraw, opts ...grpc.CallOption) (*MsgWithdrawResponse, error) + // UpdateParams defines a governance operation for updating the x/house module + // parameters. The authority is defined in the keeper. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -340,6 +453,15 @@ func (c *msgClient) Withdraw(ctx context.Context, in *MsgWithdraw, opts ...grpc. return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.house.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // Deposit defines a method for performing a deposit of tokens to become part @@ -349,6 +471,9 @@ type MsgServer interface { // Withdraw defines a method for performing a withdrawal of tokens of unused // amount corresponding to a deposit. Withdraw(context.Context, *MsgWithdraw) (*MsgWithdrawResponse, error) + // UpdateParams defines a governance operation for updating the x/house module + // parameters. The authority is defined in the keeper. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -361,6 +486,9 @@ func (*UnimplementedMsgServer) Deposit(ctx context.Context, req *MsgDeposit) (*M func (*UnimplementedMsgServer) Withdraw(ctx context.Context, req *MsgWithdraw) (*MsgWithdrawResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Withdraw not implemented") } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -402,6 +530,24 @@ func _Msg_Withdraw_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.house.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "sgenetwork.sge.house.Msg", HandlerType: (*MsgServer)(nil), @@ -414,6 +560,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "Withdraw", Handler: _Msg_Withdraw_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "sgenetwork/sge/house/tx.proto", @@ -612,6 +762,69 @@ func (m *MsgWithdrawResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) 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 = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -710,6 +923,30 @@ func (m *MsgWithdrawResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1335,6 +1572,171 @@ func (m *MsgWithdrawResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) 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 ErrIntOverflowTx + } + 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + 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 := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) 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 ErrIntOverflowTx + } + 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/market/handler.go b/x/market/handler.go index 220bb5f5..0e5139e5 100644 --- a/x/market/handler.go +++ b/x/market/handler.go @@ -29,6 +29,10 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgUpdate: res, err := msgServer.Update(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgUpdateParams: + res, err := msgServer.UpdateParams(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) return nil, sdkerrors.Wrap(sdkerrtypes.ErrUnknownRequest, errMsg) diff --git a/x/market/keeper/keeper.go b/x/market/keeper/keeper.go index e437d580..65b8597f 100644 --- a/x/market/keeper/keeper.go +++ b/x/market/keeper/keeper.go @@ -22,6 +22,9 @@ type Keeper struct { paramStore paramtypes.Subspace ovmKeeper types.OVMKeeper orderbookKeeper types.OrderbookKeeper + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string } // NewKeeper creates new keeper object @@ -30,6 +33,7 @@ func NewKeeper( storeKey, memKey storetypes.StoreKey, ps paramtypes.Subspace, + authority string, ) *Keeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { @@ -41,6 +45,7 @@ func NewKeeper( storeKey: storeKey, memKey: memKey, paramStore: ps, + authority: authority, } } @@ -58,3 +63,8 @@ func (k *Keeper) SetOVMKeeper(ovmKeeper types.OVMKeeper) { func (Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } + +// GetAuthority returns the x/market module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} diff --git a/x/market/keeper/msg_server_params.go b/x/market/keeper/msg_server_params.go new file mode 100644 index 00000000..31fa96e4 --- /dev/null +++ b/x/market/keeper/msg_server_params.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/sge-network/sge/x/market/types" +) + +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if k.GetAuthority() != req.Authority { + return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + } + + if err := req.Params.Validate(); err != nil { + return nil, err + } + + k.SetParams(ctx, req.Params) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/market/simulation/proposals.go b/x/market/simulation/proposals.go new file mode 100644 index 00000000..0747f83c --- /dev/null +++ b/x/market/simulation/proposals.go @@ -0,0 +1,43 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/sge-network/sge/x/market/types" +) + +// Simulation operation weights constants +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/market/simulation/proposals_test.go b/x/market/simulation/proposals_test.go new file mode 100644 index 00000000..8a7d06e6 --- /dev/null +++ b/x/market/simulation/proposals_test.go @@ -0,0 +1,42 @@ +package simulation_test + +import ( + "fmt" + "math/rand" + "testing" + + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sge-network/sge/x/market/simulation" + "github.com/sge-network/sge/x/market/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + require.Equal(t, len(weightedProposalMsgs), 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + require.True(t, ok) + + fmt.Println(msgUpdateParams) + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) +} diff --git a/x/market/types/codec.go b/x/market/types/codec.go index 66a82e9a..348363be 100644 --- a/x/market/types/codec.go +++ b/x/market/types/codec.go @@ -14,6 +14,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgAdd{}, "market/Add") legacy.RegisterAminoMsg(cdc, &MsgResolve{}, "market/Resolve") legacy.RegisterAminoMsg(cdc, &MsgUpdate{}, "market/Update") + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "market/MsgUpdateParams") } // RegisterInterfaces registers the module interface types @@ -21,12 +22,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil)) registry.RegisterImplementations((*sdk.Msg)(nil), &MsgAdd{}, - ) - registry.RegisterImplementations((*sdk.Msg)(nil), &MsgResolve{}, - ) - registry.RegisterImplementations((*sdk.Msg)(nil), &MsgUpdate{}, + &MsgUpdateParams{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/market/types/messages_params.go b/x/market/types/messages_params.go new file mode 100644 index 00000000..e357ac1e --- /dev/null +++ b/x/market/types/messages_params.go @@ -0,0 +1,43 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // typeMsgUpdateParams is type of message MsgUpdateParams + typeMsgUpdateParams = "market_update_params" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +// Route returns the module's message router key. +func (*MsgUpdateParams) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgUpdateParams) Type() string { return typeMsgUpdateParams } + +// GetSigners returns the expected signers for a MsgUpdateParams message. +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgUpdateParams) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// ValidateBasic does a sanity check on the provided data. +func (msg *MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "invalid authority address") + } + + if err := msg.Params.Validate(); err != nil { + return err + } + + return nil +} diff --git a/x/market/types/tx.pb.go b/x/market/types/tx.pb.go index b84f75d8..8da3fc8b 100644 --- a/x/market/types/tx.pb.go +++ b/x/market/types/tx.pb.go @@ -6,6 +6,9 @@ package types import ( context "context" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" @@ -360,6 +363,100 @@ func (m *MsgUpdateResponse) GetData() *Market { return nil } +// MsgUpdateParams is the Msg/UpdateParams request type. +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/bet parameters. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_cb37002f2abdafc2, []int{6} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cb37002f2abdafc2, []int{7} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgAdd)(nil), "sgenetwork.sge.market.MsgAdd") proto.RegisterType((*MsgAddResponse)(nil), "sgenetwork.sge.market.MsgAddResponse") @@ -367,35 +464,47 @@ func init() { proto.RegisterType((*MsgResolveResponse)(nil), "sgenetwork.sge.market.MsgResolveResponse") proto.RegisterType((*MsgUpdate)(nil), "sgenetwork.sge.market.MsgUpdate") proto.RegisterType((*MsgUpdateResponse)(nil), "sgenetwork.sge.market.MsgUpdateResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "sgenetwork.sge.market.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "sgenetwork.sge.market.MsgUpdateParamsResponse") } func init() { proto.RegisterFile("sgenetwork/sge/market/tx.proto", fileDescriptor_cb37002f2abdafc2) } var fileDescriptor_cb37002f2abdafc2 = []byte{ - // 353 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2b, 0x4e, 0x4f, 0xcd, - 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0x2f, 0x4e, 0x4f, 0xd5, 0xcf, 0x4d, 0x2c, 0xca, 0x4e, - 0x2d, 0xd1, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x45, 0xc8, 0xeb, 0x15, - 0xa7, 0xa7, 0xea, 0x41, 0xe4, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x2a, 0xf4, 0x41, 0x2c, - 0x88, 0x62, 0x29, 0x25, 0xec, 0x86, 0x41, 0x28, 0x88, 0x1a, 0x25, 0x2b, 0x2e, 0x36, 0xdf, 0xe2, - 0x74, 0xc7, 0x94, 0x14, 0x21, 0x09, 0x2e, 0xf6, 0xe4, 0xa2, 0xd4, 0xc4, 0x92, 0xfc, 0x22, 0x09, - 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, 0x18, 0x57, 0x48, 0x8c, 0x8b, 0xad, 0x24, 0x33, 0x39, 0x3b, - 0xb5, 0x44, 0x82, 0x09, 0x2c, 0x01, 0xe5, 0x29, 0xa5, 0x72, 0xf1, 0x41, 0xf4, 0x06, 0xa5, 0x16, - 0x17, 0xe4, 0xe7, 0x15, 0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0xd2, 0x4b, 0xce, 0xcf, - 0x05, 0x65, 0x1c, 0x5d, 0xe4, 0x4c, 0x54, 0x01, 0xcf, 0x93, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, - 0xe0, 0x6c, 0x64, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x9e, 0x8c, 0x3f, 0xf3, 0xb9, 0x03, 0x00, - 0x00, + // 523 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x41, 0x6b, 0x13, 0x41, + 0x18, 0xcd, 0x9a, 0x9a, 0x92, 0x4f, 0x51, 0xb2, 0x34, 0x36, 0x2e, 0xb8, 0x8d, 0x2b, 0x4a, 0x5b, + 0xc8, 0xac, 0xa9, 0x60, 0x21, 0xa0, 0xd8, 0x78, 0x94, 0x05, 0x59, 0x15, 0xc1, 0x8b, 0x4c, 0xb3, + 0xc3, 0x64, 0x89, 0x9b, 0x59, 0x66, 0xa6, 0xb5, 0x3d, 0x08, 0xe2, 0x2f, 0xf0, 0x67, 0x78, 0xcc, + 0xa1, 0x3f, 0x22, 0x78, 0x2a, 0x3d, 0x79, 0x2a, 0x92, 0x1c, 0xfa, 0x37, 0x24, 0x33, 0xb3, 0x1b, + 0x95, 0xa4, 0x29, 0x85, 0x5e, 0x76, 0xf6, 0x9b, 0xf7, 0xde, 0xf7, 0x3d, 0x66, 0x1e, 0x03, 0xae, + 0xa0, 0xa4, 0x4f, 0xe4, 0x67, 0xc6, 0x7b, 0xbe, 0xa0, 0xc4, 0x4f, 0x30, 0xef, 0x11, 0xe9, 0xcb, + 0x03, 0x94, 0x72, 0x26, 0x99, 0x5d, 0x9d, 0xe2, 0x48, 0x50, 0x82, 0x34, 0xee, 0xac, 0x50, 0x46, + 0x99, 0x62, 0xf8, 0x93, 0x3f, 0x4d, 0x76, 0xee, 0x76, 0x98, 0x48, 0x98, 0xf8, 0xa8, 0x01, 0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, 0xea, 0xc9, 0x9f, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xc9, 0x4a, 0x88, 0x51, 0x88, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -416,6 +525,9 @@ type MsgClient interface { Resolve(ctx context.Context, in *MsgResolve, opts ...grpc.CallOption) (*MsgResolveResponse, error) // Update defines a method to update a market. Update(ctx context.Context, in *MsgUpdate, opts ...grpc.CallOption) (*MsgUpdateResponse, error) + // UpdateParams defines a governance operation for updating the x/market + // module parameters. The authority is defined in the keeper. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -453,6 +565,15 @@ func (c *msgClient) Update(ctx context.Context, in *MsgUpdate, opts ...grpc.Call return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.market.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // Add defines a method to add the market with the given data. @@ -461,6 +582,9 @@ type MsgServer interface { Resolve(context.Context, *MsgResolve) (*MsgResolveResponse, error) // Update defines a method to update a market. Update(context.Context, *MsgUpdate) (*MsgUpdateResponse, error) + // UpdateParams defines a governance operation for updating the x/market + // module parameters. The authority is defined in the keeper. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -476,6 +600,9 @@ func (*UnimplementedMsgServer) Resolve(ctx context.Context, req *MsgResolve) (*M func (*UnimplementedMsgServer) Update(ctx context.Context, req *MsgUpdate) (*MsgUpdateResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -535,6 +662,24 @@ func _Msg_Update_Handler(srv interface{}, ctx context.Context, dec func(interfac return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.market.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "sgenetwork.sge.market.Msg", HandlerType: (*MsgServer)(nil), @@ -551,6 +696,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "Update", Handler: _Msg_Update_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "sgenetwork/sge/market/tx.proto", @@ -793,6 +942,69 @@ func (m *MsgUpdateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) 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 = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -906,6 +1118,30 @@ func (m *MsgUpdateResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1608,6 +1844,171 @@ func (m *MsgUpdateResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) 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 ErrIntOverflowTx + } + 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + 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 := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) 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 ErrIntOverflowTx + } + 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/orderbook/handler.go b/x/orderbook/handler.go new file mode 100644 index 00000000..3f8d5c38 --- /dev/null +++ b/x/orderbook/handler.go @@ -0,0 +1,32 @@ +package orderbook + +import ( + "fmt" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/x/orderbook/keeper" + "github.com/sge-network/sge/x/orderbook/types" +) + +// NewHandler initialize a new sdk.handler instance for registered messages +func NewHandler(k keeper.Keeper) sdk.Handler { + msgServer := keeper.NewMsgServerImpl(k) + + return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { + ctx = ctx.WithEventManager(sdk.NewEventManager()) + _ = ctx + + switch msg := msg.(type) { + case *types.MsgUpdateParams: + res, err := msgServer.UpdateParams(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + + default: + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, sdkerrors.Wrap(sdkerrtypes.ErrUnknownRequest, errMsg) + } + } +} diff --git a/x/orderbook/keeper/keeper.go b/x/orderbook/keeper/keeper.go index f0072fb1..cf7312f4 100644 --- a/x/orderbook/keeper/keeper.go +++ b/x/orderbook/keeper/keeper.go @@ -25,6 +25,9 @@ type Keeper struct { ovmKeeper types.OVMKeeper feeGrantKeeper types.FeeGrantKeeper hooks types.OrderBookHooks + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string } // SdkExpectedKeepers contains expected keepers parameter needed by NewKeeper @@ -40,6 +43,7 @@ func NewKeeper( key storetypes.StoreKey, ps paramtypes.Subspace, expectedKeepers SdkExpectedKeepers, + authority string, ) *Keeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { @@ -53,6 +57,7 @@ func NewKeeper( bankKeeper: expectedKeepers.BankKeeper, accountKeeper: expectedKeepers.AccountKeeper, feeGrantKeeper: expectedKeepers.FeeGrantKeeper, + authority: authority, } } @@ -91,3 +96,8 @@ func (k *Keeper) SetHooks(gh types.OrderBookHooks) *Keeper { func (Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } + +// GetAuthority returns the x/orderbook module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} diff --git a/x/orderbook/keeper/msg_server.go b/x/orderbook/keeper/msg_server.go new file mode 100644 index 00000000..ab6771dc --- /dev/null +++ b/x/orderbook/keeper/msg_server.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/sge-network/sge/x/orderbook/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} diff --git a/x/orderbook/keeper/msg_server_params.go b/x/orderbook/keeper/msg_server_params.go new file mode 100644 index 00000000..6d8dc25e --- /dev/null +++ b/x/orderbook/keeper/msg_server_params.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/sge-network/sge/x/orderbook/types" +) + +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if k.GetAuthority() != req.Authority { + return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + } + + if err := req.Params.Validate(); err != nil { + return nil, err + } + + k.SetParams(ctx, req.Params) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/orderbook/keeper/msg_server_test.go b/x/orderbook/keeper/msg_server_test.go new file mode 100644 index 00000000..9fa03ecc --- /dev/null +++ b/x/orderbook/keeper/msg_server_test.go @@ -0,0 +1,19 @@ +package keeper_test + +import ( + "context" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/orderbook/keeper" + "github.com/sge-network/sge/x/orderbook/types" +) + +func setupMsgServerAndApp( + t testing.TB, +) (*simapp.TestApp, *keeper.KeeperTest, types.MsgServer, sdk.Context, context.Context) { + tApp, k, ctx := setupKeeperAndApp(t) + return tApp, k, keeper.NewMsgServerImpl(*k), ctx, sdk.WrapSDKContext(ctx) +} diff --git a/x/orderbook/module.go b/x/orderbook/module.go index 22f27183..4a4cbffb 100644 --- a/x/orderbook/module.go +++ b/x/orderbook/module.go @@ -103,6 +103,7 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } // RegisterServices registers a GRPC query service to respond to the module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), am.keeper) } diff --git a/x/orderbook/simulation/proposals.go b/x/orderbook/simulation/proposals.go new file mode 100644 index 00000000..cdcaa421 --- /dev/null +++ b/x/orderbook/simulation/proposals.go @@ -0,0 +1,46 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/sge-network/sge/x/orderbook/types" +) + +// Simulation operation weights constants +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.BatchSettlementCount = uint64(r.Intn(10000)) + params.MaxOrderBookParticipations = uint64(r.Intn(1000)) + params.RequeueThreshold = uint64(r.Intn(1000)) + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/orderbook/simulation/proposals_test.go b/x/orderbook/simulation/proposals_test.go new file mode 100644 index 00000000..4bc6cccd --- /dev/null +++ b/x/orderbook/simulation/proposals_test.go @@ -0,0 +1,45 @@ +package simulation_test + +import ( + "fmt" + "math/rand" + "testing" + + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sge-network/sge/x/orderbook/simulation" + "github.com/sge-network/sge/x/orderbook/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + require.Equal(t, len(weightedProposalMsgs), 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + require.True(t, ok) + + fmt.Println(msgUpdateParams) + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + require.Equal(t, uint64(2540), msgUpdateParams.Params.BatchSettlementCount) + require.Equal(t, uint64(456), msgUpdateParams.Params.MaxOrderBookParticipations) + require.Equal(t, uint64(300), msgUpdateParams.Params.RequeueThreshold) +} diff --git a/x/orderbook/types/codec.go b/x/orderbook/types/codec.go index 23721c39..57a29568 100644 --- a/x/orderbook/types/codec.go +++ b/x/orderbook/types/codec.go @@ -2,19 +2,25 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" ) // RegisterLegacyAminoCodec registers the necessary x/orderbook interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. -func RegisterLegacyAminoCodec(_ *codec.LegacyAmino) { - // left empty because no message is available in this module +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "orderbook/MsgUpdateParams") } // RegisterInterfaces registers the module interface types func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - registry.RegisterImplementations((*sdk.Msg)(nil)) + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgUpdateParams{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } var ( diff --git a/x/orderbook/types/messages_params.go b/x/orderbook/types/messages_params.go new file mode 100644 index 00000000..e357ac1e --- /dev/null +++ b/x/orderbook/types/messages_params.go @@ -0,0 +1,43 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // typeMsgUpdateParams is type of message MsgUpdateParams + typeMsgUpdateParams = "market_update_params" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +// Route returns the module's message router key. +func (*MsgUpdateParams) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgUpdateParams) Type() string { return typeMsgUpdateParams } + +// GetSigners returns the expected signers for a MsgUpdateParams message. +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgUpdateParams) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// ValidateBasic does a sanity check on the provided data. +func (msg *MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "invalid authority address") + } + + if err := msg.Params.Validate(); err != nil { + return err + } + + return nil +} diff --git a/x/orderbook/types/tx.pb.go b/x/orderbook/types/tx.pb.go new file mode 100644 index 00000000..b5abbfc7 --- /dev/null +++ b/x/orderbook/types/tx.pb.go @@ -0,0 +1,598 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sgenetwork/sge/orderbook/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + 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. +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 + +// MsgUpdateParams is the Msg/UpdateParams request type. +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/bet parameters. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_40bc64b0300596fa, []int{0} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_40bc64b0300596fa, []int{1} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateParams)(nil), "sgenetwork.sge.orderbook.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "sgenetwork.sge.orderbook.MsgUpdateParamsResponse") +} + +func init() { proto.RegisterFile("sgenetwork/sge/orderbook/tx.proto", fileDescriptor_40bc64b0300596fa) } + +var fileDescriptor_40bc64b0300596fa = []byte{ + // 362 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2c, 0x4e, 0x4f, 0xcd, + 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0x2f, 0x4e, 0x4f, 0xd5, 0xcf, 0x2f, 0x4a, 0x49, 0x2d, + 0x4a, 0xca, 0xcf, 0xcf, 0xd6, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x40, + 0x28, 0xd1, 0x2b, 0x4e, 0x4f, 0xd5, 0x83, 0x2b, 0x91, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, + 0xd2, 0x07, 0xb1, 0x20, 0xea, 0xa5, 0x24, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xe3, 0x21, 0x12, + 0x10, 0x0e, 0x54, 0x4a, 0x1c, 0xc2, 0xd3, 0xcf, 0x2d, 0x4e, 0xd7, 0x2f, 0x33, 0x04, 0x51, 0x50, + 0x09, 0xc1, 0xc4, 0xdc, 0xcc, 0xbc, 0x7c, 0x7d, 0x30, 0x09, 0x15, 0x52, 0xc5, 0xe9, 0xb2, 0x82, + 0xc4, 0xa2, 0xc4, 0x5c, 0xa8, 0x91, 0x4a, 0x9b, 0x19, 0xb9, 0xf8, 0x7d, 0x8b, 0xd3, 0x43, 0x0b, + 0x52, 0x12, 0x4b, 0x52, 0x03, 0xc0, 0x32, 0x42, 0x66, 0x5c, 0x9c, 0x89, 0xa5, 0x25, 0x19, 0xf9, + 0x45, 0x99, 0x25, 0x95, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x4e, 0x12, 0x97, 0xb6, 0xe8, 0x8a, + 0x40, 0xdd, 0xe2, 0x98, 0x92, 0x52, 0x94, 0x5a, 0x5c, 0x1c, 0x5c, 0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ff, 0x2d, 0xa0, 0x4b, 0x4d, 0x87, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // UpdateParams defines a governance operation for updating the x/market + // module parameters. The authority is defined in the keeper. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.orderbook.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // UpdateParams defines a governance operation for updating the x/market + // module parameters. The authority is defined in the keeper. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.orderbook.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "sgenetwork.sge.orderbook.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "sgenetwork/sge/orderbook/tx.proto", +} + +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) 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 = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUpdateParams) 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 ErrIntOverflowTx + } + 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + 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 := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) 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 ErrIntOverflowTx + } + 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ovm/handler.go b/x/ovm/handler.go index e16934ce..921629db 100644 --- a/x/ovm/handler.go +++ b/x/ovm/handler.go @@ -25,6 +25,10 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgVotePubkeysChangeRequest: res, err := msgServer.VotePubkeysChange(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgUpdateParams: + res, err := msgServer.UpdateParams(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) return nil, sdkerrors.Wrap(sdkerrtypes.ErrUnknownRequest, errMsg) diff --git a/x/ovm/keeper/keeper.go b/x/ovm/keeper/keeper.go index b53a044a..65d82622 100644 --- a/x/ovm/keeper/keeper.go +++ b/x/ovm/keeper/keeper.go @@ -19,6 +19,9 @@ type Keeper struct { storeKey storetypes.StoreKey memKey storetypes.StoreKey paramStore paramtypes.Subspace + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string } // NewKeeper creates new keeper object @@ -27,6 +30,7 @@ func NewKeeper( storeKey, memKey storetypes.StoreKey, ps paramtypes.Subspace, + authority string, ) *Keeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { @@ -38,6 +42,7 @@ func NewKeeper( storeKey: storeKey, memKey: memKey, paramStore: ps, + authority: authority, } } @@ -45,3 +50,8 @@ func NewKeeper( func (Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } + +// GetAuthority returns the x/ovm module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} diff --git a/x/ovm/keeper/msg_server_params.go b/x/ovm/keeper/msg_server_params.go new file mode 100644 index 00000000..e417e821 --- /dev/null +++ b/x/ovm/keeper/msg_server_params.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/sge-network/sge/x/ovm/types" +) + +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if k.GetAuthority() != req.Authority { + return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + } + + if err := req.Params.Validate(); err != nil { + return nil, err + } + + k.SetParams(ctx, req.Params) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/ovm/simulation/proposals.go b/x/ovm/simulation/proposals.go new file mode 100644 index 00000000..6fd90d96 --- /dev/null +++ b/x/ovm/simulation/proposals.go @@ -0,0 +1,43 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/sge-network/sge/x/ovm/types" +) + +// Simulation operation weights constants +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/ovm/simulation/proposals_test.go b/x/ovm/simulation/proposals_test.go new file mode 100644 index 00000000..2b91c146 --- /dev/null +++ b/x/ovm/simulation/proposals_test.go @@ -0,0 +1,42 @@ +package simulation_test + +import ( + "fmt" + "math/rand" + "testing" + + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sge-network/sge/x/ovm/simulation" + "github.com/sge-network/sge/x/ovm/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + require.Equal(t, len(weightedProposalMsgs), 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + require.True(t, ok) + + fmt.Println(msgUpdateParams) + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) +} diff --git a/x/ovm/types/codec.go b/x/ovm/types/codec.go index a954cca2..0437708d 100644 --- a/x/ovm/types/codec.go +++ b/x/ovm/types/codec.go @@ -13,6 +13,7 @@ import ( func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgSubmitPubkeysChangeProposalRequest{}, "ovm/SubmitPubkeysChangeProposal") legacy.RegisterAminoMsg(cdc, &MsgVotePubkeysChangeRequest{}, "ovm/VotePubkeysChange") + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "ovm/MsgUpdateParams") } // RegisterInterfaces registers the module interface types @@ -20,6 +21,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSubmitPubkeysChangeProposalRequest{}, &MsgVotePubkeysChangeRequest{}, + &MsgUpdateParams{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/ovm/types/messages_params.go b/x/ovm/types/messages_params.go new file mode 100644 index 00000000..b847a267 --- /dev/null +++ b/x/ovm/types/messages_params.go @@ -0,0 +1,43 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // typeMsgUpdateParams is type of message MsgUpdateParams + typeMsgUpdateParams = "ovm_update_params" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +// Route returns the module's message router key. +func (*MsgUpdateParams) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgUpdateParams) Type() string { return typeMsgUpdateParams } + +// GetSigners returns the expected signers for a MsgUpdateParams message. +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgUpdateParams) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// ValidateBasic does a sanity check on the provided data. +func (msg *MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "invalid authority address") + } + + if err := msg.Params.Validate(); err != nil { + return err + } + + return nil +} diff --git a/x/ovm/types/tx.pb.go b/x/ovm/types/tx.pb.go index 87c2aa0f..96fd3323 100644 --- a/x/ovm/types/tx.pb.go +++ b/x/ovm/types/tx.pb.go @@ -6,6 +6,10 @@ package types import ( context "context" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" grpc "google.golang.org/grpc" @@ -243,38 +247,147 @@ func (m *MsgVotePubkeysChangeResponse) GetSuccess() bool { return false } +// MsgUpdateParams is the Msg/UpdateParams request type. +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/bet parameters. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_f051013778245841, []int{4} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f051013778245841, []int{5} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgSubmitPubkeysChangeProposalRequest)(nil), "sgenetwork.sge.ovm.MsgSubmitPubkeysChangeProposalRequest") proto.RegisterType((*MsgSubmitPubkeysChangeProposalResponse)(nil), "sgenetwork.sge.ovm.MsgSubmitPubkeysChangeProposalResponse") proto.RegisterType((*MsgVotePubkeysChangeRequest)(nil), "sgenetwork.sge.ovm.MsgVotePubkeysChangeRequest") proto.RegisterType((*MsgVotePubkeysChangeResponse)(nil), "sgenetwork.sge.ovm.MsgVotePubkeysChangeResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "sgenetwork.sge.ovm.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "sgenetwork.sge.ovm.MsgUpdateParamsResponse") } func init() { proto.RegisterFile("sgenetwork/sge/ovm/tx.proto", fileDescriptor_f051013778245841) } var fileDescriptor_f051013778245841 = []byte{ - // 334 bytes of a gzipped FileDescriptorProto - 0x1f, 0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xad, 0x8d, 0xfc, 0x41, 0x28, 0xf8, 0x45, - 0xd8, 0xda, 0x14, 0x6b, 0xd0, 0xfd, 0x44, 0x28, 0x90, 0x5d, 0x1f, 0xd2, 0xae, 0x17, 0x3e, 0xc3, - 0x50, 0x2b, 0xd5, 0x49, 0xb3, 0x62, 0x57, 0xf2, 0xe7, 0x3b, 0x48, 0x6f, 0xb3, 0x47, 0xe3, 0x82, - 0x1e, 0xfd, 0x3d, 0x78, 0x9d, 0xe5, 0xb3, 0x51, 0x91, 0x96, 0xda, 0xc8, 0xd9, 0x88, 0xd0, 0xda, - 0x3f, 0xcb, 0xb3, 0x4b, 0x73, 0xf9, 0x1c, 0xe6, 0x46, 0xb7, 0xa8, 0x5e, 0x6d, 0xd3, 0x3a, 0x37, - 0x9e, 0xd0, 0x83, 0xa5, 0xad, 0x98, 0xb5, 0x02, 0xb8, 0xea, 0xe3, 0xab, 0xa7, 0x9b, 0x37, 0xcc, - 0xe6, 0xb6, 0xae, 0xdf, 0x27, 0x3a, 0x19, 0x4f, 0x74, 0xf2, 0x39, 0xd1, 0xc9, 0xdb, 0x54, 0x2f, - 0x8c, 0xa7, 0x7a, 0xe1, 0x63, 0xaa, 0x17, 0x9e, 0x1a, 0xdc, 0x53, 0xfd, 0xd8, 0x31, 0x5d, 0x11, - 0x64, 0x99, 0x3d, 0xf9, 0x99, 0xdf, 0xe1, 0x2c, 0xc1, 0x69, 0x04, 0xe8, 0x94, 0xf3, 0x14, 0x9f, - 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x13, 0x33, 0xc7, 0x36, 0xe4, 0x02, 0x00, 0x00, + // 536 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xdf, 0x6b, 0xd3, 0x50, + 0x14, 0x6e, 0x1c, 0x54, 0x7b, 0x75, 0x8c, 0x86, 0xcd, 0xd5, 0x54, 0xb2, 0x92, 0x61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f9, 0x0c, 0x63, 0x8f, 0x6c, + 0xfe, 0x63, 0x77, 0xb6, 0xc9, 0xda, 0x46, 0x2a, 0x7f, 0xff, 0xcb, 0x0a, 0x59, 0x69, 0x20, 0x55, + 0xbf, 0x29, 0xa4, 0xf8, 0x9f, 0x78, 0xd5, 0x67, 0x69, 0x6e, 0x97, 0x3a, 0x6d, 0x5a, 0xed, 0x3a, + 0x54, 0x19, 0x4d, 0x9f, 0xe4, 0x2f, 0xe5, 0xa6, 0x5a, 0x0b, 0x04, 0x17, 0x1d, 0x2d, 0x6d, 0x6f, + 0x79, 0x82, 0x9c, 0x3b, 0x20, 0x77, 0x2e, 0x84, 0xbe, 0xbd, 0x40, 0xe1, 0x7c, 0x93, 0xf6, 0x70, + 0x89, 0xa6, 0xd9, 0x04, 0x63, 0xe3, 0x67, 0x5a, 0x1e, 0xf5, 0x17, 0xc7, 0x63, 0x5d, 0x39, 0x19, + 0xeb, 0xca, 0x9f, 0xb1, 0xae, 0x7c, 0x9d, 0xe8, 0x99, 0x93, 0x89, 0x9e, 0xf9, 0x35, 0xd1, 0x33, + 0x1f, 0xca, 0xd4, 0x13, 0xdd, 0xa8, 0x6d, 0xba, 0xcc, 0xb7, 0xce, 0xf1, 0xe2, 0xab, 0x60, 0x98, + 0x5c, 0x4d, 0xa3, 0x10, 0xb0, 0x9d, 0x8d, 0x2f, 0x83, 0x47, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, + 0xa9, 0x95, 0xb6, 0xe0, 0xbd, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -295,6 +408,9 @@ type MsgClient interface { // VotePubkeysChange defines a method to vote for a proposal for changing the // allowed public keys. VotePubkeysChange(ctx context.Context, in *MsgVotePubkeysChangeRequest, opts ...grpc.CallOption) (*MsgVotePubkeysChangeResponse, error) + // UpdateParams defines a governance operation for updating the x/ovm module + // parameters. The authority is defined in the keeper. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -323,6 +439,15 @@ func (c *msgClient) VotePubkeysChange(ctx context.Context, in *MsgVotePubkeysCha return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.ovm.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // PubkeysChangeProposal defines a method to submit a proposal for changing @@ -331,6 +456,9 @@ type MsgServer interface { // VotePubkeysChange defines a method to vote for a proposal for changing the // allowed public keys. VotePubkeysChange(context.Context, *MsgVotePubkeysChangeRequest) (*MsgVotePubkeysChangeResponse, error) + // UpdateParams defines a governance operation for updating the x/ovm module + // parameters. The authority is defined in the keeper. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -343,6 +471,9 @@ func (*UnimplementedMsgServer) SubmitPubkeysChangeProposal(ctx context.Context, func (*UnimplementedMsgServer) VotePubkeysChange(ctx context.Context, req *MsgVotePubkeysChangeRequest) (*MsgVotePubkeysChangeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method VotePubkeysChange not implemented") } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -384,6 +515,24 @@ func _Msg_VotePubkeysChange_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.ovm.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "sgenetwork.sge.ovm.Msg", HandlerType: (*MsgServer)(nil), @@ -396,6 +545,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "VotePubkeysChange", Handler: _Msg_VotePubkeysChange_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "sgenetwork/sge/ovm/tx.proto", @@ -546,6 +699,69 @@ func (m *MsgVotePubkeysChangeResponse) MarshalToSizedBuffer(dAtA []byte) (int, e return len(dAtA) - i, nil } +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) 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 = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -618,6 +834,30 @@ func (m *MsgVotePubkeysChangeResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1011,6 +1251,171 @@ func (m *MsgVotePubkeysChangeResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) 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 ErrIntOverflowTx + } + 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + 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 := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) 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 ErrIntOverflowTx + } + 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/reward/handler.go b/x/reward/handler.go index 6a490482..e982ac82 100644 --- a/x/reward/handler.go +++ b/x/reward/handler.go @@ -31,6 +31,9 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgGrantReward: res, err := msgServer.GrantReward(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgUpdateParams: + res, err := msgServer.UpdateParams(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) diff --git a/x/reward/keeper/keeper.go b/x/reward/keeper/keeper.go index e67bf48a..56626e4b 100644 --- a/x/reward/keeper/keeper.go +++ b/x/reward/keeper/keeper.go @@ -26,6 +26,9 @@ type ( betKeeper types.BetKeeper ovmKeeper types.OVMKeeper subaccountKeeper types.SubaccountKeeper + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string } ) @@ -45,6 +48,7 @@ func NewKeeper( ovmKeeper types.OVMKeeper, subaccountKeeper types.SubaccountKeeper, expectedKeepers SdkExpectedKeepers, + authority string, ) *Keeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { @@ -66,9 +70,15 @@ func NewKeeper( ovmKeeper: ovmKeeper, subaccountKeeper: subaccountKeeper, authzKeeper: expectedKeepers.AuthzKeeper, + authority: authority, } } func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } + +// GetAuthority returns the x/reward module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} diff --git a/x/reward/keeper/msg_server_params.go b/x/reward/keeper/msg_server_params.go new file mode 100644 index 00000000..7b907e00 --- /dev/null +++ b/x/reward/keeper/msg_server_params.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/sge-network/sge/x/reward/types" +) + +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if k.GetAuthority() != req.Authority { + return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + } + + if err := req.Params.Validate(); err != nil { + return nil, err + } + + k.SetParams(ctx, req.Params) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/reward/simulation/proposals.go b/x/reward/simulation/proposals.go new file mode 100644 index 00000000..b5ba6caf --- /dev/null +++ b/x/reward/simulation/proposals.go @@ -0,0 +1,43 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/sge-network/sge/x/reward/types" +) + +// Simulation operation weights constants +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/reward/simulation/proposals_test.go b/x/reward/simulation/proposals_test.go new file mode 100644 index 00000000..31481836 --- /dev/null +++ b/x/reward/simulation/proposals_test.go @@ -0,0 +1,42 @@ +package simulation_test + +import ( + "fmt" + "math/rand" + "testing" + + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sge-network/sge/x/reward/simulation" + "github.com/sge-network/sge/x/reward/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + require.Equal(t, len(weightedProposalMsgs), 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + require.True(t, ok) + + fmt.Println(msgUpdateParams) + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) +} diff --git a/x/reward/types/codec.go b/x/reward/types/codec.go index 24a22c50..f175932b 100644 --- a/x/reward/types/codec.go +++ b/x/reward/types/codec.go @@ -15,6 +15,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgUpdateCampaign{}, "reward/UpdateCampaign") legacy.RegisterAminoMsg(cdc, &MsgWithdrawFunds{}, "reward/WithdrawFunds") legacy.RegisterAminoMsg(cdc, &MsgGrantReward{}, "reward/GrantReward") + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "reward/MsgUpdateParams") } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -23,6 +24,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgUpdateCampaign{}, &MsgWithdrawFunds{}, &MsgGrantReward{}, + &MsgUpdateParams{}, ) registry.RegisterImplementations( diff --git a/x/reward/types/messages_params.go b/x/reward/types/messages_params.go new file mode 100644 index 00000000..6af6f1b5 --- /dev/null +++ b/x/reward/types/messages_params.go @@ -0,0 +1,43 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // typeMsgUpdateParams is type of message MsgUpdateParams + typeMsgUpdateParams = "reward_update_params" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +// Route returns the module's message router key. +func (*MsgUpdateParams) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgUpdateParams) Type() string { return typeMsgUpdateParams } + +// GetSigners returns the expected signers for a MsgUpdateParams message. +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgUpdateParams) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// ValidateBasic does a sanity check on the provided data. +func (msg *MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "invalid authority address") + } + + if err := msg.Params.Validate(); err != nil { + return err + } + + return nil +} diff --git a/x/reward/types/tx.pb.go b/x/reward/types/tx.pb.go index a1d0a17f..64553002 100644 --- a/x/reward/types/tx.pb.go +++ b/x/reward/types/tx.pb.go @@ -7,6 +7,9 @@ import ( context "context" cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" @@ -642,6 +645,100 @@ func (m *MsgWithdrawFundsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgWithdrawFundsResponse proto.InternalMessageInfo +// MsgUpdateParams is the Msg/UpdateParams request type. +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/bet parameters. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_0db1a5dd8b963fa8, []int{12} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_0db1a5dd8b963fa8, []int{13} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgCreatePromoter)(nil), "sgenetwork.sge.reward.MsgCreatePromoter") proto.RegisterType((*MsgCreatePromoterResponse)(nil), "sgenetwork.sge.reward.MsgCreatePromoterResponse") @@ -655,47 +752,60 @@ func init() { proto.RegisterType((*MsgGrantRewardResponse)(nil), "sgenetwork.sge.reward.MsgGrantRewardResponse") proto.RegisterType((*MsgWithdrawFunds)(nil), "sgenetwork.sge.reward.MsgWithdrawFunds") proto.RegisterType((*MsgWithdrawFundsResponse)(nil), "sgenetwork.sge.reward.MsgWithdrawFundsResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "sgenetwork.sge.reward.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "sgenetwork.sge.reward.MsgUpdateParamsResponse") } func init() { proto.RegisterFile("sgenetwork/sge/reward/tx.proto", fileDescriptor_0db1a5dd8b963fa8) } var fileDescriptor_0db1a5dd8b963fa8 = []byte{ - // 551 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0xcf, 0x6e, 0xd3, 0x40, - 0x10, 0xc6, 0x63, 0x02, 0x41, 0x4c, 0xa0, 0x14, 0x8b, 0x56, 0xc6, 0x80, 0x03, 0x96, 0x10, 0xed, - 0xa1, 0x36, 0x50, 0x71, 0xe1, 0x98, 0x08, 0x10, 0x07, 0x4b, 0xc8, 0x50, 0x81, 0xb8, 0x54, 0x5b, - 0x7b, 0xbb, 0xb1, 0x12, 0x7b, 0xad, 0xdd, 0xb5, 0xd2, 0x3e, 0x04, 0x52, 0x5f, 0x84, 0xf7, 0xe8, - 0xb1, 0x47, 0xc4, 0x21, 0x42, 0xc9, 0x1b, 0xf0, 0x04, 0xc8, 0x7f, 0xb1, 0x9d, 0x26, 0x75, 0x81, - 0x9b, 0xd7, 0xf3, 0xed, 0xfc, 0xe6, 0xb3, 0x66, 0x3c, 0xa0, 0x71, 0x82, 0x03, 0x2c, 0x26, 0x94, - 0x8d, 0x4c, 0x4e, 0xb0, 0xc9, 0xf0, 0x04, 0x31, 0xd7, 0x14, 0x47, 0x46, 0xc8, 0xa8, 0xa0, 0xf2, - 0xc6, 0x9f, 0xb8, 0xc1, 0x09, 0x36, 0xd2, 0xb8, 0x7a, 0x97, 0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, 0x1f, 0x9c, 0xce, 0x34, 0xe9, 0x6c, 0xa6, 0x49, - 0x3f, 0x67, 0x9a, 0x74, 0x32, 0xd7, 0x5a, 0x67, 0x73, 0xad, 0xf5, 0x7d, 0xae, 0xb5, 0xbe, 0x6c, - 0x13, 0x4f, 0x0c, 0xa3, 0x03, 0xc3, 0xa1, 0x7e, 0xbc, 0xae, 0x76, 0xca, 0xab, 0xeb, 0xa8, 0x58, - 0x5e, 0xc7, 0x21, 0xe6, 0x07, 0x9d, 0x64, 0x27, 0xed, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xa0, - 0x38, 0xd6, 0x53, 0xe2, 0x06, 0x00, 0x00, + // 727 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0x4f, 0x4f, 0xd4, 0x4e, + 0x18, 0xde, 0xfe, 0xf8, 0x65, 0x0d, 0xb3, 0xc8, 0x9f, 0x86, 0x85, 0xa5, 0x4a, 0xc1, 0x1a, 0x15, + 0x48, 0xb6, 0x65, 0x21, 0x6a, 0xc2, 0x49, 0x77, 0xa3, 0xc6, 0xc3, 0x26, 0xa4, 0x48, 0x34, 0x5e, + 0xc8, 0xb0, 0x1d, 0x66, 0x1b, 0x68, 0xa7, 0x99, 0x99, 0xba, 0x70, 0xf0, 0xe2, 0xdd, 0xe8, 0xc7, + 0xf0, 0x62, 0xc2, 0x81, 0x0f, 0x41, 0x3c, 0x11, 0x4e, 0xc6, 0x03, 0x31, 0x70, 0xe0, 0xee, 0x27, + 0x30, 0xfd, 0x4b, 0xdb, 0xfd, 0x8b, 0x7a, 0xd9, 0xed, 0xcc, 0xfb, 0xbc, 0xef, 0xf3, 0x3c, 0xb3, + 0xf3, 0xbe, 0x5d, 0x20, 0x33, 0x8c, 0x6c, 0xc4, 0x5b, 0x84, 0xee, 0x6a, 0x0c, 0x23, 0x8d, 0xa2, + 0x16, 0xa4, 0x86, 0xc6, 0xf7, 0x55, 0x87, 0x12, 0x4e, 0xc4, 0xe2, 0x55, 0x5c, 0x65, 0x18, 0xa9, + 0x41, 0x5c, 0x9a, 0xc4, 0x04, 0x13, 0x1f, 0xa1, 0x79, 0x4f, 0x01, 0x58, 0x9a, 0x69, 0x10, 0x66, + 0x11, 0xb6, 0x15, 0x04, 0x82, 0x45, 0x18, 0x9a, 0x0e, 0x56, 0x9a, 0xc5, 0xb0, 0xf6, 0xae, 0xe2, + 0x7d, 0x85, 0x81, 0x09, 0x68, 0x99, 0x36, 0xd1, 0xfc, 0xcf, 0x70, 0x4b, 0xe9, 0xac, 0xc9, 0x81, + 0x14, 0x5a, 0x61, 0x3d, 0xe5, 0x19, 0x98, 0xa8, 0x33, 0x5c, 0xa3, 0x08, 0x72, 0xb4, 0x4e, 0x89, + 0x45, 0x38, 0xa2, 0x62, 0x09, 0xdc, 0x68, 0x78, 0x3b, 0x84, 0x96, 0x84, 0x79, 0x61, 0x61, 0x58, + 0x8f, 0x96, 0xe2, 0x14, 0xc8, 0x73, 0xb3, 0xb1, 0x8b, 0x78, 0xe9, 0x3f, 0x3f, 0x10, 0xae, 0x94, + 0x5b, 0x60, 0xa6, 0xad, 0x8c, 0x8e, 0x98, 0x43, 0x6c, 0x86, 0x94, 0x37, 0x40, 0xac, 0x33, 0xbc, + 0x81, 0x78, 0x14, 0xa9, 0x11, 0x7b, 0xa7, 0x07, 0xc9, 0x38, 0x18, 0x72, 0x4d, 0x23, 0x64, 0xf0, + 0x1e, 0x13, 0xb4, 0x43, 0x29, 0xda, 0xdb, 0x40, 0x6a, 0xaf, 0x1c, 0xf3, 0x7e, 0x15, 0x12, 0xe6, + 0x6a, 0xd0, 0x72, 0xa0, 0x89, 0xed, 0x6b, 0xf1, 0xbe, 0x02, 0x05, 0x4e, 0x38, 0xdc, 0xdb, 0xda, + 0x71, 0x6d, 0x83, 0x05, 0xe4, 0xd5, 0xd5, 0xe3, 0xb3, 0xb9, 0xdc, 0x8f, 0xb3, 0xb9, 0x62, 0xf0, + 0x53, 0x30, 0x63, 0x57, 0x35, 0x89, 0x66, 0x41, 0xde, 0x54, 0x5f, 0xda, 0xfc, 0xd7, 0xd9, 0x9c, + 0x78, 0x00, 0xad, 0xbd, 0x35, 0x25, 0x91, 0xa9, 0xe8, 0xc0, 0x5f, 0x3d, 0xf7, 0x16, 0x09, 0x37, + 0xff, 0x77, 0x3d, 0xc4, 0x48, 0x6e, 0xd6, 0xcc, 0xa6, 0x63, 0xfc, 0x95, 0x19, 0xc7, 0x75, 0xfe, + 0xd0, 0x4c, 0x9c, 0xe9, 0x9b, 0x71, 0x5c, 0x67, 0x10, 0x33, 0x69, 0xb9, 0xb1, 0x99, 0x16, 0x18, + 0xad, 0x33, 0xfc, 0x82, 0x42, 0x9b, 0xeb, 0xfe, 0xa5, 0xbc, 0x96, 0x91, 0x3b, 0x60, 0xa4, 0x11, + 0x56, 0xdc, 0xf2, 0x42, 0xc1, 0x9d, 0x28, 0x44, 0x7b, 0x9b, 0xa9, 0x0b, 0x93, 0x56, 0x55, 0x02, + 0x53, 0x69, 0xe2, 0x58, 0xd2, 0x47, 0x01, 0x8c, 0xd7, 0x19, 0x7e, 0x6d, 0xf2, 0xa6, 0x41, 0x61, + 0x2b, 0x30, 0xf7, 0x0f, 0xee, 0xa8, 0xf8, 0x10, 0xe4, 0xa1, 0x45, 0x5c, 0x3b, 0x94, 0x52, 0x9d, + 0xed, 0x79, 0xe2, 0x7a, 0x08, 0x56, 0x24, 0x50, 0xca, 0xca, 0x89, 0xb5, 0x1e, 0x0a, 0x60, 0x2c, + 0x3e, 0xdc, 0x75, 0xbf, 0x9d, 0xc5, 0x47, 0x60, 0x18, 0xba, 0xbc, 0x49, 0xa8, 0xc9, 0x0f, 0x02, + 0xb1, 0xd5, 0xd2, 0xe9, 0x51, 0x79, 0x32, 0x9c, 0x1e, 0x4f, 0x0d, 0x83, 0x22, 0xc6, 0x36, 0x38, + 0x35, 0x6d, 0xac, 0x5f,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, 0x65, 0xe1, 0xe4, 0x5c, 0x16, 0x7e, + 0x9e, 0xcb, 0xc2, 0xe7, 0x0b, 0x39, 0x77, 0x72, 0x21, 0xe7, 0xbe, 0x5f, 0xc8, 0xb9, 0xb7, 0x8b, + 0xd8, 0xe4, 0x4d, 0x77, 0x5b, 0x6d, 0x10, 0x4b, 0x4b, 0xe4, 0xf9, 0x6f, 0xfd, 0xfd, 0xf8, 0xbf, + 0xc8, 0x81, 0x83, 0xd8, 0x76, 0xde, 0x7f, 0xef, 0xaf, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xf2, + 0x4c, 0x80, 0xd3, 0xb1, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -722,6 +832,9 @@ type MsgClient interface { WithdrawFunds(ctx context.Context, in *MsgWithdrawFunds, opts ...grpc.CallOption) (*MsgWithdrawFundsResponse, error) // GrantReward is method to allocate rewards GrantReward(ctx context.Context, in *MsgGrantReward, opts ...grpc.CallOption) (*MsgGrantRewardResponse, error) + // UpdateParams defines a governance operation for updating the x/ovm module + // parameters. The authority is defined in the keeper. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -786,6 +899,15 @@ func (c *msgClient) GrantReward(ctx context.Context, in *MsgGrantReward, opts .. return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // SetPromoterConf is a method to set the configurations of a promoter. @@ -800,6 +922,9 @@ type MsgServer interface { WithdrawFunds(context.Context, *MsgWithdrawFunds) (*MsgWithdrawFundsResponse, error) // GrantReward is method to allocate rewards GrantReward(context.Context, *MsgGrantReward) (*MsgGrantRewardResponse, error) + // UpdateParams defines a governance operation for updating the x/ovm module + // parameters. The authority is defined in the keeper. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -824,6 +949,9 @@ func (*UnimplementedMsgServer) WithdrawFunds(ctx context.Context, req *MsgWithdr func (*UnimplementedMsgServer) GrantReward(ctx context.Context, req *MsgGrantReward) (*MsgGrantRewardResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GrantReward not implemented") } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -937,6 +1065,24 @@ func _Msg_GrantReward_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "sgenetwork.sge.reward.Msg", HandlerType: (*MsgServer)(nil), @@ -965,6 +1111,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "GrantReward", Handler: _Msg_GrantReward_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "sgenetwork/sge/reward/tx.proto", @@ -1402,6 +1552,69 @@ func (m *MsgWithdrawFundsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error return len(dAtA) - i, nil } +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) 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 = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1599,6 +1812,30 @@ func (m *MsgWithdrawFundsResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2883,6 +3120,171 @@ func (m *MsgWithdrawFundsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) 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 ErrIntOverflowTx + } + 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + 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 := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) 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 ErrIntOverflowTx + } + 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/subaccount/handler.go b/x/subaccount/handler.go index 24fd75ad..beb68a13 100644 --- a/x/subaccount/handler.go +++ b/x/subaccount/handler.go @@ -13,7 +13,7 @@ import ( // NewHandler initialize a new sdk.handler instance for registered messages func NewHandler(k keeper.Keeper) sdk.Handler { - msgServer := keeper.NewMsgServerImpl(&k) + msgServer := keeper.NewMsgServerImpl(k) return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) @@ -38,6 +38,10 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgHouseWithdraw: res, err := msgServer.HouseWithdraw(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgUpdateParams: + res, err := msgServer.UpdateParams(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) return nil, sdkerrors.Wrap(sdkerrtypes.ErrUnknownRequest, errMsg) diff --git a/x/subaccount/keeper/export_test.go b/x/subaccount/keeper/export_test.go new file mode 100644 index 00000000..d22f197e --- /dev/null +++ b/x/subaccount/keeper/export_test.go @@ -0,0 +1,5 @@ +package keeper + +// KeeperTest is a wrapper object for the keeper, It is being used +// to export unexported methods of the keeper +type KeeperTest = Keeper diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index b1ba60e2..c1b69ce2 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -20,6 +20,9 @@ type Keeper struct { betKeeper types.BetKeeper houseKeeper types.HouseKeeper obKeeper types.OrderBookKeeper + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string } func NewKeeper( @@ -32,6 +35,7 @@ func NewKeeper( betKeeper types.BetKeeper, obKeeper types.OrderBookKeeper, hk types.HouseKeeper, + authority string, ) *Keeper { // set KeyTable if it is not already set if !ps.HasKeyTable() { @@ -48,6 +52,12 @@ func NewKeeper( betKeeper: betKeeper, houseKeeper: hk, obKeeper: obKeeper, + authority: authority, } return k } + +// GetAuthority returns the x/subaccount module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} diff --git a/x/subaccount/keeper/keeper_test.go b/x/subaccount/keeper/keeper_test.go index 1a6f6b4a..06d290a5 100644 --- a/x/subaccount/keeper/keeper_test.go +++ b/x/subaccount/keeper/keeper_test.go @@ -12,7 +12,7 @@ import ( "github.com/sge-network/sge/x/subaccount/keeper" ) -func setupKeeperAndApp(t testing.TB) (*simapp.TestApp, *keeper.Keeper, sdk.Context) { +func setupKeeperAndApp(t testing.TB) (*simapp.TestApp, *keeper.KeeperTest, sdk.Context) { tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) diff --git a/x/subaccount/keeper/msg_server.go b/x/subaccount/keeper/msg_server.go index 48699f9d..5625c960 100644 --- a/x/subaccount/keeper/msg_server.go +++ b/x/subaccount/keeper/msg_server.go @@ -5,14 +5,14 @@ import ( ) type msgServer struct { - keeper *Keeper + Keeper } // NewMsgServerImpl returns an implementation of the MsgServer interface // for the provided Keeper. -func NewMsgServerImpl(keeper *Keeper) types.MsgServer { +func NewMsgServerImpl(keeper Keeper) types.MsgServer { return &msgServer{ - keeper: keeper, + Keeper: keeper, } } diff --git a/x/subaccount/keeper/msg_server_balance.go b/x/subaccount/keeper/msg_server_balance.go index e7680849..5057d8d3 100644 --- a/x/subaccount/keeper/msg_server_balance.go +++ b/x/subaccount/keeper/msg_server_balance.go @@ -12,7 +12,7 @@ import ( func (k msgServer) TopUp(goCtx context.Context, msg *types.MsgTopUp) (*types.MsgTopUpResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - subAccAddr, err := k.keeper.TopUp(ctx, msg.Creator, msg.Address, msg.LockedBalances) + subAccAddr, err := k.Keeper.TopUp(ctx, msg.Creator, msg.Address, msg.LockedBalances) if err != nil { return nil, err } @@ -27,12 +27,12 @@ func (k msgServer) WithdrawUnlockedBalances(goCtx context.Context, msg *types.Ms ctx := sdk.UnwrapSDKContext(goCtx) ownerAddr := sdk.MustAccAddressFromBech32(msg.Creator) - subAccAddr, exists := k.keeper.GetSubaccountByOwner(ctx, ownerAddr) + subAccAddr, exists := k.Keeper.GetSubaccountByOwner(ctx, ownerAddr) if !exists { return nil, types.ErrSubaccountDoesNotExist } - err := k.keeper.withdrawUnlocked(ctx, subAccAddr, ownerAddr) + err := k.Keeper.withdrawUnlocked(ctx, subAccAddr, ownerAddr) if err != nil { return nil, err } diff --git a/x/subaccount/keeper/msg_server_bet.go b/x/subaccount/keeper/msg_server_bet.go index 55ca2913..a5f2f449 100644 --- a/x/subaccount/keeper/msg_server_bet.go +++ b/x/subaccount/keeper/msg_server_bet.go @@ -18,19 +18,19 @@ import ( func (k msgServer) Wager(goCtx context.Context, msg *types.MsgWager) (*types.MsgWagerResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - if !k.keeper.GetWagerEnabled(ctx) { + if !k.Keeper.GetWagerEnabled(ctx) { return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "currently the subacount wager tx is not enabled") } subAccOwner := sdk.MustAccAddressFromBech32(msg.Creator) // find subaccount - subAccAddr, exists := k.keeper.GetSubaccountByOwner(ctx, subAccOwner) + subAccAddr, exists := k.Keeper.GetSubaccountByOwner(ctx, subAccOwner) if !exists { return nil, status.Error(codes.NotFound, "subaccount not found") } payload := &types.SubAccWagerTicketPayload{} - err := k.keeper.ovmKeeper.VerifyTicketUnmarshal(sdk.WrapSDKContext(ctx), msg.Ticket, &payload) + err := k.Keeper.ovmKeeper.VerifyTicketUnmarshal(sdk.WrapSDKContext(ctx), msg.Ticket, &payload) if err != nil { return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) } @@ -39,7 +39,7 @@ func (k msgServer) Wager(goCtx context.Context, msg *types.MsgWager) (*types.Msg return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "message creator should be the same as the sub message creator%s", msg.Creator) } - bet, oddsMap, err := k.keeper.betKeeper.PrepareBetObject(ctx, payload.Msg.Creator, payload.Msg.Props) + bet, oddsMap, err := k.Keeper.betKeeper.PrepareBetObject(ctx, payload.Msg.Creator, payload.Msg.Props) if err != nil { return nil, err } @@ -48,7 +48,7 @@ func (k msgServer) Wager(goCtx context.Context, msg *types.MsgWager) (*types.Msg return nil, sdkerrors.Wrapf(types.ErrInTicketPayloadValidation, "%s", err) } - mainAccBalance := k.keeper.bankKeeper.GetBalance( + mainAccBalance := k.Keeper.bankKeeper.GetBalance( ctx, sdk.MustAccAddressFromBech32(bet.Creator), params.DefaultBondDenom) @@ -56,11 +56,11 @@ func (k msgServer) Wager(goCtx context.Context, msg *types.MsgWager) (*types.Msg return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "not enough balance in main account") } - if err := k.keeper.withdrawLockedAndUnlocked(ctx, subAccAddr, subAccOwner, payload.SubaccDeductAmount); err != nil { + if err := k.Keeper.withdrawLockedAndUnlocked(ctx, subAccAddr, subAccOwner, payload.SubaccDeductAmount); err != nil { return nil, err } - if err := k.keeper.betKeeper.Wager(ctx, bet, oddsMap); err != nil { + if err := k.Keeper.betKeeper.Wager(ctx, bet, oddsMap); err != nil { return nil, err } diff --git a/x/subaccount/keeper/msg_server_house.go b/x/subaccount/keeper/msg_server_house.go index 27a09c72..c667d562 100644 --- a/x/subaccount/keeper/msg_server_house.go +++ b/x/subaccount/keeper/msg_server_house.go @@ -14,24 +14,24 @@ import ( func (k msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposit) (*types.MsgHouseDepositResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - if !k.keeper.GetDepositEnabled(ctx) { + if !k.Keeper.GetDepositEnabled(ctx) { return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "currently the subacount deposit tx is not enabled") } // check if subaccount exists - subAccAddr, exists := k.keeper.GetSubaccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) + subAccAddr, exists := k.Keeper.GetSubaccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) if !exists { return nil, types.ErrSubaccountDoesNotExist } // get subaccount balance, and check if it can spend - balance, exists := k.keeper.GetAccountSummary(ctx, subAccAddr) + balance, exists := k.Keeper.GetAccountSummary(ctx, subAccAddr) if !exists { panic("data corruption: subaccount balance not found") } // parse the ticket payload and create deposit, setting the authz allowed as false - _, err := k.keeper.houseKeeper.ParseDepositTicketAndValidate(goCtx, ctx, msg.Msg, false) + _, err := k.Keeper.houseKeeper.ParseDepositTicketAndValidate(goCtx, ctx, msg.Msg, false) if err != nil { return nil, sdkerrors.Wrap(err, "failed to deposit") } @@ -41,7 +41,7 @@ func (k msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposi } // send house deposit from subaccount on behalf of the owner - participationIndex, feeAmount, err := k.keeper.houseKeeper.Deposit( + participationIndex, feeAmount, err := k.Keeper.houseKeeper.Deposit( ctx, msg.Msg.Creator, subAccAddr.String(), @@ -53,7 +53,7 @@ func (k msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposi } // update subaccount balance - k.keeper.SetAccountSummary(ctx, subAccAddr, balance) + k.Keeper.SetAccountSummary(ctx, subAccAddr, balance) // emit event msg.EmitEvent(&ctx, subAccAddr.String(), participationIndex, feeAmount) @@ -70,22 +70,22 @@ func (k msgServer) HouseWithdraw(goCtx context.Context, msg *types.MsgHouseWithd ctx := sdk.UnwrapSDKContext(goCtx) // check if subaccount exists - subAccAddr, exists := k.keeper.GetSubaccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) + subAccAddr, exists := k.Keeper.GetSubaccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) if !exists { return nil, types.ErrSubaccountDoesNotExist } - subAccountBalance, exists := k.keeper.GetAccountSummary(ctx, subAccAddr) + subAccountBalance, exists := k.Keeper.GetAccountSummary(ctx, subAccAddr) if !exists { panic("data corruption: subaccount balance not found") } - _, _, err := k.keeper.houseKeeper.ParseWithdrawTicketAndValidate(goCtx, msg.Msg, true) + _, _, err := k.Keeper.houseKeeper.ParseWithdrawTicketAndValidate(goCtx, msg.Msg, true) if err != nil { return nil, err } - id, err := k.keeper.houseKeeper.CalcAndWithdraw(ctx, msg.Msg, subAccAddr.String(), false) + id, err := k.Keeper.houseKeeper.CalcAndWithdraw(ctx, msg.Msg, subAccAddr.String(), false) if err != nil { return nil, err } @@ -95,7 +95,7 @@ func (k msgServer) HouseWithdraw(goCtx context.Context, msg *types.MsgHouseWithd panic("data corruption: it must be possible to unspend an house withdrawal") } - k.keeper.SetAccountSummary(ctx, subAccAddr, subAccountBalance) + k.Keeper.SetAccountSummary(ctx, subAccAddr, subAccountBalance) msg.Msg.EmitEvent(&ctx, subAccAddr.String(), id) diff --git a/x/subaccount/keeper/msg_server_params.go b/x/subaccount/keeper/msg_server_params.go new file mode 100644 index 00000000..29269762 --- /dev/null +++ b/x/subaccount/keeper/msg_server_params.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/sge-network/sge/x/subaccount/types" +) + +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if k.GetAuthority() != req.Authority { + return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + } + + if err := req.Params.Validate(); err != nil { + return nil, err + } + + k.SetParams(ctx, req.Params) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/subaccount/keeper/msg_server_subaccount.go b/x/subaccount/keeper/msg_server_subaccount.go index 202f7829..3c033651 100644 --- a/x/subaccount/keeper/msg_server_subaccount.go +++ b/x/subaccount/keeper/msg_server_subaccount.go @@ -20,7 +20,7 @@ func (k msgServer) Create( return nil, sdkerrors.Wrap(err, "invalid request") } - subAccAddr, err := k.keeper.CreateSubaccount(ctx, msg.Creator, msg.Owner, msg.LockedBalances) + subAccAddr, err := k.Keeper.CreateSubaccount(ctx, msg.Creator, msg.Owner, msg.LockedBalances) if err != nil { return nil, err } diff --git a/x/subaccount/keeper/msg_server_test.go b/x/subaccount/keeper/msg_server_test.go index c778d977..079bff35 100644 --- a/x/subaccount/keeper/msg_server_test.go +++ b/x/subaccount/keeper/msg_server_test.go @@ -14,5 +14,5 @@ func setupMsgServerAndApp( t testing.TB, ) (*simapp.TestApp, *keeper.Keeper, types.MsgServer, sdk.Context) { tApp, k, ctx := setupKeeperAndApp(t) - return tApp, k, keeper.NewMsgServerImpl(k), ctx + return tApp, k, keeper.NewMsgServerImpl(*k), ctx } diff --git a/x/subaccount/module.go b/x/subaccount/module.go index 5645f7c3..9a68aefd 100644 --- a/x/subaccount/module.go +++ b/x/subaccount/module.go @@ -109,7 +109,7 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper)) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper)) } diff --git a/x/subaccount/simulation/proposals.go b/x/subaccount/simulation/proposals.go new file mode 100644 index 00000000..04dd4b5c --- /dev/null +++ b/x/subaccount/simulation/proposals.go @@ -0,0 +1,45 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/sge-network/sge/x/subaccount/types" +) + +// Simulation operation weights constants +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.WagerEnabled = r.Intn(2) == 0 + params.DepositEnabled = r.Intn(2) == 0 + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/subaccount/simulation/proposals_test.go b/x/subaccount/simulation/proposals_test.go new file mode 100644 index 00000000..98dc7f71 --- /dev/null +++ b/x/subaccount/simulation/proposals_test.go @@ -0,0 +1,44 @@ +package simulation_test + +import ( + "fmt" + "math/rand" + "testing" + + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sge-network/sge/x/subaccount/simulation" + "github.com/sge-network/sge/x/subaccount/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + require.Equal(t, len(weightedProposalMsgs), 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + require.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + require.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + require.True(t, ok) + + fmt.Println(msgUpdateParams) + require.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + require.Equal(t, true, msgUpdateParams.Params.DepositEnabled) + require.Equal(t, true, msgUpdateParams.Params.WagerEnabled) +} diff --git a/x/subaccount/types/codec.go b/x/subaccount/types/codec.go index 4cfe3560..6257d243 100644 --- a/x/subaccount/types/codec.go +++ b/x/subaccount/types/codec.go @@ -17,6 +17,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgWager{}, "subaccount/BetWager") legacy.RegisterAminoMsg(cdc, &MsgHouseDeposit{}, "subaccount/HouseDeposit") legacy.RegisterAminoMsg(cdc, &MsgHouseWithdraw{}, "subaccount/HouseWithdraw") + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "subaccount/MsgUpdateParams") } // RegisterInterfaces registers the module interface types @@ -28,6 +29,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgWager{}, &MsgHouseDeposit{}, &MsgHouseWithdraw{}, + &MsgUpdateParams{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/subaccount/types/messages_params.go b/x/subaccount/types/messages_params.go new file mode 100644 index 00000000..fd6b2d65 --- /dev/null +++ b/x/subaccount/types/messages_params.go @@ -0,0 +1,43 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + // typeMsgUpdateParams is type of message MsgUpdateParams + typeMsgUpdateParams = "subaccount_update_params" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +// Route returns the module's message router key. +func (*MsgUpdateParams) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgUpdateParams) Type() string { return typeMsgUpdateParams } + +// GetSigners returns the expected signers for a MsgUpdateParams message. +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + +// GetSignBytes implements the LegacyMsg interface. +func (msg MsgUpdateParams) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// ValidateBasic does a sanity check on the provided data. +func (msg *MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "invalid authority address") + } + + if err := msg.Params.Validate(); err != nil { + return err + } + + return nil +} diff --git a/x/subaccount/types/tx.pb.go b/x/subaccount/types/tx.pb.go index 91d7ee08..514569c9 100644 --- a/x/subaccount/types/tx.pb.go +++ b/x/subaccount/types/tx.pb.go @@ -6,6 +6,9 @@ package types import ( context "context" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" @@ -606,6 +609,100 @@ func (m *MsgHouseWithdrawResponse) GetResponse() *types1.MsgWithdrawResponse { return nil } +// MsgUpdateParams is the Msg/UpdateParams request type. +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the x/bet parameters. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_4f026744c489fe19, []int{12} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4f026744c489fe19, []int{13} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgCreate)(nil), "sgenetwork.sge.subaccount.MsgCreate") proto.RegisterType((*MsgCreateResponse)(nil), "sgenetwork.sge.subaccount.MsgCreateResponse") @@ -619,6 +716,8 @@ func init() { proto.RegisterType((*MsgHouseDepositResponse)(nil), "sgenetwork.sge.subaccount.MsgHouseDepositResponse") proto.RegisterType((*MsgHouseWithdraw)(nil), "sgenetwork.sge.subaccount.MsgHouseWithdraw") proto.RegisterType((*MsgHouseWithdrawResponse)(nil), "sgenetwork.sge.subaccount.MsgHouseWithdrawResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "sgenetwork.sge.subaccount.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "sgenetwork.sge.subaccount.MsgUpdateParamsResponse") } func init() { @@ -626,44 +725,55 @@ func init() { } var fileDescriptor_4f026744c489fe19 = []byte{ - // 587 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0xd1, 0x6b, 0xd3, 0x40, - 0x1c, 0xc7, 0x1b, 0xeb, 0xba, 0xed, 0x37, 0x75, 0x1a, 0x87, 0xc6, 0x0c, 0x63, 0xcd, 0x26, 0x56, - 0xe7, 0x52, 0x68, 0x41, 0x5f, 0x44, 0xa4, 0x6e, 0xcc, 0x07, 0xfb, 0x12, 0x36, 0x8a, 0x22, 0x8c, - 0x24, 0x3d, 0xae, 0xa5, 0x5d, 0x2e, 0xe6, 0xae, 0x74, 0xfe, 0x17, 0x2a, 0x82, 0xff, 0xd2, 0x1e, - 0xf7, 0xe8, 0x93, 0x48, 0xfb, 0x8f, 0x48, 0x2e, 0xc9, 0x35, 0x49, 0x49, 0x5a, 0x05, 0xdf, 0xee, - 0x92, 0xef, 0xf7, 0x7b, 0x9f, 0xdf, 0x8f, 0xfb, 0x71, 0xa0, 0x53, 0x8c, 0x5c, 0xc4, 0xc6, 0xc4, - 0x1f, 0xd4, 0x29, 0x46, 0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0x24, 0x50, 0x72, 0xc7, 0xe0, 0x79, 0x71, 0x52, 0x9e, 0x4f, 0x7d, 0xf5, 0x6f, 0xbe, 0x64, 0xbd, - 0xe1, 0xe8, 0x2c, 0xa8, 0x97, 0x8b, 0x16, 0xd5, 0x9b, 0x1e, 0x23, 0x17, 0xae, 0xa5, 0x26, 0xe0, - 0x69, 0xb1, 0x39, 0xa9, 0x55, 0x1b, 0xcb, 0x6b, 0xc5, 0x79, 0x9f, 0xe0, 0x7a, 0xfa, 0x26, 0xef, - 0x2d, 0x11, 0x12, 0x8b, 0xd5, 0xe6, 0x5f, 0x88, 0xe3, 0x23, 0x5b, 0x47, 0x17, 0x13, 0x4d, 0xba, - 0x9c, 0x68, 0xd2, 0xef, 0x89, 0x26, 0x7d, 0x99, 0x6a, 0xa5, 0xcb, 0xa9, 0x56, 0xfa, 0x39, 0xd5, - 0x4a, 0x1f, 0xf6, 0x71, 0x9f, 0xf5, 0x46, 0xb6, 0xe1, 0x90, 0xb3, 0xe0, 0x09, 0xda, 0x4f, 0x3e, - 0x47, 0xe7, 0xa9, 0x77, 0xf1, 0xb3, 0x87, 0xa8, 0x5d, 0xe1, 0xaf, 0x50, 0xf3, 0x4f, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xd3, 0x75, 0x55, 0xca, 0x41, 0x07, 0x00, 0x00, + // 768 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xd1, 0x4f, 0xd3, 0x40, + 0x18, 0x5f, 0x9d, 0x0c, 0x76, 0xa0, 0x48, 0x05, 0x29, 0x25, 0xce, 0x59, 0x50, 0x27, 0xb8, 0x56, + 0x46, 0x02, 0x09, 0x31, 0x46, 0x27, 0x04, 0x1f, 0x5c, 0x62, 0x26, 0x84, 0x68, 0x4c, 0x48, 0xd7, + 0x5d, 0x6e, 0x0b, 0xac, 0x57, 0x7b, 0x37, 0x81, 0x57, 0x13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, + 0xde, 0x33, 0xa1, 0x2d, 0x5d, 0x62, 0xef, 0xdd, 0x85, 0xb8, 0x05, 0x46, 0x77, 0xb1, 0xb1, 0x03, + 0xab, 0xdb, 0xdc, 0x39, 0x91, 0x92, 0xd9, 0x64, 0x6e, 0xb8, 0x90, 0x53, 0x23, 0x93, 0xab, 0xbe, + 0x60, 0x8c, 0xa2, 0x4b, 0x28, 0x5e, 0x3e, 0xfe, 0x75, 0x2b, 0x51, 0xbe, 0xba, 0x1b, 0x7c, 0x49, + 0x94, 0xeb, 0x60, 0xcc, 0x77, 0x55, 0x86, 0xc4, 0xc2, 0x26, 0x81, 0xca, 0x57, 0x01, 0x0c, 0x95, + 0x08, 0xda, 0xc0, 0xd6, 0xa6, 0x15, 0x63, 0x55, 0x02, 0x83, 0x7a, 0xb5, 0x6a, 0x43, 0x42, 0xb8, + 0x59, 0x6f, 0xf9, 0xff, 0xec, 0x8a, 0xe0, 0x9a, 0x67, 0xcc, 0x77, 0xbb, 0x0c, 0xa6, 0x4b, 0x04, + 0x6d, 0xd5, 0x69, 0xad, 0x6a, 0xeb, 0x7b, 0x9b, 0x66, 0x3b, 0x25, 0xda, 0xbf, 0x72, 0x07, 0xcc, + 0xc4, 0x10, 0x7d, 0xfd, 0x47, 0x2c, 0x19, 0x5b, 0x3a, 0x82, 0x76, 0x4c, 0x32, 0x6e, 0x80, 0x14, + 0xad, 0x1b, 0x3b, 0x90, 0xf2, 0x5c, 0xf0, 0x95, 0xb2, 0xc1, 0x1c, 0x33, 0xb6, 0xa7, 0x28, 0x3e, + 0x01, 0x43, 0x36, 0x7f, 0x66, 0x32, 0xc3, 0x85, 0xd9, 0x70, 0x5e, 0x2a, 0x90, 0xaa, 0x61, 0x5e, + 0xd9, 0x67, 0x29, 0x6b, 0x60, 0xb4, 0x44, 0xd0, 0x73, 0xa7, 0xfe, 0x56, 0xa1, 0x85, 0x49, 0x9d, + 0x8a, 0x05, 0x90, 0x6c, 0x10, 0xc4, 0xf5, 0xb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0xca, 0x6b, + 0x30, 0xe0, 0x0e, 0x90, 0x99, 0x78, 0x1a, 0x03, 0xc9, 0xf3, 0x7d, 0x80, 0x7c, 0xe9, 0xcf, 0x02, + 0x90, 0x22, 0xfb, 0x7d, 0x29, 0x5e, 0x29, 0x8a, 0x27, 0x3f, 0xfe, 0x37, 0x5e, 0x30, 0x5e, 0x77, + 0x46, 0xf4, 0x88, 0x97, 0x81, 0x7a, 0xc5, 0xdb, 0x3e, 0x2f, 0x4c, 0x30, 0xd2, 0xd6, 0xea, 0x73, + 0xf1, 0xe4, 0x20, 0x56, 0x2e, 0xf4, 0x8f, 0xf5, 0xcf, 0x7b, 0x07, 0xae, 0xb4, 0xb7, 0xec, 0x7c, + 0x1f, 0x22, 0x1e, 0x58, 0x5e, 0xfc, 0x0b, 0xb0, 0x7f, 0xe4, 0x47, 0x01, 0x8c, 0xb4, 0x75, 0x5e, + 0x8f, 0x18, 0x83, 0xd8, 0x5e, 0x31, 0x76, 0xeb, 0x0d, 0x65, 0xe2, 0x47, 0xb7, 0xde, 0x28, 0xae, + 0x1f, 0x9f, 0x65, 0x84, 0x93, 0xb3, 0x8c, 0xf0, 0xfb, 0x2c, 0x23, 0x7c, 0x3a, 0xcf, 0x24, 0x4e, + 0xce, 0x33, 0x89, 0x9f, 0xe7, 0x99, 0xc4, 0x9b, 0x3c, 0xaa, 0xd3, 0x5a, 0xb3, 0xa2, 0x1a, 0xb8, + 0xa1, 0x05, 0x78, 0xec, 0x4b, 0xbf, 0xdf, 0xf6, 0xbb, 0xe7, 0xc0, 0x82, 0xa4, 0x92, 0x62, 0x9f, + 0xfd, 0xc5, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x0e, 0xa8, 0xd6, 0x94, 0x21, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -692,6 +802,9 @@ type MsgClient interface { HouseDeposit(ctx context.Context, in *MsgHouseDeposit, opts ...grpc.CallOption) (*MsgHouseDepositResponse, error) // HouseWithdraw defines a method for withdrawing funds from a market. HouseWithdraw(ctx context.Context, in *MsgHouseWithdraw, opts ...grpc.CallOption) (*MsgHouseWithdrawResponse, error) + // UpdateParams defines a governance operation for updating the x/subaccount + // module parameters. The authority is defined in the keeper. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -756,6 +869,15 @@ func (c *msgClient) HouseWithdraw(ctx context.Context, in *MsgHouseWithdraw, opt return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // Create defines a method for creating a subaccount. @@ -772,6 +894,9 @@ type MsgServer interface { HouseDeposit(context.Context, *MsgHouseDeposit) (*MsgHouseDepositResponse, error) // HouseWithdraw defines a method for withdrawing funds from a market. HouseWithdraw(context.Context, *MsgHouseWithdraw) (*MsgHouseWithdrawResponse, error) + // UpdateParams defines a governance operation for updating the x/subaccount + // module parameters. The authority is defined in the keeper. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -796,6 +921,9 @@ func (*UnimplementedMsgServer) HouseDeposit(ctx context.Context, req *MsgHouseDe func (*UnimplementedMsgServer) HouseWithdraw(ctx context.Context, req *MsgHouseWithdraw) (*MsgHouseWithdrawResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method HouseWithdraw not implemented") } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -909,6 +1037,24 @@ func _Msg_HouseWithdraw_Handler(srv interface{}, ctx context.Context, dec func(i return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "sgenetwork.sge.subaccount.Msg", HandlerType: (*MsgServer)(nil), @@ -937,6 +1083,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "HouseWithdraw", Handler: _Msg_HouseWithdraw_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "sgenetwork/sge/subaccount/tx.proto", @@ -1355,6 +1505,69 @@ func (m *MsgHouseWithdrawResponse) MarshalToSizedBuffer(dAtA []byte) (int, error return len(dAtA) - i, nil } +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) 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 = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1534,6 +1747,30 @@ func (m *MsgHouseWithdrawResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2612,6 +2849,171 @@ func (m *MsgHouseWithdrawResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) 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 ErrIntOverflowTx + } + 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + 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 := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) 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 ErrIntOverflowTx + } + 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0