/
app.go
271 lines (236 loc) · 8.62 KB
/
app.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package hub
import (
"encoding/json"
"io"
"os"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/crisis"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/genaccounts"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/params/client"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
db "github.com/tendermint/tm-db"
"github.com/sentinel-official/hub/x/deposit"
"github.com/sentinel-official/hub/x/vpn"
)
const (
appName = "Sentinel Hub"
)
var (
DefaultNodeHome = os.ExpandEnv("$HOME/.sentinel-hub-daemon")
DefaultCLIHome = os.ExpandEnv("$HOME/.sentinel-hub-cli")
ModuleBasics = module.NewBasicManager(
genaccounts.AppModuleBasic{},
genutil.AppModuleBasic{},
params.AppModuleBasic{},
auth.AppModuleBasic{},
bank.AppModuleBasic{},
supply.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distribution.AppModuleBasic{},
slashing.AppModuleBasic{},
crisis.AppModuleBasic{},
gov.NewAppModuleBasic(client.ProposalHandler, distribution.ProposalHandler),
vpn.AppModuleBasic{},
)
moduleAccountPermissions = map[string][]string{
auth.FeeCollectorName: nil,
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
mint.ModuleName: {supply.Minter},
distribution.ModuleName: nil,
gov.ModuleName: {supply.Burner},
deposit.ModuleName: nil,
}
)
func MakeCodec() *codec.Codec {
var cdc = codec.New()
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
codec.RegisterEvidences(cdc)
ModuleBasics.RegisterCodec(cdc)
return cdc
}
type App struct {
*baseapp.BaseApp
cdc *codec.Codec
manager *module.Manager
keys map[string]*sdk.KVStoreKey
transientKeys map[string]*sdk.TransientStoreKey
paramsKeeper params.Keeper
accountKeeper auth.AccountKeeper
bankKeeper bank.Keeper
supplyKeeper supply.Keeper
stakingKeeper staking.Keeper
mintKeeper mint.Keeper
distributionKeeper distribution.Keeper
slashingKeeper slashing.Keeper
crisisKeeper crisis.Keeper
govKeeper gov.Keeper
vpnKeeper vpn.Keeper
}
func NewApp(logger log.Logger, db db.DB, tracer io.Writer, latest bool, invarCheckPeriod uint,
options ...func(*baseapp.BaseApp)) *App {
cdc := MakeCodec()
baseApp := baseapp.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), options...)
baseApp.SetCommitMultiStoreTracer(tracer)
baseApp.SetAppVersion(version.Version)
keys := sdk.NewKVStoreKeys(baseapp.MainStoreKey,
params.StoreKey, auth.StoreKey, supply.StoreKey, staking.StoreKey,
mint.StoreKey, distribution.StoreKey, slashing.StoreKey, gov.StoreKey,
vpn.StoreKey,
)
transientKeys := sdk.NewTransientStoreKeys(params.TStoreKey, staking.TStoreKey)
var app = &App{
BaseApp: baseApp,
cdc: cdc,
keys: keys,
transientKeys: transientKeys,
}
app.paramsKeeper = params.NewKeeper(app.cdc,
keys[params.StoreKey],
transientKeys[params.TStoreKey],
params.DefaultCodespace)
authSubspace := app.paramsKeeper.Subspace(auth.DefaultParamspace)
bankSubspace := app.paramsKeeper.Subspace(bank.DefaultParamspace)
stakingSubspace := app.paramsKeeper.Subspace(staking.DefaultParamspace)
mintSubspace := app.paramsKeeper.Subspace(mint.DefaultParamspace)
distributionSubspace := app.paramsKeeper.Subspace(distribution.DefaultParamspace)
slashingSubspace := app.paramsKeeper.Subspace(slashing.DefaultParamspace)
crisisSubspace := app.paramsKeeper.Subspace(crisis.DefaultParamspace)
govSubspace := app.paramsKeeper.Subspace(gov.DefaultParamspace)
app.accountKeeper = auth.NewAccountKeeper(app.cdc,
keys[auth.StoreKey],
authSubspace,
auth.ProtoBaseAccount)
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper,
bankSubspace,
bank.DefaultCodespace,
app.ModuleAccountAddresses())
app.supplyKeeper = supply.NewKeeper(app.cdc,
keys[supply.StoreKey],
app.accountKeeper,
app.bankKeeper,
moduleAccountPermissions)
stakingKeeper := staking.NewKeeper(app.cdc,
keys[staking.StoreKey],
transientKeys[staking.TStoreKey],
app.supplyKeeper,
stakingSubspace,
staking.DefaultCodespace)
app.mintKeeper = mint.NewKeeper(app.cdc,
keys[mint.StoreKey],
mintSubspace,
&stakingKeeper,
app.supplyKeeper,
auth.FeeCollectorName)
app.distributionKeeper = distribution.NewKeeper(app.cdc,
keys[distribution.StoreKey],
distributionSubspace,
&stakingKeeper,
app.supplyKeeper,
distribution.DefaultCodespace,
auth.FeeCollectorName,
app.ModuleAccountAddresses())
app.slashingKeeper = slashing.NewKeeper(app.cdc,
keys[slashing.StoreKey],
&stakingKeeper,
slashingSubspace,
slashing.DefaultCodespace)
app.crisisKeeper = crisis.NewKeeper(crisisSubspace,
invarCheckPeriod,
app.supplyKeeper,
auth.FeeCollectorName)
govRouter := gov.NewRouter()
govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler).
AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper)).
AddRoute(distribution.RouterKey, distribution.NewCommunityPoolSpendProposalHandler(app.distributionKeeper))
app.govKeeper = gov.NewKeeper(app.cdc,
keys[gov.StoreKey],
app.paramsKeeper,
govSubspace,
app.supplyKeeper,
&stakingKeeper,
gov.DefaultCodespace,
govRouter)
app.stakingKeeper = *stakingKeeper.SetHooks(
staking.NewMultiStakingHooks(app.distributionKeeper.Hooks(), app.slashingKeeper.Hooks()))
app.vpnKeeper = vpn.NewKeeper(app.cdc,
keys[vpn.StoreKey],
app.paramsKeeper,
app.bankKeeper,
app.supplyKeeper)
app.manager = module.NewManager(
genaccounts.NewAppModule(app.accountKeeper),
genutil.NewAppModule(app.accountKeeper, app.stakingKeeper, app.BaseApp.DeliverTx),
auth.NewAppModule(app.accountKeeper),
bank.NewAppModule(app.bankKeeper, app.accountKeeper),
supply.NewAppModule(app.supplyKeeper, app.accountKeeper),
staking.NewAppModule(app.stakingKeeper, app.distributionKeeper, app.accountKeeper, app.supplyKeeper),
mint.NewAppModule(app.mintKeeper),
distribution.NewAppModule(app.distributionKeeper, app.supplyKeeper),
slashing.NewAppModule(app.slashingKeeper, app.stakingKeeper),
crisis.NewAppModule(&app.crisisKeeper),
gov.NewAppModule(app.govKeeper, app.supplyKeeper),
vpn.NewAppModule(app.vpnKeeper),
)
// NOTE: order is very important here
app.manager.SetOrderBeginBlockers(mint.ModuleName, distribution.ModuleName, slashing.ModuleName, vpn.ModuleName)
app.manager.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName)
app.manager.SetOrderInitGenesis(
genaccounts.ModuleName, distribution.ModuleName, staking.ModuleName, auth.ModuleName,
bank.ModuleName, slashing.ModuleName, gov.ModuleName, mint.ModuleName,
supply.ModuleName, crisis.ModuleName, genutil.ModuleName, vpn.ModuleName,
)
app.manager.RegisterInvariants(&app.crisisKeeper)
app.manager.RegisterRoutes(app.Router(), app.QueryRouter())
app.MountKVStores(keys)
app.MountTransientStores(transientKeys)
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(auth.NewAnteHandler(app.accountKeeper, app.supplyKeeper, auth.DefaultSigVerificationGasConsumer))
app.SetEndBlocker(app.EndBlocker)
if latest {
if err := app.LoadLatestVersion(app.keys[baseapp.MainStoreKey]); err != nil {
common.Exit(err.Error())
}
}
return app
}
func (a *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return a.manager.BeginBlock(ctx, req)
}
func (a *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return a.manager.EndBlock(ctx, req)
}
func (a *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var state map[string]json.RawMessage
a.cdc.MustUnmarshalJSON(req.AppStateBytes, &state)
return a.manager.InitGenesis(ctx, state)
}
func (a *App) LoadHeight(height int64) error {
return a.LoadVersion(height, a.keys[baseapp.MainStoreKey])
}
func (a *App) ModuleAccountAddresses() map[string]bool {
accounts := make(map[string]bool)
for name := range moduleAccountPermissions {
accounts[supply.NewModuleAddress(name).String()] = true
}
return accounts
}