-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphviz_routes.js
126 lines (122 loc) · 4.43 KB
/
graphviz_routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const helperfunctions = require("./helper_functions.js");
const graph_gen_for_contract = require("./generate_graph_for_contract.js")
const graph_gen_per_transaction=require("./generate_graph_per_transaction.js")
const generate_graph_from_static = require("./generate_graph_from_upload.js")
module.exports ={
graphvizCallback : function(contractTransList,found_trans,res){
graphvizCallback(contractTransList,found_trans,res)
},
graphvizCallbackEVMInvocation : function(contractTransList,found_trans,res){
graphvizCallbackEVMInvocation(contractTransList,found_trans,res)
},
welcomeCallback : function(contractTransList,found_trans,res){
welcomeCallback(contractTransList,found_trans,res)
}
}
var graphvizCallbackEVMInvocation = function(contractTransList,found_trans,res){
console.log("graphvizCallbackEVMInvocation called")
var response_graphviz = []; // to store results
var transArr = [];
found_trans.forEach(function(index){
var dotFormat = index.graph;
console.log(dotFormat)
transArr.push(index.randomHash)
dotFormat=dotFormat.toString()
response_graphviz.push(dotFormat);
})
//now render to screen
console.log("rendering screen ejs")
console.log("transArr is "+transArr)
res.render("viz.ejs",{
transArr:transArr,
block_num:"1000",
num_block:"10",
graph_formats: response_graphviz
});
}
var graphvizCallback = function(contractTransList,found_trans,res){
console.log("graphvizCallback called")
var found_trans_list=[];
found_trans.forEach(function(trans){//get transactions number from each object found
found_trans_list.push(trans.transaction_no);
})
console.log("Callback: there were: "+found_trans.length + "items found in the db");
console.log("Callback: we need a min of "+contractTransList.length+" items..")
Array.prototype.diff = function(a){
return this.filter(function(i){
return a.indexOf(i)<0;
});
};
var needToFindTrans=contractTransList.diff(found_trans_list) //need.diff(haveindb)
if(needToFindTrans.length){ //if there are ones that need to be generated
console.log("Callback: need to carry out graph gen for these: ");
//printing nicely
needToFindTrans.forEach(function(each){
console.log(each)
})
graph_gen_for_contract.gen_graph_promise(needToFindTrans)
}
else{ // found items in db, now display them
var response_graphviz = []; // to store results
var transArr = [];
found_trans.forEach(function(index){
var dotFormat = index.graph;
console.log(dotFormat)
transArr.push(index.randomHash)
dotFormat=dotFormat.toString()
response_graphviz.push(dotFormat);
})
//now render to screen
console.log("rendering screen ejs")
console.log("transArr is "+transArr)
res.render("viz.ejs",{ // was viz.ejs
transArr:transArr,
block_num:"1000",
num_block:"10",
graph_formats: response_graphviz
});
}
}
var welcomeCallback = function(contractTransList,found_trans,res){
console.log("graphvizCallback called")
var found_trans_list=[];
found_trans.forEach(function(trans){//get transactions number from each object found
found_trans_list.push(trans.transaction_no);
})
console.log("Callback: there were: "+found_trans.length + "items found in the db");
console.log("Callback: we need a min of "+contractTransList.length+" items..")
Array.prototype.diff = function(a){
return this.filter(function(i){
return a.indexOf(i)<0;
});
};
var needToFindTrans=contractTransList.diff(found_trans_list) //need.diff(haveindb)
if(needToFindTrans.length){ //if there are ones that need to be generated
console.log("Callback: need to carry out graph gen for these: ");
//printing nicely
needToFindTrans.forEach(function(each){
console.log(each)
})
graph_gen_for_contract.gen_graph_promise(needToFindTrans)
}
else{ // found items in db, now display them
var response_graphviz = []; // to store results
var transArr = [];
found_trans.forEach(function(index){
var dotFormat = index.graph;
console.log(dotFormat)
transArr.push(index.randomHash)
dotFormat=dotFormat.toString()
response_graphviz.push(dotFormat);
})
//now render to screen
console.log("rendering screen ejs")
console.log("transArr is "+transArr)
res.render("welcome.ejs",{ // was viz.ejs
transArr:transArr,
block_num:"1000",
num_block:"10",
graph_formats: response_graphviz
});
}
}