github.com/cosmos/cosmos-sdk@v0.50.10/x/auth/vesting/module.go (about) 1 package vesting 2 3 import ( 4 "encoding/json" 5 6 abci "github.com/cometbft/cometbft/abci/types" 7 gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" 8 "github.com/spf13/cobra" 9 "google.golang.org/grpc" 10 11 modulev1 "cosmossdk.io/api/cosmos/vesting/module/v1" 12 "cosmossdk.io/core/address" 13 "cosmossdk.io/core/appmodule" 14 "cosmossdk.io/depinject" 15 16 "github.com/cosmos/cosmos-sdk/client" 17 "github.com/cosmos/cosmos-sdk/codec" 18 codectypes "github.com/cosmos/cosmos-sdk/codec/types" 19 sdk "github.com/cosmos/cosmos-sdk/types" 20 "github.com/cosmos/cosmos-sdk/types/module" 21 "github.com/cosmos/cosmos-sdk/x/auth/keeper" 22 "github.com/cosmos/cosmos-sdk/x/auth/vesting/client/cli" 23 "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" 24 ) 25 26 var ( 27 _ module.AppModuleBasic = AppModule{} 28 29 _ appmodule.AppModule = AppModule{} 30 _ appmodule.HasServices = AppModule{} 31 ) 32 33 // AppModuleBasic defines the basic application module used by the sub-vesting 34 // module. The module itself contain no special logic or state other than message 35 // handling. 36 type AppModuleBasic struct { 37 ac address.Codec 38 } 39 40 // Name returns the module's name. 41 func (AppModuleBasic) Name() string { 42 return types.ModuleName 43 } 44 45 // RegisterCodec registers the module's types with the given codec. 46 func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { 47 types.RegisterLegacyAminoCodec(cdc) 48 } 49 50 // RegisterInterfaces registers the module's interfaces and implementations with 51 // the given interface registry. 52 func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { 53 types.RegisterInterfaces(registry) 54 } 55 56 // DefaultGenesis returns the module's default genesis state as raw bytes. 57 func (AppModuleBasic) DefaultGenesis(_ codec.JSONCodec) json.RawMessage { 58 return []byte("{}") 59 } 60 61 // ValidateGenesis performs genesis state validation. Currently, this is a no-op. 62 func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { 63 return nil 64 } 65 66 // RegisterGRPCGatewayRoutes registers the module's gRPC Gateway routes. Currently, this 67 // is a no-op. 68 func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {} 69 70 // GetTxCmd returns the root tx command for the auth module. 71 func (ab AppModuleBasic) GetTxCmd() *cobra.Command { 72 return cli.GetTxCmd(ab.ac) 73 } 74 75 // AppModule extends the AppModuleBasic implementation by implementing the 76 // AppModule interface. 77 type AppModule struct { 78 AppModuleBasic 79 80 accountKeeper keeper.AccountKeeper 81 bankKeeper types.BankKeeper 82 } 83 84 func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule { 85 return AppModule{ 86 AppModuleBasic: AppModuleBasic{ac: ak.AddressCodec()}, 87 accountKeeper: ak, 88 bankKeeper: bk, 89 } 90 } 91 92 // IsOnePerModuleType implements the depinject.OnePerModuleType interface. 93 func (am AppModule) IsOnePerModuleType() {} 94 95 // IsAppModule implements the appmodule.AppModule interface. 96 func (am AppModule) IsAppModule() {} 97 98 // RegisterServices registers module services. 99 func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { 100 types.RegisterMsgServer(registrar, NewMsgServerImpl(am.accountKeeper, am.bankKeeper)) 101 return nil 102 } 103 104 // InitGenesis performs a no-op. 105 func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { 106 return []abci.ValidatorUpdate{} 107 } 108 109 // ExportGenesis is always empty, as InitGenesis does nothing either. 110 func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { 111 return am.DefaultGenesis(cdc) 112 } 113 114 // ConsensusVersion implements AppModule/ConsensusVersion. 115 func (AppModule) ConsensusVersion() uint64 { return 1 } 116 117 // 118 // App Wiring Setup 119 // 120 121 func init() { 122 appmodule.Register(&modulev1.Module{}, 123 appmodule.Provide(ProvideModule), 124 ) 125 } 126 127 type ModuleInputs struct { 128 depinject.In 129 130 AccountKeeper keeper.AccountKeeper 131 BankKeeper types.BankKeeper 132 } 133 134 type ModuleOutputs struct { 135 depinject.Out 136 137 Module appmodule.AppModule 138 } 139 140 func ProvideModule(in ModuleInputs) ModuleOutputs { 141 m := NewAppModule(in.AccountKeeper, in.BankKeeper) 142 143 return ModuleOutputs{Module: m} 144 }