arnaucube
arnaucube/goBlockchainDataAnalysisPublic Self-hosted repository
fixed blockchain explore and generation of nodes and edges
arnaucode idoctnef@openmailbox.org
Thu, 27 Jul 2017 15:21:23 +0200
commit

efb763eb46eae0943c59e677e2a3f7d3325d8cd2

parent

f9262f72a11182c75f708022929a28ebc8d4002a

3 files changed, 40 insertions(+), 29 deletions(-)

jump to
M README.md → README.md

@@ -1,2 +1,11 @@

# goBlockchainDataAnalysis blockchain data analysis, written in Go + + + +## Run + +- First run explorer +``` +./goBlockchainDataAnalysis -explore +```
M exploreBlockchain.go → exploreBlockchain.go

@@ -2,6 +2,7 @@ package main

import ( "fmt" + "strconv" "gopkg.in/mgo.v2/bson"

@@ -46,6 +47,21 @@ check(err)

var originAddresses []string var outputAddresses []string + for _, Vo := range tx.Vout { + //if Vo.Value > 0 { + for _, outputAddr := range Vo.ScriptPubKey.Addresses { + outputAddresses = append(outputAddresses, outputAddr) + var n2 NodeModel + n2.Id = outputAddr + n2.Label = outputAddr + n2.Title = outputAddr + n2.Group = strconv.FormatInt(block.Height, 10) + n2.Value = 1 + n2.Shape = "dot" + saveNode(nodeCollection, n2) + } + //} + } for _, Vi := range tx.Vin { th, err := chainhash.NewHashFromStr(Vi.Txid) check(err)

@@ -62,38 +78,23 @@ n1.Group = string(block.Height)

n1.Value = 1 n1.Shape = "dot" saveNode(nodeCollection, n1) + + for _, outputAddr := range outputAddresses { + var e EdgeModel + e.From = originAddr + e.To = outputAddr + e.Label = txVi.Vout[Vi.Vout].Value + e.Txid = tx.Txid + e.Arrows = "to" + e.BlockHeight = block.Height + saveEdge(edgeCollection, e) + //fmt.Println(e) + } } } else { originAddresses = append(originAddresses, "origin") } - } - for _, Vo := range tx.Vout { - //if Vo.Value > 0 { - for _, outputAddr := range Vo.ScriptPubKey.Addresses { - outputAddresses = append(outputAddresses, outputAddr) - var n2 NodeModel - n2.Id = outputAddr - n2.Label = outputAddr - n2.Title = outputAddr - n2.Group = string(block.Height) - n2.Value = 1 - n2.Shape = "dot" - saveNode(nodeCollection, n2) - - for _, originAddr := range originAddresses { - var e EdgeModel - e.From = originAddr - e.To = outputAddr - e.Label = Vo.Value - e.Txid = tx.Txid - e.Arrows = "to" - e.BlockHeight = block.Height - saveEdge(edgeCollection, e) - //fmt.Println(e) - } - } - //} } fmt.Print("originAddresses: ") fmt.Println(len(originAddresses))
M mongoOperations.go → mongoOperations.go

@@ -74,16 +74,17 @@

func saveNode(c *mgo.Collection, node NodeModel) { //first, check if the node already exists result := NodeModel{} - err := c.Find(bson.M{"id": node.Id, "group": node.Group}).One(&result) + err := c.Find(bson.M{"id": node.Id}).One(&result) if err != nil { //node not found, so let's add a new entry err = c.Insert(node) check(err) } else { - err = c.Update(bson.M{"id": node.Id, "group": node.Group}, &node) + /*err = c.Update(bson.M{"id": node.Id}, &node) if err != nil { log.Fatal(err) } + */ } }