-
Notifications
You must be signed in to change notification settings - Fork 7
/
testapp.go
111 lines (85 loc) · 2.64 KB
/
testapp.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
package app
import (
"fmt"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
bapp "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/go-amino"
"github.com/sharering/shareledger/constants"
"github.com/sharering/shareledger/x/auth"
"github.com/sharering/shareledger/x/bank"
)
type TestShareLedgerApp struct {
*bapp.BaseApp
cdc *amino.Codec
// keys to access the substores
// bankKey *sdk.KVStoreKey
//accountKey *sdk.KVStoreKey
//keepers
bankKeeper bank.Keeper
// Manage getting and setting accounts
accountMapper auth.AccountMapper
}
func NewTestShareLedgerApp(logger log.Logger, db dbm.DB) *TestShareLedgerApp {
cdc := MakeCodec()
// Create the base application object.
baseApp := bapp.NewBaseApp(appName, logger, db, auth.GetTxDecoder(cdc))
authKey := sdk.NewKVStoreKey(constants.STORE_AUTH)
//bankKey := sdk.NewKVStoreKey(constants.STORE_BANK)
// Mount Store
baseApp.MountStores(authKey)
err := baseApp.LoadLatestVersion(authKey)
if err != nil {
cmn.Exit(err.Error())
}
// accountMapper for Auth Module storing and Bank module
accountMapper := auth.NewAccountMapper(
cdc,
authKey,
&auth.SHRAccount{},
)
// Determine how transactions are decoded.
//baseApp.SetTxDecoder(types.GetTxDecoder(cdc))
app := &TestShareLedgerApp{
BaseApp: baseApp,
cdc: cdc,
//accountKey: accountKey,
accountMapper: accountMapper,
}
//app.SetTxDecoder(auth.GetTxDecoder(cdc))
app.SetAnteHandler(auth.NewAnteHandler(accountMapper))
// app.Router().
// AddRoute(constants.MESSAGE_AUTH, auth.NewHandler(accountMapper))
app.cdc = auth.RegisterCodec(app.cdc)
app.SetupBank(accountMapper)
// Set Tx Fee Calculation
// app.SetFeeHandler(fee.NewFeeHandler(accountMapper, exchangeKey))
// Register InitChain
// logger.Info("Register Init Chainer")
// app.SetInitChainer(app.InitChainer)
// app.SetEndBlocker(EndBlocker(accountMapper, app.posKeeper))
// app.SetBeginBlocker(BeginBlocker)
return app
}
func (app *TestShareLedgerApp) SetupBank(am auth.AccountMapper) {
// Bank module
// Create a key for accessing the account store.
app.cdc = bank.RegisterCodec(app.cdc)
app.bankKeeper = bank.NewKeeper(am /*, cdc*/)
// Register message routes.
// Note the handler gets access to the account store.
// app.Router().
// AddRoute("bank", bank.NewHandler(am))
app.Router().
AddRoute("test", GetHandler())
}
func GetHandler() sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
fmt.Printf("Handler for Msg: %v\n", msg)
return sdk.Result{
Log: "Testing",
}
}
}