arnaucube
arnaucube/goBlockchainDataAnalysisPublic Self-hosted repository
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
12
13func main() {
14	//read goBlockchainDataAbalysis config
15	readConfig("config.json")
16
17	//connect with mongodb
18	readMongodbConfig("./mongodbConfig.json")
19	session, err := getSession()
20	check(err)
21	blockCollection = getCollection(session, "blocks")
22
23	// create new client instance
24	client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{
25		HTTPPostMode: true,
26		DisableTLS:   true,
27		Host:         config.Host + ":" + config.Port,
28		User:         config.User,
29		Pass:         config.Pass,
30	}, nil)
31	if err != nil {
32		log.Fatalf("error creating new btc client: %v", err)
33	}
34
35	// list accounts
36	accounts, err := client.ListAccounts()
37	if err != nil {
38		log.Fatalf("error listing accounts: %v", err)
39	}
40	// iterate over accounts (map[string]btcutil.Amount) and write to stdout
41	for label, amount := range accounts {
42		log.Printf("%s: %s", label, amount)
43	}
44
45	explore(client, config.GenesisBlock)
46
47	// Get the current block count.
48	blockCount, err := client.GetBlockCount()
49	if err != nil {
50		log.Fatal(err)
51	}
52	log.Printf("Block count: %d", blockCount)
53}