diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 11a32241..5b9728a8 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -290,6 +290,7 @@ func NewAppKeeper( BankKeeper: appKeepers.BankKeeper, }, authtypes.FeeCollectorName, + govModAddress, ) appKeepers.DistrKeeper = distrkeeper.NewKeeper( @@ -475,7 +476,6 @@ 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( @@ -487,7 +487,7 @@ func NewAppKeeper( AccountKeeper: appKeepers.AccountKeeper, FeeGrantKeeper: appKeepers.FeeGrantKeeper, }, - authority, + govModAddress, ) appKeepers.OVMKeeper = ovmmodulekeeper.NewKeeper( @@ -495,7 +495,7 @@ func NewAppKeeper( appKeepers.keys[ovmmoduletypes.StoreKey], appKeepers.keys[ovmmoduletypes.MemStoreKey], appKeepers.GetSubspace(ovmmoduletypes.ModuleName), - authority, + govModAddress, ) appKeepers.MarketKeeper = marketmodulekeeper.NewKeeper( @@ -503,7 +503,7 @@ func NewAppKeeper( appKeepers.keys[marketmoduletypes.StoreKey], appKeepers.keys[marketmoduletypes.MemStoreKey], appKeepers.GetSubspace(marketmoduletypes.ModuleName), - authority, + govModAddress, ) appKeepers.MarketKeeper.SetOVMKeeper(appKeepers.OVMKeeper) appKeepers.MarketKeeper.SetOrderbookKeeper(appKeepers.OrderbookKeeper) @@ -513,7 +513,7 @@ func NewAppKeeper( appKeepers.keys[betmoduletypes.StoreKey], appKeepers.keys[betmoduletypes.MemStoreKey], appKeepers.GetSubspace(betmoduletypes.ModuleName), - authority, + govModAddress, ) appKeepers.BetKeeper.SetMarketKeeper(appKeepers.MarketKeeper) appKeepers.BetKeeper.SetOrderbookKeeper(appKeepers.OrderbookKeeper) @@ -532,7 +532,7 @@ func NewAppKeeper( housemodulekeeper.SdkExpectedKeepers{ AuthzKeeper: appKeepers.AuthzKeeper, }, - authority, + govModAddress, ) appKeepers.OrderbookKeeper.SetHouseKeeper(appKeepers.HouseKeeper) @@ -546,7 +546,7 @@ func NewAppKeeper( appKeepers.BetKeeper, appKeepers.OrderbookKeeper, appKeepers.HouseKeeper, - authority, + govModAddress, ) appKeepers.RewardKeeper = rewardmodulekeeper.NewKeeper( @@ -562,7 +562,7 @@ func NewAppKeeper( BankKeeper: appKeepers.BankKeeper, AccountKeeper: appKeepers.AccountKeeper, }, - authority, + govModAddress, ) // ** Hooks ** \\ diff --git a/go.mod b/go.mod index fa67301a..44044b6d 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,6 @@ 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 fc0d003a..459ce2ea 100644 --- a/go.sum +++ b/go.sum @@ -2273,6 +2273,7 @@ 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/x/bet/simulation/proposals.go b/x/bet/simulation/proposals.go index b8e12cd3..060b2dc1 100644 --- a/x/bet/simulation/proposals.go +++ b/x/bet/simulation/proposals.go @@ -16,7 +16,7 @@ import ( const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec ) // ProposalMsgs defines the module weighted proposals' contents diff --git a/x/bet/simulation/proposals_test.go b/x/bet/simulation/proposals_test.go index 9dd7cce6..6e7a8b5e 100644 --- a/x/bet/simulation/proposals_test.go +++ b/x/bet/simulation/proposals_test.go @@ -19,6 +19,7 @@ import ( func TestProposalMsgs(t *testing.T) { // initialize parameters s := rand.NewSource(1) + //#nosec r := rand.New(s) ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) diff --git a/x/house/simulation/proposals.go b/x/house/simulation/proposals.go index b0664565..e1acf047 100644 --- a/x/house/simulation/proposals.go +++ b/x/house/simulation/proposals.go @@ -16,7 +16,7 @@ import ( const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec ) // ProposalMsgs defines the module weighted proposals' contents diff --git a/x/house/simulation/proposals_test.go b/x/house/simulation/proposals_test.go index 6d2de8dd..37ee4b9b 100644 --- a/x/house/simulation/proposals_test.go +++ b/x/house/simulation/proposals_test.go @@ -19,6 +19,7 @@ import ( func TestProposalMsgs(t *testing.T) { // initialize parameters s := rand.NewSource(1) + //#nosec r := rand.New(s) ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) diff --git a/x/market/simulation/proposals.go b/x/market/simulation/proposals.go index 0747f83c..2be67a41 100644 --- a/x/market/simulation/proposals.go +++ b/x/market/simulation/proposals.go @@ -15,7 +15,7 @@ import ( const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec ) // ProposalMsgs defines the module weighted proposals' contents @@ -30,7 +30,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg { } // SimulateMsgUpdateParams returns a random MsgUpdateParams -func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { +func SimulateMsgUpdateParams(_ *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { // use the default gov module account address as authority var authority sdk.AccAddress = address.Module("gov") diff --git a/x/market/simulation/proposals_test.go b/x/market/simulation/proposals_test.go index 8a7d06e6..7c57131d 100644 --- a/x/market/simulation/proposals_test.go +++ b/x/market/simulation/proposals_test.go @@ -18,6 +18,7 @@ import ( func TestProposalMsgs(t *testing.T) { // initialize parameters s := rand.NewSource(1) + //#nosec r := rand.New(s) ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index 6f914615..f650f851 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -21,6 +21,9 @@ type Keeper struct { stakingKeeper types.StakingKeeper bankKeeper types.BankKeeper feeCollectorName string + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string } // ExpectedKeepers contains expected keepers parameter needed by NewKeeper @@ -37,6 +40,7 @@ func NewKeeper( ak types.AccountKeeper, expectedKeepers ExpectedKeepers, feeCollectorName string, + authority string, ) *Keeper { // ensure mint module account is set if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { @@ -55,6 +59,7 @@ func NewKeeper( stakingKeeper: expectedKeepers.StakingKeeper, bankKeeper: expectedKeepers.BankKeeper, feeCollectorName: feeCollectorName, + authority: authority, } } diff --git a/x/mint/keeper/msg_server.go b/x/mint/keeper/msg_server.go new file mode 100644 index 00000000..a18ae394 --- /dev/null +++ b/x/mint/keeper/msg_server.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/sge-network/sge/x/mint/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/mint/keeper/msg_server_params.go b/x/mint/keeper/msg_server_params.go new file mode 100644 index 00000000..c4c7770d --- /dev/null +++ b/x/mint/keeper/msg_server_params.go @@ -0,0 +1,28 @@ +package keeper + +import ( + "context" + + "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/mint/types" +) + +// UpdateParams updates the params. +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if k.authority != req.Authority { + return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, 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/mint/module.go b/x/mint/module.go index 3075ce3b..818e0949 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -127,6 +127,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/keeper/msg_server_test.go b/x/orderbook/keeper/msg_server_test.go deleted file mode 100644 index 9fa03ecc..00000000 --- a/x/orderbook/keeper/msg_server_test.go +++ /dev/null @@ -1,19 +0,0 @@ -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/simulation/proposals.go b/x/orderbook/simulation/proposals.go index cdcaa421..86b99778 100644 --- a/x/orderbook/simulation/proposals.go +++ b/x/orderbook/simulation/proposals.go @@ -15,7 +15,7 @@ import ( const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec ) // ProposalMsgs defines the module weighted proposals' contents diff --git a/x/orderbook/simulation/proposals_test.go b/x/orderbook/simulation/proposals_test.go index 4bc6cccd..9f73bdc5 100644 --- a/x/orderbook/simulation/proposals_test.go +++ b/x/orderbook/simulation/proposals_test.go @@ -18,6 +18,7 @@ import ( func TestProposalMsgs(t *testing.T) { // initialize parameters s := rand.NewSource(1) + //#nosec r := rand.New(s) ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) diff --git a/x/ovm/simulation/proposals.go b/x/ovm/simulation/proposals.go index 6fd90d96..3a3ce0c2 100644 --- a/x/ovm/simulation/proposals.go +++ b/x/ovm/simulation/proposals.go @@ -15,7 +15,7 @@ import ( const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec ) // ProposalMsgs defines the module weighted proposals' contents @@ -30,7 +30,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg { } // SimulateMsgUpdateParams returns a random MsgUpdateParams -func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { +func SimulateMsgUpdateParams(_ *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { // use the default gov module account address as authority var authority sdk.AccAddress = address.Module("gov") diff --git a/x/ovm/simulation/proposals_test.go b/x/ovm/simulation/proposals_test.go index 2b91c146..8183cf30 100644 --- a/x/ovm/simulation/proposals_test.go +++ b/x/ovm/simulation/proposals_test.go @@ -18,6 +18,7 @@ import ( func TestProposalMsgs(t *testing.T) { // initialize parameters s := rand.NewSource(1) + //#nosec r := rand.New(s) ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) diff --git a/x/reward/simulation/proposals.go b/x/reward/simulation/proposals.go index b5ba6caf..10d500d7 100644 --- a/x/reward/simulation/proposals.go +++ b/x/reward/simulation/proposals.go @@ -15,7 +15,7 @@ import ( const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec ) // ProposalMsgs defines the module weighted proposals' contents @@ -30,7 +30,7 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg { } // SimulateMsgUpdateParams returns a random MsgUpdateParams -func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { +func SimulateMsgUpdateParams(_ *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { // use the default gov module account address as authority var authority sdk.AccAddress = address.Module("gov") diff --git a/x/reward/simulation/proposals_test.go b/x/reward/simulation/proposals_test.go index 31481836..a2e01a33 100644 --- a/x/reward/simulation/proposals_test.go +++ b/x/reward/simulation/proposals_test.go @@ -18,6 +18,7 @@ import ( func TestProposalMsgs(t *testing.T) { // initialize parameters s := rand.NewSource(1) + //#nosec r := rand.New(s) ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) diff --git a/x/subaccount/simulation/proposals.go b/x/subaccount/simulation/proposals.go index 04dd4b5c..c6265cb2 100644 --- a/x/subaccount/simulation/proposals.go +++ b/x/subaccount/simulation/proposals.go @@ -15,7 +15,7 @@ import ( const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //#nosec ) // ProposalMsgs defines the module weighted proposals' contents diff --git a/x/subaccount/simulation/proposals_test.go b/x/subaccount/simulation/proposals_test.go index 98dc7f71..43e7a464 100644 --- a/x/subaccount/simulation/proposals_test.go +++ b/x/subaccount/simulation/proposals_test.go @@ -18,6 +18,7 @@ import ( func TestProposalMsgs(t *testing.T) { // initialize parameters s := rand.NewSource(1) + //#nosec r := rand.New(s) ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil)