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