goBlockchainDataAnalysis/main.go
main.goRaw
1package main
2
3import (
4 "fmt"
5 "log"
6 "net/http"
7 "os"
8
9 mgo "gopkg.in/mgo.v2"
10
11 "github.com/btcsuite/btcrpcclient"
12 "github.com/fatih/color"
13)
14
15var blockCollection *mgo.Collection
16var nodeCollection *mgo.Collection
17var edgeCollection *mgo.Collection
18
19func main() {
20 //read goBlockchainDataAbalysis config
21 readConfig("config.json")
22
23 //connect with mongodb
24 readMongodbConfig("./mongodbConfig.json")
25 session, err := getSession()
26 check(err)
27 blockCollection = getCollection(session, "blocks")
28 nodeCollection = getCollection(session, "nodes")
29 edgeCollection = getCollection(session, "edges")
30
31 // create new client instance
32 client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{
33 HTTPPostMode: true,
34 DisableTLS: true,
35 Host: config.Host + ":" + config.Port,
36 User: config.User,
37 Pass: config.Pass,
38 }, nil)
39 if err != nil {
40 log.Fatalf("error creating new btc client: %v", err)
41 }
42
43 // list accounts
44 accounts, err := client.ListAccounts()
45 if err != nil {
46 log.Fatalf("error listing accounts: %v", err)
47 }
48 // iterate over accounts (map[string]btcutil.Amount) and write to stdout
49 for label, amount := range accounts {
50 log.Printf("%s: %s", label, amount)
51 }
52 if len(os.Args) > 1 {
53 if os.Args[1] == "-explore" {
54 fmt.Println("starting to explore blockchain")
55 explore(client, config.GenesisBlock)
56 }
57 }
58
59 // Get the current block count.
60 blockCount, err := client.GetBlockCount()
61 if err != nil {
62 log.Fatal(err)
63 }
64 log.Printf("Block count: %d", blockCount)
65
66 //http server start
67 readServerConfig("./serverConfig.json")
68 color.Green("server running")
69 router := NewRouter()
70 log.Fatal(http.ListenAndServe(":"+serverConfig.ServerPort, router))
71
72}