Browse Source

finished generation of network map of address history (back in blockchain)

master
arnaucode 7 years ago
parent
commit
7d36e363ec
3 changed files with 65 additions and 40 deletions
  1. +57
    -0
      addressTree.go
  2. +0
    -40
      exploreBlockchain.go
  3. +8
    -0
      mongoOperations.go

+ 57
- 0
addressTree.go

@ -0,0 +1,57 @@
package main
import (
"gopkg.in/mgo.v2/bson"
)
func upTree(address string, network NetworkModel) NetworkModel {
var upNetwork NetworkModel
//add address node to network
node := NodeModel{}
err := nodeCollection.Find(bson.M{"id": address}).One(&node)
check(err)
if nodeInNodes(network.Nodes, node) == false {
network.Nodes = append(network.Nodes, node)
}
//get edges before the address
edges := []EdgeModel{}
err = edgeCollection.Find(bson.M{"to": address}).All(&edges)
check(err)
for _, e := range edges {
if edgeInEdges(network.Edges, e) == false {
network.Edges = append(network.Edges, e)
}
//get the nodes involved in edges
/*
nodes := []NodeModel{}
err := nodeCollection.Find(bson.M{"id": }).All(&edges)
check(err)
*/
if e.From != e.To {
upNetwork = upTree(e.From, network)
for _, upN := range upNetwork.Nodes {
if nodeInNodes(network.Nodes, upN) == false {
network.Nodes = append(network.Nodes, upN)
}
}
for _, upE := range upNetwork.Edges {
if edgeInEdges(network.Edges, upE) == false {
network.Edges = append(network.Edges, upE)
}
}
}
}
return network
}
func addressTree(address string) NetworkModel {
var network NetworkModel
network = upTree(address, network)
return network
}

+ 0
- 40
exploreBlockchain.go

@ -4,11 +4,8 @@ import (
"fmt"
"strconv"
"gopkg.in/mgo.v2/bson"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcrpcclient"
"github.com/fatih/color"
)
func explore(client *btcrpcclient.Client, blockHash string) {
@ -111,40 +108,3 @@ func explore(client *btcrpcclient.Client, blockHash string) {
fmt.Println(realBlocks)
fmt.Println("reached the end of blockchain")
}
func addressTree(address string) NetworkModel {
var network NetworkModel
var currentEdge EdgeModel
currentEdge.From = "a"
currentEdge.To = "b"
for currentEdge.From != currentEdge.To {
color.Green("for")
fmt.Println(address)
//get edges before the address
edges := []EdgeModel{}
err := edgeCollection.Find(bson.M{"to": address}).All(&edges)
check(err)
for _, edge := range edges {
network.Edges = append(network.Edges, edge)
fmt.Println(edge)
}
//get all nodes from edges
for _, edge := range edges {
node := NodeModel{}
err := nodeCollection.Find(bson.M{"id": edge.From}).One(&node)
check(err)
if nodeInNodes(network.Nodes, node) == false {
network.Nodes = append(network.Nodes, node)
}
err = nodeCollection.Find(bson.M{"id": edge.To}).One(&node)
check(err)
if nodeInNodes(network.Nodes, node) == false {
network.Nodes = append(network.Nodes, node)
}
}
address = edges[0].From
currentEdge = edges[0]
}
return network
}

+ 8
- 0
mongoOperations.go

@ -118,3 +118,11 @@ func nodeInNodes(nodes []NodeModel, node NodeModel) bool {
}
return false
}
func edgeInEdges(edges []EdgeModel, edge EdgeModel) bool {
for _, e := range edges {
if e.From == edge.From && e.To == edge.To {
return true
}
}
return false
}

Loading…
Cancel
Save