Browse Source

sankey in frontend works, added logs system, added getLastTx in backend and frontend

master
arnaucode 6 years ago
parent
commit
fe164456fb
11 changed files with 107 additions and 51 deletions
  1. +1
    -0
      .gitignore
  2. +12
    -0
      README.md
  3. +2
    -2
      errors.go
  4. BIN
      goBlockchainDataAnalysis05.png
  5. +19
    -0
      log.go
  6. +32
    -36
      main.go
  7. +19
    -8
      serverRoutes.go
  8. +6
    -2
      web/views/main/main.html
  9. +10
    -1
      web/views/main/main.js
  10. +1
    -1
      web/views/sankey/sankey.html
  11. +5
    -1
      web/views/sankey/sankey.js

+ 1
- 0
.gitignore

@ -17,3 +17,4 @@
/*.conf
/*.json
*.mp4
logs

+ 12
- 0
README.md

@ -1,6 +1,18 @@
# goBlockchainDataAnalysis
blockchain data analysis, written in Go
![goBlockchainDataAnalysis](https://raw.githubusercontent.com/arnaucode/goBlockchainDataAnalysis/master/goBlockchainDataAnalysis01.png "goBlockchainDataAnalysis")
![goBlockchainDataAnalysis](https://raw.githubusercontent.com/arnaucode/goBlockchainDataAnalysis/master/goBlockchainDataAnalysis02.png "goBlockchainDataAnalysis")
![goBlockchainDataAnalysis](https://raw.githubusercontent.com/arnaucode/goBlockchainDataAnalysis/master/goBlockchainDataAnalysis05.png "goBlockchainDataAnalysis")
![goBlockchainDataAnalysis](https://raw.githubusercontent.com/arnaucode/goBlockchainDataAnalysis/master/goBlockchainDataAnalysis04.png "goBlockchainDataAnalysis")
### Install
1. Nodejs & NPM https://nodejs.org/
2. MongoDB https://www.mongodb.com/

+ 2
- 2
errors.go

@ -1,9 +1,9 @@
package main
import "fmt"
import "log"
func check(err error) {
if err != nil {
fmt.Println(err)
log.Println(err)
}
}

BIN
goBlockchainDataAnalysis05.png

Before After
Width: 1179  |  Height: 557  |  Size: 127 KiB

+ 19
- 0
log.go

@ -0,0 +1,19 @@
package main
import (
"io"
"log"
"os"
"time"
)
func savelog() {
timeS := time.Now().String()
_ = os.Mkdir("logs", os.ModePerm)
logFile, err := os.OpenFile("logs/log-"+timeS+".log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
if err != nil {
panic(err)
}
mw := io.MultiWriter(os.Stdout, logFile)
log.SetOutput(mw)
}

+ 32
- 36
main.go

@ -1,7 +1,6 @@
package main
import (
"fmt"
"log"
"net/http"
"os"
@ -20,6 +19,7 @@ var dateCountCollection *mgo.Collection
var hourCountCollection *mgo.Collection
func main() {
savelog()
//read goBlockchainDataAbalysis config
readConfig("config.json")
@ -33,50 +33,46 @@ func main() {
dateCountCollection = getCollection(session, "dateCounts")
hourCountCollection = getCollection(session, "hourCounts")
// create new client instance
client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{
HTTPPostMode: true,
DisableTLS: true,
Host: config.Host + ":" + config.Port,
User: config.User,
Pass: config.Pass,
}, nil)
if err != nil {
log.Fatalf("error creating new btc client: %v", err)
}
// list accounts
accounts, err := client.ListAccounts()
if err != nil {
log.Fatalf("error listing accounts: %v", err)
}
// iterate over accounts (map[string]btcutil.Amount) and write to stdout
for label, amount := range accounts {
log.Printf("%s: %s", label, amount)
}
if len(os.Args) > 1 {
if os.Args[1] == "-explore" {
// create new client instance
client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{
HTTPPostMode: true,
DisableTLS: true,
Host: config.Host + ":" + config.Port,
User: config.User,
Pass: config.Pass,
}, nil)
if err != nil {
log.Fatalf("error creating new btc client: %v", err)
}
// list accounts
accounts, err := client.ListAccounts()
if err != nil {
log.Fatalf("error listing accounts: %v", err)
}
// iterate over accounts (map[string]btcutil.Amount) and write to stdout
for label, amount := range accounts {
log.Printf("%s: %s", label, amount)
}
color.Blue("starting to explore blockchain")
explore(client, config.GenesisBlock)
}
/*if os.Args[1] == "-tree" {
color.Blue("starting to make tree")
addressTree(client, "fY3HZxu7HFKRcYzVSTXRZpAJMP4qba2oR6")
}*/
}
// Get the current block count.
blockCount, err := client.GetBlockCount()
if err != nil {
log.Fatal(err)
// Get the current block count.
blockCount, err := client.GetBlockCount()
if err != nil {
log.Fatal(err)
}
log.Printf("Block count: %d", blockCount)
}
}
log.Printf("Block count: %d", blockCount)
//http server start
readServerConfig("./serverConfig.json")
color.Green("server running")
fmt.Print("port: ")
color.Green(serverConfig.ServerPort)
log.Println("server running")
log.Print("port: ")
log.Println(serverConfig.ServerPort)
router := NewRouter()
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Access-Control-Allow-Origin"})

