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

     1  package feesplit
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/gorilla/mux"
     7  	"github.com/spf13/cobra"
     8  
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context"
    10  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    11  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    12  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module"
    13  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/upgrade"
    14  	"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/base"
    15  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
    16  	tmtypes "github.com/fibonacci-chain/fbc/libs/tendermint/types"
    17  	"github.com/fibonacci-chain/fbc/x/feesplit/client/cli"
    18  	"github.com/fibonacci-chain/fbc/x/feesplit/keeper"
    19  	"github.com/fibonacci-chain/fbc/x/feesplit/types"
    20  )
    21  
    22  // type check to ensure the interface is properly implemented
    23  var (
    24  	_ module.AppModule      = AppModule{}
    25  	_ module.AppModuleBasic = AppModuleBasic{}
    26  	_ upgrade.UpgradeModule = AppModule{}
    27  )
    28  
    29  // AppModuleBasic type for the fees module
    30  type AppModuleBasic struct{}
    31  
    32  // Name returns the fees module's name.
    33  func (AppModuleBasic) Name() string {
    34  	return types.ModuleName
    35  }
    36  
    37  // RegisterCodec registers types for module
    38  func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
    39  	types.RegisterCodec(cdc)
    40  }
    41  
    42  // DefaultGenesis is json default structure
    43  func (AppModuleBasic) DefaultGenesis() json.RawMessage {
    44  	//return types.ModuleCdc.MustMarshalJSON(types.DefaultGenesisState())
    45  	return nil
    46  }
    47  
    48  // ValidateGenesis is the validation check of the Genesis
    49  func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
    50  	if len(bz) > 0 {
    51  		var genesisState types.GenesisState
    52  		err := types.ModuleCdc.UnmarshalJSON(bz, &genesisState)
    53  		if err != nil {
    54  			return err
    55  		}
    56  
    57  		return genesisState.Validate()
    58  	}
    59  	return nil
    60  }
    61  
    62  // RegisterRESTRoutes Registers rest routes
    63  func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
    64  }
    65  
    66  // GetQueryCmd Gets the root query command of this module
    67  func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
    68  	return cli.GetQueryCmd(types.ModuleName, cdc)
    69  }
    70  
    71  // GetTxCmd returns the root tx command for the swap module.
    72  func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
    73  	return cli.GetTxCmd(cdc)
    74  }
    75  
    76  // ___________________________________________________________________________
    77  
    78  // AppModule implements the AppModule interface for the fees module.
    79  type AppModule struct {
    80  	AppModuleBasic
    81  	*base.BaseIBCUpgradeModule
    82  	keeper keeper.Keeper
    83  }
    84  
    85  // NewAppModule creates a new AppModule Object
    86  func NewAppModule(k keeper.Keeper) AppModule {
    87  	m := AppModule{
    88  		AppModuleBasic: AppModuleBasic{},
    89  		keeper:         k,
    90  	}
    91  	m.BaseIBCUpgradeModule = base.NewBaseIBCUpgradeModule(m)
    92  	return m
    93  }
    94  
    95  // Name returns the fees module's name.
    96  func (AppModule) Name() string {
    97  	return types.ModuleName
    98  }
    99  
   100  // RegisterInvariants registers the fees module's invariants.
   101  func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}
   102  
   103  // NewHandler returns nil - fees module doesn't expose tx gRPC endpoints
   104  func (am AppModule) NewHandler() sdk.Handler {
   105  	return NewHandler(am.keeper)
   106  }
   107  
   108  // Route returns the fees module's message routing key.
   109  func (am AppModule) Route() string {
   110  	return types.RouterKey
   111  }
   112  
   113  // QuerierRoute returns the claim module's query routing key.
   114  func (am AppModule) QuerierRoute() string {
   115  	return types.RouterKey
   116  }
   117  
   118  // NewQuerierHandler sets up new querier handler for module
   119  func (am AppModule) NewQuerierHandler() sdk.Querier {
   120  	return keeper.NewQuerier(am.keeper)
   121  }
   122  
   123  // BeginBlock executes all ABCI BeginBlock logic respective to the fees module.
   124  func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {
   125  	if tmtypes.DownloadDelta {
   126  		types.GetParamsCache().SetNeedParamsUpdate()
   127  	}
   128  }
   129  
   130  // EndBlock executes all ABCI EndBlock logic respective to the fees module. It
   131  // returns no validator updates.
   132  func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
   133  	return []abci.ValidatorUpdate{}
   134  }
   135  
   136  // InitGenesis performs the fees module's genesis initialization. It returns
   137  // no validator updates.
   138  func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
   139  	//var genesisState types.GenesisState
   140  	//
   141  	//types.ModuleCdc.MustUnmarshalJSON(data, &genesisState)
   142  	//InitGenesis(ctx, am.keeper, genesisState)
   143  	//return []abci.ValidatorUpdate{}
   144  	return nil
   145  }
   146  
   147  // ExportGenesis returns the fees module's exported genesis state as raw JSON bytes.
   148  func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
   149  	if !tmtypes.HigherThanVenus3(ctx.BlockHeight()) {
   150  		return nil
   151  	}
   152  	gs := ExportGenesis(ctx, am.keeper)
   153  	return types.ModuleCdc.MustMarshalJSON(gs)
   154  	return nil
   155  }