-
Notifications
You must be signed in to change notification settings - Fork 2
/
module.go
113 lines (90 loc) · 3 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
package pbb
import (
"encoding/json"
"github.com/csmuller/up-voting-system/pbb/internal/types"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/csmuller/up-voting-system/pbb/client/cli"
"github.com/csmuller/up-voting-system/pbb/client/rest"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
)
var (
// Make sure the interfaces are implemented.
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
)
type AppModuleBasic struct{}
func (AppModuleBasic) Name() string {
return BulletinBoardModuleName
}
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
RegisterCodec(cdc)
}
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
return ModuleCdc.MustMarshalJSON(DefaultGenesisState())
}
// ValidateGenesis validates the Genesis block information given in the JSON message.
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
var data types.GenesisState
err := ModuleCdc.UnmarshalJSON(bz, &data)
if err != nil {
return err
}
return ValidateGenesis(data)
}
// Register rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
rest.RegisterRoutes(ctx, rtr, BulletinBoardModuleName)
}
// Get the root query command of this module
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(BulletinBoardModuleName, cdc)
}
// Get the root tx command of this module
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetTxCmd(BulletinBoardModuleName, cdc)
}
type AppModule struct {
AppModuleBasic
bulletinBoardKeeper BulletinBoardKeeper
}
func NewAppModule(k BulletinBoardKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
bulletinBoardKeeper: k,
}
}
func (AppModule) Name() string {
return BulletinBoardModuleName
}
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}
func (am AppModule) Route() string {
return BulletinBoardModuleName
}
func (am AppModule) NewHandler() sdk.Handler {
return NewHandler(am.bulletinBoardKeeper)
}
func (am AppModule) QuerierRoute() string {
return BulletinBoardModuleName
}
func (am AppModule) NewQuerierHandler() sdk.Querier {
return NewQuerier(am.bulletinBoardKeeper)
}
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
func (am AppModule) EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState types.GenesisState
types.ModuleCdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.bulletinBoardKeeper, genesisState)
return []abci.ValidatorUpdate{}
}
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
gs := ExportGenesis(ctx, am.bulletinBoardKeeper)
return ModuleCdc.MustMarshalJSON(gs)
}