+ 19
- 8
serverRoutes.go

@ -26,6 +26,12 @@ var routes = Routes{
"/alladdresses",
AllAddresses,
},
Route{
"GetLastTx",
"Get",
"/lasttx",
GetLastTx,
},
Route{
"AddressNetwork",
"GET",
@ -50,14 +56,6 @@ var routes = Routes{
"/houranalysis",
GetHourAnalysis,
},
/*
Route{
"SelectItem",
"GET",
"/selectItem/{userid}/{itemid}",
SelectItem,
},
*/
}
//ROUTES
@ -95,6 +93,19 @@ func AllAddresses(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, string(jsonNodes))
}
func GetLastTx(w http.ResponseWriter, r *http.Request) {
ipFilter(w, r)
nodes := []NodeModel{}
err := nodeCollection.Find(bson.M{}).Limit(10).Sort("-$natural").All(&nodes)
check(err)
//convert []resp struct to json
jNodes, err := json.Marshal(nodes)
check(err)
fmt.Fprintln(w, string(jNodes))
}
func AddressNetwork(w http.ResponseWriter, r *http.Request) {
ipFilter(w, r)

+ 6
- 2
web/views/main/main.html

@ -3,10 +3,14 @@
<div class="col-sm-4">
<div class="panel">
<div class="panel-heading c_blueGrey300">
<h3 class="panel-title">Last blocks</h3>
<h3 class="panel-title">Last addresses</h3>
</div>
<div class="panel-body" style="max-height: 500px;overflow-y: scroll;">
<div class="list-group-item" ng-repeat="node in addresses">
<div class="row-content">
<p class="list-group-item-text">{{node.id}}</p>
</div>
</div>
</div>
</div>
</div>

+ 10
- 1
web/views/main/main.js

@ -10,5 +10,14 @@ angular.module('app.main', ['ngRoute'])
}])
.controller('MainCtrl', function($scope, $http) {
$scope.addresses = [];
$http.get(urlapi + 'lasttx')
.then(function(data, status, headers, config) {
console.log('data success');
console.log(data);
$scope.addresses = data.data;
}, function(data, status, headers, config) {
console.log('data error');
});
});

+ 1
- 1
web/views/sankey/sankey.html

@ -19,7 +19,7 @@
</div>
<div class="col-sm-10">
<div class="panel-heading c_blueGrey300">
<h3 class="panel-title">Sankey</h3>
<h3 class="panel-title">Sankey - address {{selectedAddress}}</h3>
</div>
<div class="panel-body">
<!--<ng-sankey id="sankeyChart" options="options" data="data"></ng-sankey>

+ 5
- 1
web/views/sankey/sankey.js

@ -10,7 +10,7 @@ angular.module('app.sankey', ['ngRoute', 'ngSankey'])
}])
.controller('SankeyCtrl', function($scope, $http, $routeParams) {
$scope.selectedAddress = "";
$scope.options = {
chart: '#sankeyChart',
width: 960,
@ -36,6 +36,9 @@ angular.module('app.sankey', ['ngRoute', 'ngSankey'])
});
$scope.getAddressSankey = function(address) {
console.log(address);
$scope.selectedAddress = address.id;
$scope.data.nodes = [];
$scope.data.links = [];
$http.get(urlapi + 'address/sankey/' + address.id)
.then(function(data, status, headers, config) {
console.log('data success');
@ -43,6 +46,7 @@ angular.module('app.sankey', ['ngRoute', 'ngSankey'])
$scope.data.nodes = data.data.nodes;
$scope.data.links = data.data.links;
console.log($scope.data);
d3.selectAll("svg > *").remove();
let chart = new d3.sankeyChart(data.data, $scope.options);
//$scope.data = data.data;
}, function(data, status, headers, config) {

Loading…
Cancel
Save