Files
sonr/x/dex/module.go
T
Prad NukalaandGitHub 13e6c3e84d Master (#1262)
* clear

* feat: Add everything

* fix: Commenht
2025-10-03 14:45:52 -04:00

151 lines
4.6 KiB
Go
Executable File

// Package dex defines the swap module.
package dex
import (
"context"
"encoding/json"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
cli "github.com/sonr-io/sonr/x/dex/client/cli"
"github.com/sonr-io/sonr/x/dex/keeper"
"github.com/sonr-io/sonr/x/dex/types"
"github.com/spf13/cobra"
"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"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
abci "github.com/cometbft/cometbft/abci/types"
)
var (
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModule = AppModule{}
_ module.AppModuleSimulation = AppModule{}
)
// AppModuleBasic is the module AppModuleBasic.
type AppModuleBasic struct{}
// Name implements AppModuleBasic interface.
func (AppModuleBasic) Name() string {
return types.ModuleName
}
// RegisterLegacyAminoCodec implements AppModuleBasic interface.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// RegisterInterfaces registers module concrete types into protobuf Any.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// DefaultGenesis returns default genesis state as raw bytes for the swap module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the swap 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 err
}
return genState.Validate()
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the swap module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// GetTxCmd implements AppModuleBasic interface.
func (AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}
// GetQueryCmd implements AppModuleBasic interface.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.NewQueryCmd()
}
// AppModule is the module AppModule.
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
}
// IsAppModule implements module.AppModule.
func (AppModule) IsAppModule() {
}
// IsOnePerModuleType implements module.AppModule.
func (AppModule) IsOnePerModuleType() {
}
// NewAppModule initializes a new AppModule for the module.
func NewAppModule(keeper keeper.Keeper) *AppModule {
return &AppModule{
keeper: keeper,
}
}
// RegisterInvariants implements the AppModule interface.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
}
// InitGenesis performs genesis initialization for the ibc-router module. It returns
// no validator updates.
func (am AppModule) InitGenesis(
ctx sdk.Context,
cdc codec.JSONCodec,
data json.RawMessage,
) []abci.ValidatorUpdate {
var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
am.keeper.InitGenesis(ctx, genesisState)
return []abci.ValidatorUpdate{}
}
// ExportGenesis returns the exported genesis state as raw bytes for the swap module.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
genState := am.keeper.ExportGenesis(ctx)
return cdc.MustMarshalJSON(genState)
}
// ConsensusVersion returns the consensus state breaking version for the swap module.
func (am AppModule) ConsensusVersion() uint64 { return 1 }
// GenerateGenesisState implements the AppModuleSimulation interface.
func (am AppModule) GenerateGenesisState(simState *module.SimulationState) {}
// ProposalContents implements the AppModuleSimulation interface.
func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}
// RegisterStoreDecoder implements the AppModuleSimulation interface.
func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) {}
// WeightedOperations implements the AppModuleSimulation interface.
func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
return nil
}