forked from terra-money/alliance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
148 lines (119 loc) · 4.71 KB
/
module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package alliance
import (
"context"
"encoding/json"
"fmt"
simulation2 "github.com/noria-net/alliance/x/alliance/tests/simulation"
// this line is used by starport scaffolding # 1
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/noria-net/alliance/x/alliance/client/cli"
"github.com/noria-net/alliance/x/alliance/keeper"
migrationsv4 "github.com/noria-net/alliance/x/alliance/migrations/v4"
"github.com/noria-net/alliance/x/alliance/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)
var (
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModule = AppModule{}
_ module.AppModuleSimulation = AppModule{}
_ module.EndBlockAppModule = AppModule{}
)
type AppModuleBasic struct {
cdc codec.Codec
pcdc *codec.ProtoCodec
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, sk types.StakingKeeper,
ak types.AccountKeeper, bk types.BankKeeper, registry cdctypes.InterfaceRegistry,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc, pcdc: codec.NewProtoCodec(registry)},
keeper: keeper,
stakingKeeper: sk,
bankKeeper: bk,
accountKeeper: ak,
}
}
func (a AppModuleBasic) Name() string {
return types.ModuleName
}
func (a AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
func (a AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
func (a AppModuleBasic) DefaultGenesis(jsonCodec codec.JSONCodec) json.RawMessage {
return jsonCodec.MustMarshalJSON(DefaultGenesisState())
}
func (a AppModuleBasic) ValidateGenesis(jsonCodec codec.JSONCodec, _ client.TxEncodingConfig, message json.RawMessage) error {
var genesis types.GenesisState
if err := jsonCodec.UnmarshalJSON(message, &genesis); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return ValidateGenesis(&genesis)
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck
}
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}
func (a AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}
// AppModule implements an application module for the alliance module.
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
stakingKeeper types.StakingKeeper
bankKeeper types.BankKeeper
accountKeeper types.AccountKeeper
}
func (a AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return EndBlocker(ctx, a.keeper)
}
func (a AppModule) InitGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec, message json.RawMessage) []abci.ValidatorUpdate {
var genesis types.GenesisState
jsonCodec.MustUnmarshalJSON(message, &genesis)
return a.keeper.InitGenesis(ctx, &genesis)
}
func (a AppModule) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) json.RawMessage {
genesis := a.keeper.ExportGenesis(ctx)
return a.cdc.MustMarshalJSON(genesis)
}
func (a AppModule) RegisterInvariants(registry sdk.InvariantRegistry) {
RegisterInvariants(registry, a.keeper)
}
// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries
func (a AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(a.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(a.keeper))
err := cfg.RegisterMigration(types.ModuleName, 3, migrationsv4.Migrate(a.keeper))
if err != nil {
panic(fmt.Sprintf("failed to migrate x/alliance from version 3 to 4: %v", err))
}
}
func (a AppModule) ConsensusVersion() uint64 {
return 4
}
func (a AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation2.RandomizedGenesisState(simState)
}
func (a AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return nil
}
func (a AppModule) RegisterStoreDecoder(registry sdk.StoreDecoderRegistry) {
registry[types.StoreKey] = simulation2.NewDecodeStore(a.cdc)
}
func (a AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
return simulation2.WeightedOperations(a.pcdc, a.accountKeeper, a.bankKeeper, a.stakingKeeper, a.keeper)
}