-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
109 lines (89 loc) · 3.27 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
package gravity
import (
"encoding/json"
"fmt"
"github.com/ci123chain/ci123chain/pkg/abci/types/module"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/ci123chain/ci123chain/pkg/abci/codec"
codectypes "github.com/ci123chain/ci123chain/pkg/abci/codec/types"
sdk "github.com/ci123chain/ci123chain/pkg/abci/types"
"github.com/ci123chain/ci123chain/pkg/account"
client "github.com/ci123chain/ci123chain/pkg/client/context"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/ci123chain/ci123chain/pkg/gravity/keeper"
"github.com/ci123chain/ci123chain/pkg/gravity/types"
)
// type check to ensure the interface is properly implemented
var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
)
// AppModuleBasic object for module implementation
type AppModuleBasic struct{}
// Name implements app module basic
func (AppModuleBasic) Name() string {
return types.ModuleName
}
func (AppModuleBasic) RegisterCodec(codec *codec.Codec) {
types.RegisterCodec(codec)
}
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
types.SetBinary(registry)
return
}
func (am AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {}
// DefaultGenesis implements app module basic
func (AppModuleBasic) DefaultGenesis(validators []tmtypes.GenesisValidator) json.RawMessage {
bz, _ := json.Marshal(types.DefaultGenesisState())
return bz
}
//____________________________________________________________________________
// AppModule object for module implementation
type AppModule struct {
AppModuleBasic
Keeper keeper.Keeper
AccKeeper account.AccountKeeper
}
// NewAppModule creates a new AppModule Object
func NewAppModule(k keeper.Keeper, accKeeper account.AccountKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
Keeper: k,
AccKeeper: accKeeper,
}
}
// Name implements app module
func (AppModule) Name() string {
return types.ModuleName
}
// InitGenesis initializes the genesis state for this module and implements app module.
func (am AppModule) InitGenesis(ctx sdk.Context, bz json.RawMessage) []abci.ValidatorUpdate {
var genesisState types.GenesisState
err := types.SubModuleCdc.UnmarshalJSON(bz, &genesisState)
if err != nil {
panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", types.ModuleName, err))
}
keeper.InitGenesis(ctx, am.Keeper, genesisState)
return []abci.ValidatorUpdate{}
}
//// ExportGenesis exports the current genesis state to a json.RawMessage
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
gs := keeper.ExportGenesis(ctx, am.Keeper)
return types.SubModuleCdc.MustMarshalJSON(&gs)
}
// EndBlock implements app module
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
EndBlocker(ctx, am.Keeper)
// this begin blocker is only for testing purposes, don't import into your
// own chain running gravity
//TestingEndBlocker(ctx, am.Keeper)
return []abci.ValidatorUpdate{}
}
func (m AppModule) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) {
}
func (m AppModule) Committer(ctx sdk.Context) {
}
func (am AppModule) RegisterServices(cfg module.Configurator) {
}