mirror of
https://github.com/arnaucube/goBlockchainDataAnalysis.git
synced 2026-02-06 19:26:41 +01:00
added continuous block exploration each minute
This commit is contained in:
39
continuousTasks.go
Normal file
39
continuousTasks.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
|
"gopkg.in/mgo.v2/bson"
|
||||||
|
)
|
||||||
|
|
||||||
|
func explorationContinue() {
|
||||||
|
// create new client instance
|
||||||
|
client, err := rpcclient.New(&rpcclient.ConnConfig{
|
||||||
|
HTTPPostMode: true,
|
||||||
|
DisableTLS: true,
|
||||||
|
Host: config.Host + ":" + config.Port,
|
||||||
|
User: config.User,
|
||||||
|
Pass: config.Pass,
|
||||||
|
}, nil)
|
||||||
|
check(err)
|
||||||
|
//get last block stored in mongodb
|
||||||
|
lastBlock := BlockModel{}
|
||||||
|
err = blockCollection.Find(bson.M{}).Sort("-$natural").One(&lastBlock)
|
||||||
|
check(err)
|
||||||
|
log.Println("Getting last block stored in MongoDB. Hash: " + string(lastBlock.Hash) + ", BlockHeight: " + strconv.FormatInt(lastBlock.Height, 10))
|
||||||
|
log.Println("continuing blockchain exploration since last block in mongodb")
|
||||||
|
start := time.Now()
|
||||||
|
explore(client, string(lastBlock.Hash))
|
||||||
|
log.Println("blockchain exploration finished, time:")
|
||||||
|
log.Println(time.Since(start))
|
||||||
|
}
|
||||||
|
|
||||||
|
func continuousExploration() {
|
||||||
|
for {
|
||||||
|
explorationContinue()
|
||||||
|
time.Sleep(time.Second * 60)
|
||||||
|
}
|
||||||
|
}
|
||||||
23
main.go
23
main.go
@@ -4,11 +4,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
mgo "gopkg.in/mgo.v2"
|
mgo "gopkg.in/mgo.v2"
|
||||||
"gopkg.in/mgo.v2/bson"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
@@ -78,27 +76,10 @@ func main() {
|
|||||||
log.Printf("Block count: %d", blockCount)
|
log.Printf("Block count: %d", blockCount)
|
||||||
}
|
}
|
||||||
if os.Args[1] == "-continue" {
|
if os.Args[1] == "-continue" {
|
||||||
// create new client instance
|
explorationContinue()
|
||||||
client, err := rpcclient.New(&rpcclient.ConnConfig{
|
|
||||||
HTTPPostMode: true,
|
|
||||||
DisableTLS: true,
|
|
||||||
Host: config.Host + ":" + config.Port,
|
|
||||||
User: config.User,
|
|
||||||
Pass: config.Pass,
|
|
||||||
}, nil)
|
|
||||||
check(err)
|
|
||||||
//get last block stored in mongodb
|
|
||||||
lastBlock := BlockModel{}
|
|
||||||
err = blockCollection.Find(bson.M{}).Sort("-$natural").One(&lastBlock)
|
|
||||||
check(err)
|
|
||||||
log.Println("Getting last block stored in MongoDB. Hash: " + string(lastBlock.Hash) + ", BlockHeight: " + strconv.FormatInt(lastBlock.Height, 10))
|
|
||||||
log.Println("continuing blockchain exploration since last block in mongodb")
|
|
||||||
start := time.Now()
|
|
||||||
explore(client, string(lastBlock.Hash))
|
|
||||||
log.Println("blockchain exploration finished, time:")
|
|
||||||
log.Println(time.Since(start))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
go continuousExploration()
|
||||||
//run thw webserver
|
//run thw webserver
|
||||||
go webserver()
|
go webserver()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user