-
Notifications
You must be signed in to change notification settings - Fork 47
/
app.go
348 lines (307 loc) · 9.9 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
// Copyright 2024 NASD Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package noble
import (
_ "embed"
"fmt"
"io"
"os"
"path/filepath"
"cosmossdk.io/core/appconfig"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/noble-assets/noble/v8/upgrade"
_ "cosmossdk.io/x/evidence"
_ "cosmossdk.io/x/feegrant/module"
_ "cosmossdk.io/x/upgrade"
_ "github.com/circlefin/noble-cctp/x/cctp"
_ "github.com/circlefin/noble-fiattokenfactory/x/fiattokenfactory"
_ "github.com/cosmos/cosmos-sdk/x/auth"
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting"
_ "github.com/cosmos/cosmos-sdk/x/authz/module"
_ "github.com/cosmos/cosmos-sdk/x/bank"
_ "github.com/cosmos/cosmos-sdk/x/consensus"
_ "github.com/cosmos/cosmos-sdk/x/crisis"
_ "github.com/cosmos/cosmos-sdk/x/params"
_ "github.com/cosmos/cosmos-sdk/x/slashing"
_ "github.com/cosmos/cosmos-sdk/x/staking"
_ "github.com/monerium/module-noble/v2"
_ "github.com/noble-assets/authority"
_ "github.com/noble-assets/forwarding/v2"
"github.com/noble-assets/globalfee"
_ "github.com/noble-assets/halo/v2"
_ "github.com/ondoprotocol/usdy-noble/v2"
// Cosmos Modules
evidencekeeper "cosmossdk.io/x/evidence/keeper"
feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
// IBC Modules
pfmkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
transferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
// Circle Modules
cctpkeeper "github.com/circlefin/noble-cctp/x/cctp/keeper"
ftfkeeper "github.com/circlefin/noble-fiattokenfactory/x/fiattokenfactory/keeper"
// Ondo Modules
aurakeeper "github.com/ondoprotocol/usdy-noble/v2/keeper"
// Hashnote Modules
halokeeper "github.com/noble-assets/halo/v2/keeper"
// Monerium Modules
florinkeeper "github.com/monerium/module-noble/v2/keeper"
// Noble Modules
authoritykeeper "github.com/noble-assets/authority/keeper"
forwardingkeeper "github.com/noble-assets/forwarding/v2/keeper"
globalfeekeeper "github.com/noble-assets/globalfee/keeper"
)
var DefaultNodeHome string
//go:embed app.yaml
var AppConfigYAML []byte
var (
_ runtime.AppI = (*App)(nil)
_ servertypes.Application = (*App)(nil)
)
// App defines the interface of Noble's Cosmos SDK-based application that extends the default ABCI interface.
type App struct {
*runtime.App
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry codectypes.InterfaceRegistry
// Cosmos Modules
AccountKeeper authkeeper.AccountKeeper
AuthzKeeper authzkeeper.Keeper
BankKeeper bankkeeper.Keeper
ConsensusKeeper consensuskeeper.Keeper
CrisisKeeper *crisiskeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
ParamsKeeper paramskeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
// IBC Modules
CapabilityKeeper *capabilitykeeper.Keeper
IBCKeeper *ibckeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
PFMKeeper *pfmkeeper.Keeper
TransferKeeper transferkeeper.Keeper
// Circle Modules
CCTPKeeper *cctpkeeper.Keeper
FTFKeeper *ftfkeeper.Keeper
// Ondo Modules
AuraKeeper *aurakeeper.Keeper
// Hashnote Modules
HaloKeeper *halokeeper.Keeper
// Monerium Modules
FlorinKeeper *florinkeeper.Keeper
// Noble Modules
AuthorityKeeper *authoritykeeper.Keeper
ForwardingKeeper *forwardingkeeper.Keeper
GlobalFeeKeeper *globalfeekeeper.Keeper
}
func init() {
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
DefaultNodeHome = filepath.Join(userHomeDir, ".noble")
}
// AppConfig returns the default app config.
func AppConfig() depinject.Config {
return depinject.Configs(
appconfig.LoadYAML(AppConfigYAML),
depinject.Supply(
// supply custom module basics
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
},
),
)
}
// NewApp initializes and returns a new Noble application.
func NewApp(
logger log.Logger,
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) (*App, error) {
var (
app = &App{}
appBuilder *runtime.AppBuilder
)
if err := depinject.Inject(
depinject.Configs(
AppConfig(),
depinject.Supply(
logger,
appOpts,
),
),
&appBuilder,
&app.appCodec,
&app.legacyAmino,
&app.txConfig,
&app.interfaceRegistry,
// Cosmos Modules
&app.AccountKeeper,
&app.AuthzKeeper,
&app.BankKeeper,
&app.ConsensusKeeper,
&app.CrisisKeeper,
&app.EvidenceKeeper,
&app.FeeGrantKeeper,
&app.ParamsKeeper,
&app.SlashingKeeper,
&app.StakingKeeper,
&app.UpgradeKeeper,
// Circle Modules
&app.CCTPKeeper,
&app.FTFKeeper,
// Hashnote Modules
&app.HaloKeeper,
// Monerium Modules
&app.FlorinKeeper,
// Ondo Modules
&app.AuraKeeper,
// Noble Modules
&app.AuthorityKeeper,
&app.ForwardingKeeper,
&app.GlobalFeeKeeper,
); err != nil {
return nil, err
}
app.App = appBuilder.Build(db, traceStore, baseAppOptions...)
if err := app.RegisterLegacyModules(); err != nil {
return nil, err
}
// When initializing the upgrade keeper via dependency injection, the
// initial module version map is created using only the modules that are
// wired through dependency injection. As a result, any "legacy" modules
// (those that don't support dependency injection) are excluded. The line
// below updates the version map to ensure that all modules are included.
app.UpgradeKeeper.SetInitVersionMap(app.ModuleManager.GetVersionMap())
anteHandler, err := NewAnteHandler(HandlerOptions{
HandlerOptions: ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
SignModeHandler: app.txConfig.SignModeHandler(),
TxFeeChecker: globalfee.TxFeeChecker(app.GlobalFeeKeeper),
},
cdc: app.appCodec,
FTFKeeper: app.FTFKeeper,
IBCKeeper: app.IBCKeeper,
})
if err != nil {
return nil, err
}
app.SetAnteHandler(anteHandler)
if err := app.RegisterUpgradeHandler(); err != nil {
return nil, err
}
if err := app.RegisterStreamingServices(appOpts, app.kvStoreKeys()); err != nil {
return nil, err
}
if err := app.Load(loadLatest); err != nil {
return nil, err
}
return app, nil
}
func (app *App) LegacyAmino() *codec.LegacyAmino {
return app.legacyAmino
}
func (app *App) SimulationManager() *module.SimulationManager {
return nil
}
//
func (app *App) GetKey(storeKey string) *storetypes.KVStoreKey {
key, _ := app.UnsafeFindStoreKey(storeKey).(*storetypes.KVStoreKey)
return key
}
func (app *App) GetMemKey(memKey string) *storetypes.MemoryStoreKey {
key, _ := app.UnsafeFindStoreKey(memKey).(*storetypes.MemoryStoreKey)
return key
}
func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
return subspace
}
func (app *App) RegisterUpgradeHandler() error {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
app.ModuleManager,
app.Configurator(),
app.appCodec,
app.interfaceRegistry,
app.Logger(),
app.GetKey(capabilitytypes.ModuleName),
app.AccountKeeper,
app.AuthorityKeeper,
app.BankKeeper,
app.CapabilityKeeper,
app.IBCKeeper.ClientKeeper,
app.ConsensusKeeper,
app.GlobalFeeKeeper,
app.ParamsKeeper,
app.StakingKeeper,
),
)
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
return fmt.Errorf("failed to read upgrade info from disk: %w", err)
}
if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return nil
}
if upgradeInfo.Name == upgrade.UpgradeName {
app.SetStoreLoader(upgrade.CreateStoreLoader(upgradeInfo.Height))
}
return nil
}
func (app *App) kvStoreKeys() map[string]*storetypes.KVStoreKey {
keys := make(map[string]*storetypes.KVStoreKey)
for _, k := range app.GetStoreKeys() {
if kv, ok := k.(*storetypes.KVStoreKey); ok {
keys[kv.Name()] = kv
}
}
return keys
}