-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.go
128 lines (100 loc) · 3.24 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
package app
import (
"github.com/WeTrustPlatform/cosmos-trstchain/x/multisigservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/tendermint/tendermint/libs/log"
bam "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
)
const (
appName = "trstchain"
)
// TRSTChainApp defines all the parameters needed for the app
type TRSTChainApp struct {
*bam.BaseApp
cdc *codec.Codec
// sdk keepers
// AccountKeeper handles address -> account lookups
keyAccount *sdk.KVStoreKey
accountKeeper auth.AccountKeeper
// FeeCollectionKeeper collects transaction fees and renders them to the fee distribution module
keyFeeCollection *sdk.KVStoreKey
feeCollectionKeeper auth.FeeCollectionKeeper
// ParamsKeeper handles parameter storage for the application
keyParams *sdk.KVStoreKey
tkeyParams *sdk.TransientStoreKey
paramsKeeper params.Keeper
// CoinKeeper allows you perform sdk.Coins interactions
coinKeeper bank.Keeper
// app-specific keepers
keyMain *sdk.KVStoreKey
// MultisigServiceKeeper stores multsig wallets info
keyMultisigService *sdk.KVStoreKey
multisigServiceKeeper multisigservice.Keeper
}
// NewTRSTChainApp creates new instances of TRSTChain
func NewTRSTChainApp(logger log.Logger, db dbm.DB) *TRSTChainApp {
cdc := MakeCodec()
bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc))
var app = &TRSTChainApp{
BaseApp: bApp,
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyMultisigService: sdk.NewKVStoreKey("multisig_service"),
keyAccount: sdk.NewKVStoreKey("account"),
keyFeeCollection: sdk.NewKVStoreKey("fee_collection"),
keyParams: sdk.NewKVStoreKey("params"),
tkeyParams: sdk.NewTransientStoreKey("transient_params"),
}
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
app.accountKeeper = auth.NewAccountKeeper(
app.cdc,
app.keyAccount,
app.paramsKeeper.Subspace(auth.DefaultParamspace),
auth.ProtoBaseAccount,
)
app.coinKeeper = bank.NewBaseKeeper(
app.accountKeeper,
app.paramsKeeper.Subspace(bank.DefaultParamspace),
bank.DefaultCodespace,
)
app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(cdc, app.keyFeeCollection)
app.multisigServiceKeeper = multisigservice.NewKeeper(
app.cdc,
app.coinKeeper,
app.accountKeeper,
app.keyMultisigService,
)
// The AnteHandler handles signature verification and transaction pre-processing
app.SetAnteHandler(auth.NewAnteHandler(app.accountKeeper, app.feeCollectionKeeper))
app.setUpRouter()
app.SetInitChainer(app.initChainer)
app.MountStores(
app.keyMain,
app.keyMultisigService,
app.keyAccount,
app.keyFeeCollection,
app.keyParams,
app.tkeyParams,
)
err := app.LoadLatestVersion(app.keyMain)
if err != nil {
cmn.Exit(err.Error())
}
return app
}
// MakeCodec generates the necessary codecs for Amino
func MakeCodec() *codec.Codec {
var cdc = codec.New()
auth.RegisterCodec(cdc)
bank.RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
multisigservice.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
return cdc
}