forked from irisnet/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
95 lines (75 loc) · 2.34 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
package app
import (
"fmt"
"os"
bam "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/abci/server"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-wire"
cmn "github.com/tendermint/tmlibs/common"
)
const appName = "BasecoinApp"
// BasecoinApp - extended ABCI application
type BasecoinApp struct {
*bam.BaseApp
router bam.Router
cdc *wire.Codec
multiStore sdk.CommitMultiStore //TODO distinguish this store from *bam.BaseApp.cms <- is this one master?? confused
// The key to access the substores.
capKeyMainStore *sdk.KVStoreKey
capKeyIBCStore *sdk.KVStoreKey
// Object mappers:
accountMapper sdk.AccountMapper
}
// NewBasecoinApp - create new BasecoinApp
// TODO: This should take in more configuration options.
// TODO: This should be moved into baseapp to isolate complexity
func NewBasecoinApp(genesisPath string) *BasecoinApp {
// Create and configure app.
var app = &BasecoinApp{}
// TODO open up out of functions, or introduce clarity,
// interdependancies are a nightmare to debug
app.initCapKeys() // ./init_capkeys.go
app.initBaseApp() // ./init_baseapp.go
app.initStores() // ./init_stores.go
app.initBaseAppInitStater()
app.initHandlers() // ./init_handlers.go
genesisiDoc, err := bam.GenesisDocFromFile(genesisPath)
if err != nil {
panic(fmt.Errorf("error loading genesis state: %v", err))
}
// set up the cache store for ctx, get ctx
// TODO: can InitChain handle this too ?
app.BaseApp.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{}})
ctx := app.BaseApp.NewContext(false, nil) // context for DeliverTx
// TODO: combine with InitChain and let tendermint invoke it.
err = app.BaseApp.InitStater(ctx, genesisiDoc.AppState)
if err != nil {
panic(fmt.Errorf("error initializing application genesis state: %v", err))
}
app.loadStores()
return app
}
// RunForever - BasecoinApp execution and cleanup
func (app *BasecoinApp) RunForever() {
// Start the ABCI server
srv, err := server.NewServer("0.0.0.0:46658", "socket", app)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
srv.Start()
// Wait forever
cmn.TrapSignal(func() {
// Cleanup
srv.Stop()
})
}
// Load the stores
func (app *BasecoinApp) loadStores() {
if err := app.LoadLatestVersion(app.capKeyMainStore); err != nil {
fmt.Println(err)
os.Exit(1)
}
}