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

     1  package upgrade
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/gorilla/mux"
     6  	"github.com/spf13/cobra"
     7  
     8  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
     9  
    10  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context"
    11  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/flags"
    12  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    13  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    14  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module"
    15  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/upgrade/client/cli"
    16  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/upgrade/client/rest"
    17  )
    18  
    19  // module codec
    20  var moduleCdc = codec.New()
    21  
    22  func init() {
    23  	RegisterCodec(moduleCdc)
    24  }
    25  
    26  var (
    27  	_ module.AppModule      = AppModule{}
    28  	_ module.AppModuleBasic = AppModuleBasic{}
    29  )
    30  
    31  // AppModuleBasic implements the sdk.AppModuleBasic interface
    32  type AppModuleBasic struct{}
    33  
    34  // Name returns the ModuleName
    35  func (AppModuleBasic) Name() string {
    36  	return ModuleName
    37  }
    38  
    39  // RegisterCodec registers the upgrade types on the amino codec
    40  func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
    41  	RegisterCodec(cdc)
    42  }
    43  
    44  // RegisterRESTRoutes registers all REST query handlers
    45  func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, r *mux.Router) {
    46  	rest.RegisterRoutes(ctx, r)
    47  }
    48  
    49  // GetQueryCmd returns the cli query commands for this module
    50  func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
    51  	queryCmd := &cobra.Command{
    52  		Use:   "upgrade",
    53  		Short: "Querying commands for the upgrade module",
    54  	}
    55  	queryCmd.AddCommand(flags.GetCommands(
    56  		cli.GetPlanCmd(StoreKey, cdc),
    57  		cli.GetAppliedHeightCmd(StoreKey, cdc),
    58  	)...)
    59  
    60  	return queryCmd
    61  }
    62  
    63  // GetTxCmd returns the transaction commands for this module
    64  func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
    65  	txCmd := &cobra.Command{
    66  		Use:   "upgrade",
    67  		Short: "Upgrade transaction subcommands",
    68  	}
    69  	txCmd.AddCommand(flags.PostCommands()...)
    70  	return txCmd
    71  }
    72  
    73  // AppModule implements the sdk.AppModule interface
    74  type AppModule struct {
    75  	AppModuleBasic
    76  	keeper Keeper
    77  }
    78  
    79  // NewAppModule creates a new AppModule object
    80  func NewAppModule(keeper Keeper) AppModule {
    81  	return AppModule{
    82  		AppModuleBasic: AppModuleBasic{},
    83  		keeper:         keeper,
    84  	}
    85  }
    86  
    87  // RegisterInvariants does nothing, there are no invariants to enforce
    88  func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
    89  
    90  // Route is empty, as we do not handle Messages (just proposals)
    91  func (AppModule) Route() string { return "" }
    92  
    93  // NewHandler is empty, as we do not handle Messages (just proposals)
    94  func (am AppModule) NewHandler() sdk.Handler { return nil }
    95  
    96  // QuerierRoute returns the route we respond to for abci queries
    97  func (AppModule) QuerierRoute() string { return QuerierKey }
    98  
    99  // NewQuerierHandler registers a query handler to respond to the module-specific queries
   100  func (am AppModule) NewQuerierHandler() sdk.Querier {
   101  	return NewQuerier(am.keeper)
   102  }
   103  
   104  // InitGenesis is ignored, no sense in serializing future upgrades
   105  func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
   106  	return []abci.ValidatorUpdate{}
   107  }
   108  
   109  // DefaultGenesis is an empty object
   110  func (AppModuleBasic) DefaultGenesis() json.RawMessage {
   111  	return []byte("{}")
   112  }
   113  
   114  // ValidateGenesis is always successful, as we ignore the value
   115  func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
   116  	return nil
   117  }
   118  
   119  // ExportGenesis is always empty, as InitGenesis does nothing either
   120  func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
   121  	return am.DefaultGenesis()
   122  }
   123  
   124  // BeginBlock calls the upgrade module hooks
   125  //
   126  // CONTRACT: this is registered in BeginBlocker *before* all other modules' BeginBlock functions
   127  func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
   128  	BeginBlocker(am.keeper, ctx, req)
   129  }
   130  
   131  // EndBlock does nothing
   132  func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
   133  	return []abci.ValidatorUpdate{}
   134  }