github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/mint/module.go (about)

     1  package mint
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/mint/internal/types"
     7  	"math/rand"
     8  
     9  	"github.com/gorilla/mux"
    10  	"github.com/spf13/cobra"
    11  
    12  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
    13  
    14  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context"
    15  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    16  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    17  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module"
    18  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/mint/client/cli"
    19  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/mint/client/rest"
    20  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/mint/simulation"
    21  	sim "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/simulation"
    22  )
    23  
    24  var (
    25  	_ module.AppModule           = AppModule{}
    26  	_ module.AppModuleBasic      = AppModuleBasic{}
    27  	_ module.AppModuleSimulation = AppModule{}
    28  )
    29  
    30  // AppModuleBasic defines the basic application module used by the mint module.
    31  type AppModuleBasic struct{}
    32  
    33  var _ module.AppModuleBasic = AppModuleBasic{}
    34  
    35  // Name returns the mint module's name.
    36  func (AppModuleBasic) Name() string {
    37  	return ModuleName
    38  }
    39  
    40  // RegisterCodec registers the mint module's types for the given codec.
    41  func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
    42  	types.RegisterCodec(cdc)
    43  }
    44  
    45  // DefaultGenesis returns default genesis state as raw bytes for the mint
    46  // module.
    47  func (AppModuleBasic) DefaultGenesis() json.RawMessage {
    48  	return ModuleCdc.MustMarshalJSON(DefaultGenesisState())
    49  }
    50  
    51  // ValidateGenesis performs genesis state validation for the mint module.
    52  func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
    53  	var data GenesisState
    54  	if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil {
    55  		return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err)
    56  	}
    57  
    58  	return ValidateGenesis(data)
    59  }
    60  
    61  // RegisterRESTRoutes registers the REST routes for the mint module.
    62  func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
    63  	rest.RegisterRoutes(ctx, rtr)
    64  }
    65  
    66  // GetTxCmd returns no root tx command for the mint module.
    67  func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil }
    68  
    69  // GetQueryCmd returns the root query command for the mint module.
    70  func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
    71  	return cli.GetQueryCmd(cdc)
    72  }
    73  
    74  //____________________________________________________________________________
    75  
    76  // AppModule implements an application module for the mint module.
    77  type AppModule struct {
    78  	AppModuleBasic
    79  
    80  	keeper Keeper
    81  }
    82  
    83  // NewAppModule creates a new AppModule object
    84  func NewAppModule(keeper Keeper) AppModule {
    85  	return AppModule{
    86  		AppModuleBasic: AppModuleBasic{},
    87  		keeper:         keeper,
    88  	}
    89  }
    90  
    91  // Name returns the mint module's name.
    92  func (AppModule) Name() string {
    93  	return ModuleName
    94  }
    95  
    96  // RegisterInvariants registers the mint module invariants.
    97  func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
    98  
    99  // Route returns the message routing key for the mint module.
   100  func (AppModule) Route() string { return "" }
   101  
   102  // NewHandler returns an sdk.Handler for the mint module.
   103  func (am AppModule) NewHandler() sdk.Handler { return nil }
   104  
   105  // QuerierRoute returns the mint module's querier route name.
   106  func (AppModule) QuerierRoute() string {
   107  	return QuerierRoute
   108  }
   109  
   110  // NewQuerierHandler returns the mint module sdk.Querier.
   111  func (am AppModule) NewQuerierHandler() sdk.Querier {
   112  	return NewQuerier(am.keeper)
   113  }
   114  
   115  // InitGenesis performs genesis initialization for the mint module. It returns
   116  // no validator updates.
   117  func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
   118  	var genesisState GenesisState
   119  	ModuleCdc.MustUnmarshalJSON(data, &genesisState)
   120  	InitGenesis(ctx, am.keeper, genesisState)
   121  	return []abci.ValidatorUpdate{}
   122  }
   123  
   124  // ExportGenesis returns the exported genesis state as raw bytes for the mint
   125  // module.
   126  func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
   127  	gs := ExportGenesis(ctx, am.keeper)
   128  	return ModuleCdc.MustMarshalJSON(gs)
   129  }
   130  
   131  // BeginBlock returns the begin blocker for the mint module.
   132  func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
   133  	BeginBlocker(ctx, am.keeper)
   134  }
   135  
   136  // EndBlock returns the end blocker for the mint module. It returns no validator
   137  // updates.
   138  func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
   139  	return []abci.ValidatorUpdate{}
   140  }
   141  
   142  //____________________________________________________________________________
   143  
   144  // AppModuleSimulation functions
   145  
   146  // GenerateGenesisState creates a randomized GenState of the mint module.
   147  func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
   148  	simulation.RandomizedGenState(simState)
   149  }
   150  
   151  // ProposalContents doesn't return any content functions for governance proposals.
   152  func (AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalContent {
   153  	return nil
   154  }
   155  
   156  // RandomizedParams creates randomized mint param changes for the simulator.
   157  func (AppModule) RandomizedParams(r *rand.Rand) []sim.ParamChange {
   158  	return simulation.ParamChanges(r)
   159  }
   160  
   161  // RegisterStoreDecoder registers a decoder for mint module's types.
   162  func (AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
   163  	sdr[StoreKey] = simulation.DecodeStore
   164  }
   165  
   166  // WeightedOperations doesn't return any mint module operation.
   167  func (AppModule) WeightedOperations(_ module.SimulationState) []sim.WeightedOperation {
   168  	return nil
   169  }