added tx page in frontend and backend route. Added address tx chart time analysis
arnaucode idoctnef@openmailbox.org
Wed, 30 Aug 2017 00:32:56 +0200
10 files changed,
205 insertions(+),
28 deletions(-)
M
dateAnalysis.go
→
dateAnalysis.go
@@ -8,6 +8,9 @@
"gopkg.in/mgo.v2/bson" ) +func dateBeforeThan(dateA time.Time, dateB time.Time) bool { + return dateA.Before(dateB) +} func map24hours() map[int]int { h := make(map[int]int) for i := 0; i < 24; i++ {
M
mongoModels.go
→
mongoModels.go
@@ -107,6 +107,10 @@ type ChartAnalysisResp struct {
Labels []string `json:"labels"` Data []int `json:"data"` } +type ChartAnalysisRespFloat64 struct { + Labels []string `json:"labels"` + Data []float64 `json:"data"` +} type ChartSeriesAnalysisResp struct { Labels []string `json:"labels"` Data [][]int `json:"data"`
M
serverRoutes.go
→
serverRoutes.go
@@ -53,6 +53,12 @@ "/block/{height}",
Block, }, Route{ + "Tx", + "GET", + "/tx/{txid}", + Tx, + }, + Route{ "Address", "GET", "/address/{hash}",@@ -99,6 +105,12 @@ "GetLast7DayHourAnalysis",
"Get", "/last7dayhour", GetLast7DayHourAnalysis, + }, + Route{ + "GetAddressTimeChart", + "GET", + "/addresstimechart/{hash}", + GetAddressTimeChart, }, }@@ -189,14 +201,6 @@
txs := []TxModel{} err = txCollection.Find(bson.M{"blockheight": heightString}).All(&txs) block.Txs = txs - - /*for _, tx := range address.Txs { - blocks := []BlockModel{} - err = blockCollection.Find(bson.M{"blockheight": tx.BlockHash}).All(&blocks) - for _, block := range blocks { - address.Blocks = append(address.Blocks, block) - } - }*/ //convert []resp struct to json jsonResp, err := json.Marshal(block)@@ -205,6 +209,24 @@
fmt.Fprintln(w, string(jsonResp)) } } +func Tx(w http.ResponseWriter, r *http.Request) { + ipFilter(w, r) + + vars := mux.Vars(r) + txid := vars["txid"] + if txid == "undefined" { + fmt.Fprintln(w, "not valid txid") + } else { + tx := TxModel{} + err := txCollection.Find(bson.M{"txid": txid}).One(&tx) + + //convert []resp struct to json + jsonResp, err := json.Marshal(tx) + check(err) + + fmt.Fprintln(w, string(jsonResp)) + } +} func Address(w http.ResponseWriter, r *http.Request) { ipFilter(w, r)@@ -217,7 +239,7 @@ address := AddressModel{}
err := addressCollection.Find(bson.M{"hash": hash}).One(&address) txs := []TxModel{} - err = txCollection.Find(bson.M{"$or": []bson.M{bson.M{"from": hash}, bson.M{"to": hash}}}).All(&txs) + err = txCollection.Find(bson.M{"$or": []bson.M{bson.M{"vin.address": hash}, bson.M{"vout.address": hash}}}).All(&txs) address.Txs = txs for _, tx := range address.Txs {@@ -463,3 +485,56 @@ jsonResp, err := json.Marshal(resp)
check(err) fmt.Fprintln(w, string(jsonResp)) } +func GetAddressTimeChart(w http.ResponseWriter, r *http.Request) { + ipFilter(w, r) + + vars := mux.Vars(r) + hash := vars["hash"] + if hash == "undefined" { + fmt.Fprintln(w, "not valid hash") + } else { + address := AddressModel{} + err := addressCollection.Find(bson.M{"hash": hash}).One(&address) + + txs := []TxModel{} + err = txCollection.Find(bson.M{"$or": []bson.M{bson.M{"vin.address": hash}, bson.M{"vout.address": hash}}}).All(&txs) + address.Txs = txs + + for _, tx := range address.Txs { + blocks := []BlockModel{} + err = blockCollection.Find(bson.M{"hash": tx.BlockHash}).All(&blocks) + for _, block := range blocks { + address.Blocks = append(address.Blocks, block) + } + } + + count := make(map[time.Time]float64) + for _, tx := range txs { + var val float64 + for _, vin := range tx.Vin { + val = val + vin.Amount + } + count[tx.DateT] = val + } + var dateSorted []time.Time + for t, _ := range count { + dateSorted = append(dateSorted, t) + } + sort.Slice(dateSorted, func(i, j int) bool { + //return dateSorted[i] < dateSorted[j] + return dateBeforeThan(dateSorted[i], dateSorted[j]) + }) + + var resp ChartAnalysisRespFloat64 + for _, t := range dateSorted { + resp.Labels = append(resp.Labels, t.String()) + resp.Data = append(resp.Data, count[t]) + } + + //convert []resp struct to json + jsonResp, err := json.Marshal(resp) + check(err) + + fmt.Fprintln(w, string(jsonResp)) + } +}
M
web/app.js
→
web/app.js
@@ -12,6 +12,7 @@ 'angular-svg-round-progressbar',
'app.navbar', 'app.main', 'app.block', + 'app.tx', 'app.address', 'app.network', 'app.addressNetwork',
M
web/index.html
→
web/index.html
@@ -76,8 +76,9 @@ <!-- app's js -->
<script src="app.js"></script> <script src="views/navbar.js"></script> <script src="views/main/main.js"></script> + <script src="views/block/block.js"></script> + <script src="views/tx/tx.js"></script> <script src="views/address/address.js"></script> - <script src="views/block/block.js"></script> <script src="views/network/network.js"></script> <script src="views/addressNetwork/addressNetwork.js"></script> <script src="views/sankey/sankey.js"></script>
M
web/views/address/address.html
→
web/views/address/address.html
@@ -8,20 +8,29 @@ <div class="panel-body">
{{address.amount}} </div> </div> + <div class="panel"> + <div class="panel-heading c_deepPurpleG300to500"> + <h3 class="panel-title">Address uses + </div> + <div class="panel-body"> + <canvas id="line" class="chart chart-line" chart-data="addresstimechart.data" chart-labels="addresstimechart.labels"> + </canvas> + </div> + </div> </div> <div class="col-sm-8"> <div class="panel"> <div class="panel-heading c_deepPurpleG300to500"> <h3 class="panel-title">Blocks where address appears</h3> </div> - <div class="panel-body"> + <div class="panel-body" style="max-height: 300px;overflow-y: scroll;"> <div class="list-group"> <a ng-href="#!/block/{{block.height}}" class="list-group-item-text" ng-repeat="block in address.blocks"> Block Height: {{block.height}} <br> Hash: {{block.hash}} <br> {{block.datet}} <br> Size: {{block.size}} bytes - <br> + <hr> </a> </div> </div>@@ -39,32 +48,36 @@ <div class="panel-body">
<table class="table table-hover"> <thead> <tr> - <th>BlockHeight</th> - <th>From</th> - <th>To</th> - <th>Amount</th> - <th></th> + <th>Txid</th> + <th>Input</th> + <th>Output</th> </tr> </thead> <tbody> <tr ng-repeat="tx in address.txs"> <td style="max-width:20px; overflow:hidden;"> - <a ng-href="#!/block/{{tx.blockheight}}" class="list-group-item-text"> - {{tx.blockheight}} + <a ng-href="#!/tx/{{tx.txid}}" class="list-group-item-text"> + {{tx.txid}} </a> + <br> + {{tx.datet}} </td> <td style="max-width:20px; overflow:hidden;"> - <a ng-href="#!/address/{{tx.from}}" class="list-group-item-text"> - {{tx.from}} - </a> + <table><tbody><tr ng-repeat="vin in tx.vin"><td> + <a ng-href="#!/address/{{vin.address}}" class="list-group-item-text"> + {{vin.address}} + </a> + :{{vin.amount}} + </td></tr></tbody></table> </td> <td style="max-width:20px; overflow:hidden;"> - <a ng-href="#!/address/{{tx.to}}" class="list-group-item-text"> - {{tx.to}} - </a> + <table><tbody><tr ng-repeat="vout in tx.vout"><td> + <a ng-href="#!/address/{{vout.address}}" class="list-group-item-text"> + {{vout.address}} + </a> + :{{vout.value}} + </td></tr></tbody></table> </td> - <td>{{tx.amount}}</td> - <td><a ng-href="#!/tx/{{tx.id}}">View</a></td> </tr> </tbody> </table>
M
web/views/address/address.js
→
web/views/address/address.js
@@ -18,4 +18,16 @@ $scope.address = data.data;
}, function(data, status, headers, config) { console.log('data error'); }); + $scope.addresstimechart= { + data:[], + labels: [] + }; + $http.get(urlapi + 'addresstimechart/' + $routeParams.hash) + .then(function(data, status, headers, config) { + console.log(data); + $scope.addresstimechart.data = data.data.data; + $scope.addresstimechart.labels = data.data.labels; + }, function(data, status, headers, config) { + console.log('data error'); + }); });
M
web/views/block/block.html
→
web/views/block/block.html
@@ -43,7 +43,7 @@ </thead>
<tbody> <tr ng-repeat="tx in block.txs"> <td style="max-width:20px; overflow:hidden;"> - <a ng-href="#!/address/{{tx.from}}" class="list-group-item-text"> + <a ng-href="#!/tx/{{tx.txid}}" class="list-group-item-text"> {{tx.txid}} </a> </td>
A
web/views/tx/tx.html
@@ -0,0 +1,47 @@
+<div class="row"> + <div class="col-sm-12"> + <div class="panel"> + <div class="panel-heading c_deepPurpleG300to500"> + <h3 class="panel-title">Tx {{tx.txid}}</h3> + </div> + <div class="panel-body"> + <div class="col-sm-12"> + <table class="table table-hover"> + <thead> + <tr> + <th>Txid</th> + <th>Input</th> + <th>Output</th> + </tr> + </thead> + <tbody> + <tr> + <td style="max-width:20px; overflow:hidden;"> + <a ng-href="#!/tx/{{tx.txid}}" class="list-group-item-text"> + {{tx.txid}} + </a> + </td> + <td style="max-width:20px; overflow:hidden;"> + <table><tbody><tr ng-repeat="vin in tx.vin"><td> + <a ng-href="#!/address/{{vin.address}}" class="list-group-item-text"> + {{vin.address}} + </a> + :{{vin.amount}} + </td></tr></tbody></table> + </td> + <td style="max-width:20px; overflow:hidden;"> + <table><tbody><tr ng-repeat="vout in tx.vout"><td> + <a ng-href="#!/address/{{vout.address}}" class="list-group-item-text"> + {{vout.address}} + </a> + :{{vout.value}} + </td></tr></tbody></table> + </td> + </tr> + </tbody> + </table> + </div> + </div> + </div> + </div> +</div>
A
web/views/tx/tx.js
@@ -0,0 +1,21 @@
+'use strict'; + +angular.module('app.tx', ['ngRoute']) + + .config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/tx/:txid', { + templateUrl: 'views/tx/tx.html', + controller: 'TxCtrl' + }); + }]) + + .controller('TxCtrl', function($scope, $http, $routeParams) { + $scope.tx = {}; + $http.get(urlapi + 'tx/' + $routeParams.txid) + .then(function(data, status, headers, config) { + console.log(data); + $scope.tx = data.data; + }, function(data, status, headers, config) { + console.log('data error'); + }); + });