github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/genutil/module.go (about)

     1  package genutil
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/fibonacci-chain/fbc/x/genutil/types"
     7  
     8  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context"
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    10  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    11  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module"
    12  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
    13  	"github.com/gorilla/mux"
    14  	"github.com/spf13/cobra"
    15  )
    16  
    17  var (
    18  	_ module.AppModuleGenesis = AppModule{}
    19  	_ module.AppModuleBasic   = AppModuleBasic{}
    20  )
    21  
    22  // AppModuleBasic is the struct of app module basics object
    23  type AppModuleBasic struct{}
    24  
    25  // Name returns the module name
    26  func (AppModuleBasic) Name() string {
    27  	return ModuleName
    28  }
    29  
    30  // DefaultGenesis returns the default genesis state in json raw message
    31  func (AppModuleBasic) DefaultGenesis() json.RawMessage {
    32  	return ModuleCdc.MustMarshalJSON(GenesisState{})
    33  }
    34  
    35  // ValidateGenesis gives a quick validity check for module genesis
    36  func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
    37  	var data GenesisState
    38  	err := ModuleCdc.UnmarshalJSON(bz, &data)
    39  	if err != nil {
    40  		return err
    41  	}
    42  	return ValidateGenesis(data)
    43  }
    44  
    45  // nolint
    46  func (AppModuleBasic) RegisterCodec(cdc *codec.Codec)                         {}
    47  func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {}
    48  func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command                 { return nil }
    49  func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command              { return nil }
    50  
    51  // AppModule is the struct of this app module
    52  type AppModule struct {
    53  	AppModuleBasic
    54  	accountKeeper types.AccountKeeper
    55  	stakingKeeper types.StakingKeeper
    56  	deliverTx     deliverTxfn
    57  }
    58  
    59  // NewAppModule creates a new AppModule object
    60  func NewAppModule(accountKeeper types.AccountKeeper,
    61  	stakingKeeper types.StakingKeeper, deliverTx deliverTxfn) module.AppModule {
    62  
    63  	return module.NewGenesisOnlyAppModule(AppModule{
    64  		AppModuleBasic: AppModuleBasic{},
    65  		accountKeeper:  accountKeeper,
    66  		stakingKeeper:  stakingKeeper,
    67  		deliverTx:      deliverTx,
    68  	})
    69  }
    70  
    71  // InitGenesis initializes the module genesis state
    72  func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
    73  	var genesisState GenesisState
    74  	ModuleCdc.MustUnmarshalJSON(data, &genesisState)
    75  	return InitGenesis(ctx, ModuleCdc, am.stakingKeeper, am.deliverTx, genesisState)
    76  }
    77  
    78  // ExportGenesis exports the module genesis state
    79  func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
    80  	return nil
    81  }