-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapp.go
195 lines (169 loc) · 5.05 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
package simapp
import (
_ "embed"
"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"
_ "cosmossdk.io/x/upgrade"
_ "github.com/cosmos/cosmos-sdk/x/auth"
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
_ "github.com/cosmos/cosmos-sdk/x/bank"
_ "github.com/cosmos/cosmos-sdk/x/consensus"
_ "github.com/cosmos/cosmos-sdk/x/params"
_ "github.com/cosmos/cosmos-sdk/x/staking"
_ "github.com/ondoprotocol/usdy-noble/v2"
// Cosmos Modules
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/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"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
// IBC Modules
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
transferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
// Custom Modules
aurakeeper "github.com/ondoprotocol/usdy-noble/v2/keeper"
)
var DefaultNodeHome string
//go:embed app.yaml
var AppConfigYAML []byte
var (
_ runtime.AppI = (*SimApp)(nil)
_ servertypes.Application = (*SimApp)(nil)
)
// SimApp extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
type SimApp struct {
*runtime.App
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry codectypes.InterfaceRegistry
// Cosmos Modules
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
ConsensusKeeper consensuskeeper.Keeper
ParamsKeeper paramskeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
// IBC Modules
CapabilityKeeper *capabilitykeeper.Keeper
IBCKeeper *ibckeeper.Keeper
TransferKeeper transferkeeper.Keeper
// Custom Modules
AuraKeeper *aurakeeper.Keeper
}
func init() {
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
DefaultNodeHome = filepath.Join(userHomeDir, ".simapp")
}
// 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),
},
),
)
}
// NewSimApp returns a reference to an initialized SimApp.
func NewSimApp(
logger log.Logger,
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) (*SimApp, error) {
var (
app = &SimApp{}
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.BankKeeper,
&app.ConsensusKeeper,
&app.ParamsKeeper,
&app.StakingKeeper,
&app.UpgradeKeeper,
// Custom Modules
&app.AuraKeeper,
); err != nil {
return nil, err
}
app.App = appBuilder.Build(db, traceStore, baseAppOptions...)
if err := app.RegisterLegacyModules(); 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 *SimApp) LegacyAmino() *codec.LegacyAmino {
return app.legacyAmino
}
func (app *SimApp) SimulationManager() *module.SimulationManager {
return nil
}
func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey {
key, _ := app.UnsafeFindStoreKey(storeKey).(*storetypes.KVStoreKey)
return key
}
func (app *SimApp) GetMemKey(memKey string) *storetypes.MemoryStoreKey {
key, _ := app.UnsafeFindStoreKey(memKey).(*storetypes.MemoryStoreKey)
return key
}
func (app *SimApp) GetSubspace(moduleName string) paramstypes.Subspace {
subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
return subspace
}
func (app *SimApp) 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
}