-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from osmosis-labs/vuong/provider-module
Init meshsecurityprovider module
- Loading branch information
Showing
20 changed files
with
2,404 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
|
||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" | ||
) | ||
|
||
// GetQueryCmd returns the cli query commands for this module | ||
func GetQueryCmd() *cobra.Command { | ||
meshsecurityproviderQueryCmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
meshsecurityproviderQueryCmd.AddCommand( | ||
GetCmdQueryParams(), | ||
) | ||
|
||
return meshsecurityproviderQueryCmd | ||
} | ||
|
||
|
||
// GetCmdQueryParams implements a command to return the current parameters. | ||
func GetCmdQueryParams() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "params", | ||
Short: "Query the current meshsecurityprovider module parameters", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
params := &types.ParamsRequest{} | ||
|
||
res, err := queryClient.Params(context.Background(), params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(&res.Params) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
|
||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" | ||
) | ||
|
||
// NewTxCmd returns a root CLI command handler for certain modules transaction commands. | ||
func NewTxCmd() *cobra.Command { | ||
txCmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: "meshsecurityprovider subcommands", | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
txCmd.AddCommand() | ||
return txCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/cometbft/cometbft/libs/log" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" | ||
) | ||
|
||
type Keeper struct { | ||
storeKey storetypes.StoreKey | ||
cdc codec.BinaryCodec | ||
authority string | ||
|
||
bankKeeper types.BankKeeper | ||
wasmKeeper types.WasmKeeper | ||
stakingKeeper types.StakingKeeper | ||
} | ||
|
||
func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, | ||
authority string, bankKeeper types.BankKeeper, wasmKeeper types.WasmKeeper, | ||
stakingKeeper types.StakingKeeper, | ||
) *Keeper { | ||
return &Keeper{ | ||
storeKey: storeKey, | ||
cdc: cdc, | ||
authority: authority, | ||
bankKeeper: bankKeeper, | ||
wasmKeeper: wasmKeeper, | ||
stakingKeeper: stakingKeeper, | ||
} | ||
} | ||
|
||
// Logger returns a module-specific logger. | ||
func (k Keeper) Logger(ctx sdk.Context) log.Logger { | ||
return ctx.Logger().With("module", "x/"+types.ModuleName) | ||
} | ||
|
||
// GetAuthority returns the x/staking module's authority. | ||
func (k Keeper) GetAuthority() string { | ||
return k.authority | ||
} | ||
|
||
// SetParams sets the module's parameters. | ||
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { | ||
if err := params.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
store := ctx.KVStore(k.storeKey) | ||
bz, err := k.cdc.Marshal(¶ms) | ||
if err != nil { | ||
return err | ||
} | ||
store.Set(types.ParamsKey, bz) | ||
|
||
return nil | ||
} | ||
|
||
// GetParams gets the module's parameters. | ||
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get(types.ParamsKey) | ||
if bz == nil { | ||
return params | ||
} | ||
|
||
k.cdc.MustUnmarshal(bz, ¶ms) | ||
return params | ||
} | ||
|
||
// InitGenesis initializes the meshsecurity provider module's state from a provided genesis | ||
// state. | ||
func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { | ||
if err := genState.Validate(); err != nil { | ||
panic(err) | ||
} | ||
|
||
k.SetParams(ctx, genState.Params) | ||
} | ||
|
||
// ExportGenesis returns the meshsecurity provider module's exported genesis. | ||
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { | ||
return &types.GenesisState{ | ||
Params: k.GetParams(ctx), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
|
||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" | ||
) | ||
|
||
type msgServer struct { | ||
*Keeper | ||
} | ||
|
||
// NewMsgServerImpl returns an implementation of the bank MsgServer interface | ||
// for the provided Keeper. | ||
func NewMsgServerImpl(keeper *Keeper) types.MsgServer { | ||
return &msgServer{Keeper: keeper} | ||
} | ||
|
||
var _ types.MsgServer = msgServer{} | ||
|
||
func (ms msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
if ms.authority != msg.Authority { | ||
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.authority, msg.Authority) | ||
} | ||
|
||
// store params | ||
if err := ms.SetParams(ctx, msg.Params); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.MsgUpdateParamsResponse{}, nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// VaultAddress - Address of vault contract | ||
func (k Keeper) VaultAddress(ctx sdk.Context) string { | ||
return k.GetParams(ctx).VaultAddress | ||
} | ||
|
||
// NativeStakingAddress - Address of native staking contract | ||
func (k Keeper) NativeStakingAddress(ctx sdk.Context) string { | ||
return k.GetParams(ctx).NativeStakingAddress | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package module | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/client/cli" | ||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/keeper" | ||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types" | ||
) | ||
|
||
var ( | ||
_ module.AppModule = AppModule{} | ||
_ module.AppModuleBasic = AppModuleBasic{} | ||
) | ||
|
||
type AppModuleBasic struct{} | ||
|
||
func (AppModuleBasic) Name() string { return types.ModuleName } | ||
|
||
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { | ||
types.RegisterLegacyAminoCodec(cdc) | ||
} | ||
|
||
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { | ||
return cdc.MustMarshalJSON(types.DefaultGenesis()) | ||
} | ||
|
||
// ValidateGenesis performs genesis state validation for the meshsecurity provider module. | ||
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { | ||
var genState types.GenesisState | ||
if err := cdc.UnmarshalJSON(bz, &genState); err != nil { | ||
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) | ||
} | ||
return genState.Validate() | ||
} | ||
|
||
// --------------------------------------- | ||
// Interfaces. | ||
func (b AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { | ||
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func (b AppModuleBasic) GetTxCmd() *cobra.Command { | ||
return cli.NewTxCmd() | ||
} | ||
|
||
func (b AppModuleBasic) GetQueryCmd() *cobra.Command { | ||
return cli.GetQueryCmd() | ||
} | ||
|
||
// RegisterInterfaces registers interfaces and implementations of the meshsecurity provider module. | ||
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { | ||
types.RegisterInterfaces(registry) | ||
} | ||
|
||
type AppModule struct { | ||
AppModuleBasic | ||
|
||
k *keeper.Keeper | ||
} | ||
|
||
func (am AppModule) RegisterServices(cfg module.Configurator) { | ||
// types.RegisterMsgServer(cfg.MsgServer(), meshsecurityprovider.NewMsgServerImpl(&am.k)) | ||
// queryproto.RegisterQueryServer(cfg.QueryServer(), grpc.Querier{Q: module.NewQuerier(am.k)}) | ||
} | ||
|
||
func NewAppModule(moduleKeeper *keeper.Keeper) AppModule { | ||
return AppModule{ | ||
AppModuleBasic: AppModuleBasic{}, | ||
k: moduleKeeper, | ||
} | ||
} | ||
|
||
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { | ||
} | ||
|
||
// QuerierRoute returns the meshsecurity provider module's querier route name. | ||
func (AppModule) QuerierRoute() string { return types.RouterKey } | ||
|
||
// InitGenesis performs genesis initialization for the meshsecurity provider module. | ||
// no validator updates. | ||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { | ||
var genesisState types.GenesisState | ||
|
||
cdc.MustUnmarshalJSON(gs, &genesisState) | ||
|
||
am.k.InitGenesis(ctx, &genesisState) | ||
return []abci.ValidatorUpdate{} | ||
} | ||
|
||
// ExportGenesis returns the exported genesis state as raw bytes for the meshsecurity provider. | ||
// module. | ||
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { | ||
genState := am.k.ExportGenesis(ctx) | ||
return cdc.MustMarshalJSON(genState) | ||
} | ||
|
||
// BeginBlock performs TODO. | ||
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} | ||
|
||
// EndBlock performs TODO. | ||
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { | ||
return []abci.ValidatorUpdate{} | ||
} | ||
|
||
// ConsensusVersion implements AppModule/ConsensusVersion. | ||
func (AppModule) ConsensusVersion() uint64 { return 1 } |
Oops, something went wrong.