goBlockchainDataAnalysis/main.go
main.goRaw
1package main
2
3import (
4 "log"
5
6 "github.com/btcsuite/btcrpcclient"
7)
8
9func main() {
10
11 readConfig("config.json")
12
13 // create new client instance
14 client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{
15 HTTPPostMode: true,
16 DisableTLS: true,
17 Host: config.Host + ":" + config.Port,
18 User: config.User,
19 Pass: config.Pass,
20 }, nil)
21 if err != nil {
22 log.Fatalf("error creating new btc client: %v", err)
23 }
24
25 // list accounts
26 accounts, err := client.ListAccounts()
27 if err != nil {
28 log.Fatalf("error listing accounts: %v", err)
29 }
30 // iterate over accounts (map[string]btcutil.Amount) and write to stdout
31 for label, amount := range accounts {
32 log.Printf("%s: %s", label, amount)
33 }
34
35 explore(client, config.GenesisBlock)
36
37 // Get the current block count.
38 blockCount, err := client.GetBlockCount()
39 if err != nil {
40 log.Fatal(err)
41 }
42 log.Printf("Block count: %d", blockCount)
43}