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.

72 lines
1.7 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "os"
  7. mgo "gopkg.in/mgo.v2"
  8. "github.com/btcsuite/btcrpcclient"
  9. "github.com/fatih/color"
  10. )
  11. var blockCollection *mgo.Collection
  12. var nodeCollection *mgo.Collection
  13. var edgeCollection *mgo.Collection
  14. func main() {
  15. //read goBlockchainDataAbalysis config
  16. readConfig("config.json")
  17. //connect with mongodb
  18. readMongodbConfig("./mongodbConfig.json")
  19. session, err := getSession()
  20. check(err)
  21. blockCollection = getCollection(session, "blocks")
  22. nodeCollection = getCollection(session, "nodes")
  23. edgeCollection = getCollection(session, "edges")
  24. // create new client instance
  25. client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{
  26. HTTPPostMode: true,
  27. DisableTLS: true,
  28. Host: config.Host + ":" + config.Port,
  29. User: config.User,
  30. Pass: config.Pass,
  31. }, nil)
  32. if err != nil {
  33. log.Fatalf("error creating new btc client: %v", err)
  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. if len(os.Args) > 1 {
  45. if os.Args[1] == "-explore" {
  46. fmt.Println("starting to explore blockchain")
  47. explore(client, config.GenesisBlock)
  48. }
  49. }
  50. // Get the current block count.
  51. blockCount, err := client.GetBlockCount()
  52. if err != nil {
  53. log.Fatal(err)
  54. }
  55. log.Printf("Block count: %d", blockCount)
  56. //http server start
  57. readServerConfig("./serverConfig.json")
  58. color.Green("server running")
  59. router := NewRouter()
  60. log.Fatal(http.ListenAndServe(":"+serverConfig.ServerPort, router))
  61. }