You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

  1. package main
  2. import (
  3. "log"
  4. mgo "gopkg.in/mgo.v2"
  5. "github.com/btcsuite/btcrpcclient"
  6. )
  7. var blockCollection *mgo.Collection
  8. func main() {
  9. //read goBlockchainDataAbalysis config
  10. readConfig("config.json")
  11. //connect with mongodb
  12. readMongodbConfig("./mongodbConfig.json")
  13. session, err := getSession()
  14. check(err)
  15. blockCollection = getCollection(session, "blocks")
  16. // create new client instance
  17. client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{
  18. HTTPPostMode: true,
  19. DisableTLS: true,
  20. Host: config.Host + ":" + config.Port,
  21. User: config.User,
  22. Pass: config.Pass,
  23. }, nil)
  24. if err != nil {
  25. log.Fatalf("error creating new btc client: %v", err)
  26. }
  27. // list accounts
  28. accounts, err := client.ListAccounts()
  29. if err != nil {
  30. log.Fatalf("error listing accounts: %v", err)
  31. }
  32. // iterate over accounts (map[string]btcutil.Amount) and write to stdout
  33. for label, amount := range accounts {
  34. log.Printf("%s: %s", label, amount)
  35. }
  36. explore(client, config.GenesisBlock)
  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. }