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.

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