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.

39 lines
1023 B

  1. package main
  2. import (
  3. "log"
  4. "strconv"
  5. "time"
  6. "github.com/btcsuite/btcd/rpcclient"
  7. "gopkg.in/mgo.v2/bson"
  8. )
  9. func explorationContinue() {
  10. // create new client instance
  11. client, err := rpcclient.New(&rpcclient.ConnConfig{
  12. HTTPPostMode: true,
  13. DisableTLS: true,
  14. Host: config.Host + ":" + config.Port,
  15. User: config.User,
  16. Pass: config.Pass,
  17. }, nil)
  18. check(err)
  19. //get last block stored in mongodb
  20. lastBlock := BlockModel{}
  21. err = blockCollection.Find(bson.M{}).Sort("-$natural").One(&lastBlock)
  22. check(err)
  23. log.Println("Getting last block stored in MongoDB. Hash: " + string(lastBlock.Hash) + ", BlockHeight: " + strconv.FormatInt(lastBlock.Height, 10))
  24. log.Println("continuing blockchain exploration since last block in mongodb")
  25. start := time.Now()
  26. explore(client, string(lastBlock.Hash))
  27. log.Println("blockchain exploration finished, time:")
  28. log.Println(time.Since(start))
  29. }
  30. func continuousExploration() {
  31. for {
  32. explorationContinue()
  33. time.Sleep(time.Second * 60)
  34. }
  35. }