-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmint.go
56 lines (44 loc) · 1.05 KB
/
mint.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
package main
import (
"mint/jsonstore"
"os"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
mgo "gopkg.in/mgo.v2"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"
)
func main() {
initJSONStore()
}
func initJSONStore() error {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
// Create the application
var app types.Application
session, err := mgo.Dial("localhost")
if err != nil {
panic(err)
}
db := session.DB("tendermintdb")
// Clean the DB on each reboot
collections := [5]string{"posts", "comments", "users", "userpostvotes", "usercommentvotes"}
for _, collection := range collections {
db.C(collection).RemoveAll(nil)
}
app = jsonstore.NewJSONStoreApplication(db)
// Start the listener
srv, err := server.NewServer("tcp://0.0.0.0:46658", "socket", app)
if err != nil {
return err
}
srv.SetLogger(logger.With("module", "abci-server"))
if err := srv.Start(); err != nil {
return err
}
// Wait forever
cmn.TrapSignal(func() {
// Cleanup
srv.Stop()
})
return nil
}