diff --git a/DevelopmentNotes.md b/DevelopmentNotes.md index 97c8912..b2580d6 100644 --- a/DevelopmentNotes.md +++ b/DevelopmentNotes.md @@ -2,10 +2,7 @@ ## ToDo list -- Sankey generation without loops - - Backend - - Network Address generation avoiding infinite relation loops - Sankey Address generation without loops - Frontend - After Sankey visualization, go to Network Address visualization and render without Sankey dots @@ -31,3 +28,5 @@ other ``` - mantain connection with wallet using websockets + +- num address evolution throught time \ No newline at end of file diff --git a/addressTree.go b/addressTree.go index a3b454f..4901630 100644 --- a/addressTree.go +++ b/addressTree.go @@ -45,11 +45,7 @@ func upTree(address string, network NetworkModel) NetworkModel { //need to be fixed when there is a bucle between the addresses (A-->B, B-->C, C-->A) fmt.Println(e.From + " - " + e.To) - //if e.From != e.To && e.From != upLevelEdge.To && e.To != upLevelEdge.From { - //if e.From != e.To { - fmt.Println(endBranch) - fmt.Println(edgeInEdges(network.Edges, edgeUpCheck)) - if edgeInEdges(network.Edges, edgeUpCheck) == false && endBranch == false { + if edgeInEdges(network.Edges, edgeUpCheck) == false && endBranch == false && edgeUpCheck.BlockHeight <= e.BlockHeight && e.To != edgeUpCheck.From { upNetwork = upTree(e.From, network) for _, upN := range upNetwork.Nodes { if nodeInNodes(network.Nodes, upN) == false { diff --git a/exploreBlockchain.go b/exploreBlockchain.go index 5a2998a..be39c7c 100644 --- a/exploreBlockchain.go +++ b/exploreBlockchain.go @@ -5,10 +5,10 @@ import ( "strconv" "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/btcsuite/btcrpcclient" + "github.com/btcsuite/btcd/rpcclient" ) -func explore(client *btcrpcclient.Client, blockHash string) { +func explore(client *rpcclient.Client, blockHash string) { var realBlocks int /*var nOrigin NodeModel nOrigin.Id = "origin" @@ -39,9 +39,23 @@ func explore(client *btcrpcclient.Client, blockHash string) { newBlock.DateT = unixTimeToTime(block.Time) newBlock.Date.Year, newBlock.Date.Month, newBlock.Date.Day, newBlock.Date.Hour = decomposeDate(block.Time) + //stats blocks + stats := getStats() + stats.BlockCount++ + if len(block.Tx) > 1 { + stats.RealBlockCount++ + } + updateStats(stats) + for k, txHash := range block.Tx { if k > 0 { realBlocks++ + + //stats txs + stats := getStats() + stats.TxCount++ + updateStats(stats) + fmt.Print("Block Height: ") fmt.Print(block.Height) fmt.Print(", num of Tx: ") diff --git a/goBlockchainDataAnalysis b/goBlockchainDataAnalysis index 9042092..a6b9017 100755 Binary files a/goBlockchainDataAnalysis and b/goBlockchainDataAnalysis differ diff --git a/main.go b/main.go index 6311baa..cc49af5 100644 --- a/main.go +++ b/main.go @@ -10,10 +10,11 @@ import ( mgo "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" - "github.com/btcsuite/btcrpcclient" + "github.com/btcsuite/btcd/rpcclient" "github.com/gorilla/handlers" ) +var statsCollection *mgo.Collection var blockCollection *mgo.Collection var txCollection *mgo.Collection var addressCollection *mgo.Collection @@ -31,6 +32,7 @@ func main() { //readMongodbConfig("./mongodbConfig.json") session, err := getSession() check(err) + statsCollection = getCollection(session, "stats") blockCollection = getCollection(session, "blocks") txCollection = getCollection(session, "txs") addressCollection = getCollection(session, "address") @@ -42,7 +44,7 @@ func main() { if len(os.Args) > 1 { if os.Args[1] == "-explore" { // create new client instance - client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{ + client, err := rpcclient.New(&rpcclient.ConnConfig{ HTTPPostMode: true, DisableTLS: true, Host: config.Host + ":" + config.Port, @@ -77,7 +79,7 @@ func main() { } if os.Args[1] == "-continue" { // create new client instance - client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{ + client, err := rpcclient.New(&rpcclient.ConnConfig{ HTTPPostMode: true, DisableTLS: true, Host: config.Host + ":" + config.Port, diff --git a/mongoModels.go b/mongoModels.go index beb1db8..553d0c8 100644 --- a/mongoModels.go +++ b/mongoModels.go @@ -102,3 +102,10 @@ type DateCountModel struct { Date string `json:"date"` Count int `json:"count"` } +type StatsModel struct { + Title string `json:"title"` + RealBlockCount int `json:"realblockcount"` + BlockCount int `json:"blockcount"` + TxCount int `json:"txcount"` + AddrCount int `json:"addrcount"` +} diff --git a/mongoOperations.go b/mongoOperations.go index 42009df..2975f38 100644 --- a/mongoOperations.go +++ b/mongoOperations.go @@ -117,6 +117,11 @@ func saveAddress(address AddressModel) { //address not found, so let's add a new entry err = addressCollection.Insert(address) check(err) + + //stats addr + stats := getStats() + stats.AddrCount++ + updateStats(stats) } } func saveTx(tx TxModel) { diff --git a/serverRoutes.go b/serverRoutes.go index 39740e9..6464bff 100644 --- a/serverRoutes.go +++ b/serverRoutes.go @@ -22,6 +22,12 @@ var routes = Routes{ "/", Index, }, + Route{ + "Stats", + "Get", + "/stats", + Stats, + }, Route{ "AllAddresses", "Get", @@ -106,6 +112,16 @@ func NewUser(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "new user added: ", newUser.ID) } */ +func Stats(w http.ResponseWriter, r *http.Request) { + ipFilter(w, r) + + stats := getStats() + + jsonResp, err := json.Marshal(stats) + check(err) + + fmt.Fprintln(w, string(jsonResp)) +} func AllAddresses(w http.ResponseWriter, r *http.Request) { ipFilter(w, r) @@ -154,6 +170,7 @@ func AddressNetwork(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "not valid address") } else { network := addressTree(address) + network.Nodes[0].Shape = "triangle" //convert []resp struct to json jNetwork, err := json.Marshal(network) diff --git a/stats.go b/stats.go new file mode 100644 index 0000000..f495d04 --- /dev/null +++ b/stats.go @@ -0,0 +1,23 @@ +package main + +import "gopkg.in/mgo.v2/bson" + +func getStats() StatsModel { + var stats StatsModel + err := statsCollection.Find(bson.M{"title": "stats"}).One(&stats) + check(err) + stats.Title = "stats" + return stats +} + +func updateStats(stats StatsModel) { + var oldStats StatsModel + err := statsCollection.Find(bson.M{"title": "stats"}).One(&oldStats) + if err != nil { + err = statsCollection.Insert(stats) + check(err) + } else { + err = statsCollection.Update(bson.M{"title": "stats"}, &stats) + check(err) + } +} diff --git a/web/views/main/main.html b/web/views/main/main.html index 035f8d0..54149ac 100644 --- a/web/views/main/main.html +++ b/web/views/main/main.html @@ -1,3 +1,45 @@ +
+
+
+
+

{{stats.realblockcount}}/{{stats.blockcount}} Blocks with content

+
+
+
+
+
+
+
+
+
+

{{stats.txcount}} Txs

+
+
+
+
+
+
+
+
+
+

{{stats.addrcount}} Addr

+
+
+
+
+
+
+
+
+
+

300-500 Min-Max Block Size

+
+
+
+
+
+
+
@@ -15,31 +57,35 @@
-
-

Last 24 hours Tx/Hour - View more

-
-
- - -
-
-

Last 7 days Tx/Hour +
+
+

Last 24 hours Tx/Hour View more

+
+
+ + +
-
- - -
+
+
+

Last 7 days Tx/Hour + View more

+
+
+ + +
+

-

Hours

+

Tx/Day Last 7 Days

- - + +
@@ -50,7 +96,7 @@

Last Tx with amount

-
+