mirror of
https://github.com/arnaucube/goBlockchainDataAnalysis.git
synced 2026-02-07 11:46:38 +01:00
fixed blockchain explore and generation of nodes and edges
This commit is contained in:
@@ -1,2 +1,11 @@
|
||||
# goBlockchainDataAnalysis
|
||||
blockchain data analysis, written in Go
|
||||
|
||||
|
||||
|
||||
## Run
|
||||
|
||||
- First run explorer
|
||||
```
|
||||
./goBlockchainDataAnalysis -explore
|
||||
```
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
|
||||
@@ -46,6 +47,21 @@ func explore(client *btcrpcclient.Client, blockHash string) {
|
||||
|
||||
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,39 +78,24 @@ func explore(client *btcrpcclient.Client, blockHash string) {
|
||||
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))
|
||||
fmt.Print("outputAddresses: ")
|
||||
|
||||
@@ -74,16 +74,17 @@ func getAllNodes() ([]NodeModel, error) {
|
||||
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)
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user