mirror of
https://github.com/arnaucube/goBlockchainDataAnalysis.git
synced 2026-02-06 19:26:41 +01:00
sankey in frontend works, added logs system, added getLastTx in backend and frontend
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@
|
||||
/*.conf
|
||||
/*.json
|
||||
*.mp4
|
||||
logs
|
||||
|
||||
12
README.md
12
README.md
@@ -1,6 +1,18 @@
|
||||
# goBlockchainDataAnalysis
|
||||
blockchain data analysis, written in Go
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||

|
||||
|
||||
|
||||

|
||||
|
||||
|
||||

|
||||
|
||||
### Install
|
||||
1. Nodejs & NPM https://nodejs.org/
|
||||
2. MongoDB https://www.mongodb.com/
|
||||
|
||||
@@ -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
Normal file
BIN
goBlockchainDataAnalysis05.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 127 KiB |
19
log.go
Normal file
19
log.go
Normal file
@@ -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)
|
||||
}
|
||||
68
main.go
68
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"})
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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,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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user