mirror of
https://github.com/arnaucube/goBlockchainDataAnalysis.git
synced 2026-02-07 03:36:44 +01:00
fixed blockchain explore and generation of nodes and edges
This commit is contained in:
@@ -1,2 +1,11 @@
|
|||||||
# goBlockchainDataAnalysis
|
# goBlockchainDataAnalysis
|
||||||
blockchain data analysis, written in Go
|
blockchain data analysis, written in Go
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
- First run explorer
|
||||||
|
```
|
||||||
|
./goBlockchainDataAnalysis -explore
|
||||||
|
```
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"gopkg.in/mgo.v2/bson"
|
"gopkg.in/mgo.v2/bson"
|
||||||
|
|
||||||
@@ -46,6 +47,21 @@ func explore(client *btcrpcclient.Client, blockHash string) {
|
|||||||
|
|
||||||
var originAddresses []string
|
var originAddresses []string
|
||||||
var outputAddresses []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 {
|
for _, Vi := range tx.Vin {
|
||||||
th, err := chainhash.NewHashFromStr(Vi.Txid)
|
th, err := chainhash.NewHashFromStr(Vi.Txid)
|
||||||
check(err)
|
check(err)
|
||||||
@@ -62,39 +78,24 @@ func explore(client *btcrpcclient.Client, blockHash string) {
|
|||||||
n1.Value = 1
|
n1.Value = 1
|
||||||
n1.Shape = "dot"
|
n1.Shape = "dot"
|
||||||
saveNode(nodeCollection, n1)
|
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 {
|
} else {
|
||||||
originAddresses = append(originAddresses, "origin")
|
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.Print("originAddresses: ")
|
||||||
fmt.Println(len(originAddresses))
|
fmt.Println(len(originAddresses))
|
||||||
fmt.Print("outputAddresses: ")
|
fmt.Print("outputAddresses: ")
|
||||||
|
|||||||
@@ -74,16 +74,17 @@ func getAllNodes() ([]NodeModel, error) {
|
|||||||
func saveNode(c *mgo.Collection, node NodeModel) {
|
func saveNode(c *mgo.Collection, node NodeModel) {
|
||||||
//first, check if the node already exists
|
//first, check if the node already exists
|
||||||
result := NodeModel{}
|
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 {
|
if err != nil {
|
||||||
//node not found, so let's add a new entry
|
//node not found, so let's add a new entry
|
||||||
err = c.Insert(node)
|
err = c.Insert(node)
|
||||||
check(err)
|
check(err)
|
||||||
} else {
|
} 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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user