forked from Gilg4mesh/dailyblockchain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
803 lines (705 loc) · 26.4 KB
/
index.html
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Samourai Whirlpool live</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/vivagraph.js"></script>
<script type="text/javascript" src="js/webgl-programs.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<style>
body{
margin: 0;
padding: 0;
position: relative;
background:#054050;
color:#cbd7da;
}
.input-node{color:green;}
.output-node{color:red;}
.input-output-node{color:orange;}
.transaction-node{color:#008ed2;}
#log{
position: absolute;
left:4px;
top:4px;
padding:4px;
text-align:left;
font-size:0.8em;
}
#info{
position: absolute;
right:4px;
top:4px;
padding:4px;
}
</style>
<link rel="shortcut icon" href="http://samouraiwallet.com/static/public/favicon/favicon.ico"/>
<link rel="apple-touch-icon" sizes="57x57" href="http://samouraiwallet.com/static/public/favicon/apple-icon-57x57.png"/>
<link rel="apple-touch-icon" sizes="60x60" href="http://samouraiwallet.com/static/public/favicon/apple-icon-60x60.png"/>
<link rel="apple-touch-icon" sizes="72x72" href="http://samouraiwallet.com/static/public/favicon/apple-icon-72x72.png"/>
<link rel="apple-touch-icon" sizes="76x76" href="http://samouraiwallet.com/static/public/favicon/apple-icon-76x76.png"/>
<link rel="apple-touch-icon" sizes="114x114" href="http://samouraiwallet.com/static/public/favicon/apple-icon-114x114.png"/>
<link rel="apple-touch-icon" sizes="120x120" href="http://samouraiwallet.com/static/public/favicon/apple-icon-120x120.png"/>
<link rel="apple-touch-icon" sizes="144x144" href="http://samouraiwallet.com/static/public/favicon/apple-icon-144x144.png"/>
<link rel="apple-touch-icon" sizes="152x152" href="http://samouraiwallet.com/static/public/favicon/apple-icon-152x152.png"/>
<link rel="apple-touch-icon" sizes="180x180" href="http://samouraiwallet.com/static/public/favicon/apple-icon-180x180.png"/>
<link rel="icon" type="image/png" sizes="192x192" href="http://samouraiwallet.com/static/public/favicon/android-icon-192x192.png"/>
<link rel="icon" type="image/png" sizes="16x16" href="http://samouraiwallet.com/static/public/favicon/favicon-16x16.png"/>
<link rel="icon" type="image/png" sizes="32x32" href="http://samouraiwallet.com/static/public/favicon/favicon-32x32.png"/>
<link rel="icon" type="image/png" sizes="96x96" href="http://samouraiwallet.com/static/public/favicon/favicon-96x96.png"/>
</head>
<body>
<div id="g" style="background:#043a48; border-bottom:12px solid #c12727; width:100%; height:800px;"></div>
<div id="info"></div>
<div id="log">
Processed <span id="blocks">0</span> blocks since #<span id="blockHeight">0</span>, <span id="allTxs">0</span> txs.<br/>
<small id="txHash"></small>
</div>
<div style="float:right"><scroll> to zoom<br/><space> to pause</div>
<center>
<h1>Samourai Whirlpool live</h1>
Visualizing Whirlpool transactions from 100 last blocks and mempool (real-time).<br/>
<span style="color:#00FF00"><span id="NODE_PREMIX">0</span> premixs</span>, <span style="color:#FF0000"><span id="NODE_POSTMIX">0</span> postmixs unspent</span>,
<span style="color:#fde7e7"><span id="NODE_POSTMIX_SPEND">0</span> postmixs spent</span>, <span style="color:#999999"><span id="NODE_TX0_INPUT">0</span> tx0 inputs</span>, <span style="color:#333333"><span id="NODE_TX0_CHANGE">0</span> tx0 changes</span><br/>
<span style="color:#008ED2"><span id="TX_MIX">0</span> mixs</span>,
<span style="color:#29efef"><span id="TX_TX0">0</span> tx0s</span>, <span style="color:#f57900"><span id="TX_SPEND">0</span> postmix spends</span>
</center>
<br/>
<center><small style="color:#ccc"><a href="https://samouraiwallet.com">SamouraiWallet</a> - Visualization forked from <a href="https://dailyblockchain.github.io/" target="_blank">dailyblockchain.github.io</a></small></center>
</body>
<script language="javascript" type="text/javascript">
var ADDRESSES_MIX_INPUTS = {}
var ADDRESSES_TX0_OUTPUTS = {}
var ADDRESSES_MIX_OUTPUTS = {}
var ADDRESSES_SPEND_INPUTS = {}
var LINKS_UNCONFIRMED = {}
const TX_TYPE = {
MIX: 'MIX',
SPEND: 'SPEND',
TX0: 'TX0'
};
const NODE_TYPE = {
PREMIX: 'PREMIX',
TX0_INPUT: 'TX0_INPUT',
TX0_CHANGE: 'TX0_CHANGE',
POSTMIX: 'POSTMIX',
POSTMIX_SPEND: 'POSTMIX_SPEND'
};
const POOL_DENOMINATIONS = [100000,1000000,5000000,50000000];
// viva graph part
var graphics = Viva.Graph.View.webglGraphics();
var isWebgl = graphics.isSupported();
if (!isWebgl) {
alert("Turn on webgl or use modern browser");
}
var graph = Viva.Graph.graph(),
layout = Viva.Graph.Layout.forceDirected(graph, {
springLength : 80,
springCoeff : 0.0002,
dragCoeff : 0.009,
gravity : -30,
theta : 0.7
}),
minNodeSize = 1,
maxNodeSize = 100000000;
function getPoolColor(pool) {
return 0x008ED2;
/*if (pool) {
switch (pool) {
case "0.5btc": return 0xeb3030;
case "0.05btc": return 0x410d0d;
case "0.01btc": return 0x6c1616;
case "0.001btc": return 0x961e1e;
}
}
console.error('unknown pool:',pool)
return "#000000";*/
}
function getPoolSize(pool) {
if (pool) {
switch (pool) {
case "0.5btc": return 500;
case "0.05btc": return 50;
case "0.01btc": return 10;
case "0.001btc": return 1;
}
}
console.error('unknown pool:',pool)
return 1;
}
function log10(val) {
return Math.log(val) / Math.LN10;
}
function log2(val) {
return Math.log(val) / Math.LN2;
}
var scaleType = "LOG";//"LINEAR"; //"LOG"; // LINEAR
var getNodeColor = function(node) {
// outpoint
if (node.data.t) {
switch (node.data.t) {
case NODE_TYPE.PREMIX: return 0x00FF00;
case NODE_TYPE.POSTMIX: return 0xFF0000;
case NODE_TYPE.TX0_INPUT: return 0x999999;
case NODE_TYPE.TX0_CHANGE: return 0x333333;
case NODE_TYPE.POSTMIX_SPEND: return 0xfde7e7;
default: return 0xFFA500;
}
}
// tx
switch (node.data.tt) {
case TX_TYPE.SPEND: return 0xf57900;
case TX_TYPE.TX0: return 0x29efef;
case TX_TYPE.MIX: return 0x008ED2;
}
console.error("unknown nodeColor", node)
},
getLinkColor = function(link) {
if (link.data.tt == TX_TYPE.SPEND) {
return 0xFF0000;
} else if (link.data.tt == TX_TYPE.TX0) {
return 0x00FF00;
}
return 0x808080; //getPoolColor(node.data.p); //0x008ED2
},
getNodeSize = function(node){
var value
if(!node.data.s){
// tx
value = node.data.tv;
//console.log('size tx',value)
} else {
// outpoint
value = node.data.s;
//console.log('size outpoint',value)
}
value = value*value*value
//value = node.data.s/100000;
//value = value*value;
var rmin = 1;
var rmax = 25;
// linear normalization to a range rmin,rmax
if(scaleType == "LINEAR"){
return rmin + (rmax - rmin) * ( (value - minNodeSize)/(maxNodeSize - minNodeSize) ) ;
}else{
// log normalization to a range rmin,rmax
var min = log2(minNodeSize);
var max = log2(maxNodeSize);
var val = log2( value );
// linear scaling from min.max -> rmin rmax
return rmin + (rmax - rmin) * ( (val - min)/(max - min) ) ;
}
},
getNodeDetails = function(node){
console.log('details',node);
var label = "transaction";
var id = '';
if(node.data && node.data.t){
// input/output
id += 'Address: <a href="https://oxt.me/address/' + node.id + '" target="_blank">' + node.id + '</a><br/>';
label = node.data.t;
}else{
// transaction node
id='';
label = node.data.tt+' transaction';
}
var linkData = node.data ? node.data : node.links[0].data
id += 'Tx: <small><a href="https://oxt.me/transaction/' + linkData.h + '" target="_blank">' + linkData.h + '</a></small><br/>';
id += 'Pool: '+linkData.p;
var html = "<h4>"+label+"</h4><small>"+id
if (node.data.s) {
html += "<br/>Value: "+(node.data.s/100000000)+" BTC";
} else {
html += "<br/>Volume: "+(node.data.tv/100000000)+" BTC";
}
document.getElementById("info").innerHTML = html
};
// need to get these 2 from yavis.reddit.min.js
graphics.setLinkProgram(Viva.Graph.View.webglDualColorLinkProgram());
graphics.setNodeProgram(Viva.Graph.View.webglCustomNodeProgram());
graphics
.node(function(node){
return Viva.Graph.View.webglSquare(getNodeSize(node), getNodeColor(node));
/*if (false && node.data) {
return Viva.Graph.svg('image')
.attr('width', 24)
.attr('height', 24)
.link(node.data.url);
} else {
return Viva.Graph.View.webglSquare(getNodeSize(node), getNodeColor(node));
}*/
})
.link(function(link){
var fromColor, toColor;
fromColor = toColor = getLinkColor(link);//0x808080;//getPoolColor(link.data.p)
var line = Viva.Graph.View.webglDualColorLine(fromColor, toColor);
line.oldStart = fromColor;
line.oldEnd = toColor;
return line;
});
var renderer = Viva.Graph.View.renderer(graph,{
layout : layout,
graphics : graphics,
container : document.getElementById('g')
//prerender : 10
});
var blocks = 0, blockHeight='', allTxs = 0, since=new Date().toISOString();
var counts = {};
for (const t of Object.values(TX_TYPE)) {
counts[t] = 0;
}
for (const t of Object.values(NODE_TYPE)) {
counts[t] = 0;
}
var events = Viva.Graph.webglInputEvents(graphics, graph),
lastHovered = null,
colorLinks = function(node, color) {
if (node && node.id) {
graph.forEachLinkedNode(node.id, function(node, link){
if (color) {
link.ui.start = link.ui.end = color;
} else {
//link.ui.start = link.ui.oldStart;
//link.ui.end =link.ui.oldEnd;
link.ui.start = link.ui.end = 0x80808040;
}
});
}
};
events.click(function(node){
getNodeDetails(node);
colorLinks(lastHovered);
lastHovered = node;
graph.forEachLinkedNode(node.id, function(node, link){
link.ui.start = link.ui.end = 0xffffffff;
graphics.bringLinkToFront(link.ui);
});
renderer.rerender();
}).mouseLeave(function(node) {
colorLinks(lastHovered);
lastHovered = null;
colorLinks(node);
renderer.rerender();
});
var APPROX_FACTOR = 10000;
// pause rendere on spacebar
var paused = false;
$(window).keydown(function(e) {
if (e.keyCode === 32) { // toggle on spacebar;
e.preventDefault();
paused = !paused;
if (paused) { renderer.pause(); }
else { renderer.resume(); }
}
});
var width = $("#g").width(),
height= $("#g").height();
renderer.run();
graphics.scale(0.15, {x : width/2, y : height/2});
// websockets part
var linksBuffer = [];
var wsUri = "ws://ws.blockchain.info/inv";
if (document.location.protocol.indexOf("https") === 0) {
wsUri = "wss://ws.blockchain.info/inv";
}
var output;
function incr(type, isTx) {
counts[type]++;
$('#'+(isTx?'TX':'NODE')+'_'+type).html(counts[type]);
}
function getMempool() {
return $.getJSON('https://api.haskoin.com/btc/mempool?notx=false&limit=50000', data => {
console.log('MEMPOOL', data)
return data
})
}
function getLastBlock() {
return $.getJSON('https://api.haskoin.com/btc/block/best?notx=true', data => {
console.log('BEST', data)
return data
})
}
function getLatestBlocks() {
return $.getJSON('https://api.haskoin.com/btc/block/latest?notx=true', data => {
console.log('BLOCKS', data)
return data
})
}
function getBlockTxs(id) {
return $.getJSON('https://api.haskoin.com/btc/transactions/block/' + id, data => {
console.log('BLOCKTXS '+id)
return data
})
}
async function loadTxs(txids) {
const myTxs = [];
var x=0;
while(myTxs.length < 1000 && txids.length>0) {
for (var i = 0; i < 100; i++) {
myTxs.push(txids.pop())
}
console.log('loadTxs #'+x)
await $.getJSON('https://api.haskoin.com/btc/transactions', {txids: txids.join(',')}, data => {
//console.log('TXS', data)
return data
}).then(txs => onTxs(txs))
x++;
}
}
async function loadBlocks(blks) {
for (const block of blks) {
const txs = await getBlockTxs(block.hash)
onTxs(txs)
blocks++;
blockHeight = block.height
$('#blocks').html(blocks)
$('#blockHeight').html(blockHeight)
}
}
getLatestBlocks().then(blocks => loadBlocks(blocks))
function init() {
output = document.getElementById("output");
testWebSocket();
}
function addNodeTx(id, link, txType) {
let node = graph.getNode(id);
if( !node ){
graph.addNode(id,{h:link.h, p:link.p, tt:link.tt, tv:link.tv});
incr(txType, true);
}
}
function addNode(id, link, nodeType) {
var node = graph.getNode(id);
if( !node ){
graph.addNode(id,{s:link.value,t:link.t,tt:link.tt,h:link.h,p:link.p, tv:link.tv});
incr(nodeType, false);
} else {
// such a node already exists
if(node.data && node.data.t && nodeType == NODE_TYPE.POSTMIX){
node.data.t = NODE_TYPE.POSTMIX_SPEND;
node.ui.color = 0xfde7e7;
renderer.rerender();
counts[nodeType]--;
incr(NODE_TYPE.POSTMIX_SPEND, false);
}
}
}
function addNodes(link){
if(link.isInput){
// outpoint
addNode(link.from, link, link.t);
// tx node
addNodeTx(link.to, link, link.tt);
} else {
// outpoint
addNode(link.to, link, link.t);
// tx node
addNodeTx(link.from, link, link.tt);
}
}
function getValue(o) {
return o.value || (o.prev_out ? o.prev_out.value : 0)
}
function getNodeType(txType, isInput, n) {
switch (txType) {
case TX_TYPE.MIX:
return isInput ? NODE_TYPE.PREMIX : NODE_TYPE.POSTMIX;
case TX_TYPE.TX0:
return isInput ? NODE_TYPE.TX0_INPUT : (n > 1 ? NODE_TYPE.PREMIX : NODE_TYPE.TX0_CHANGE);
case TX_TYPE.SPEND:
return isInput ? NODE_TYPE.POSTMIX : NODE_TYPE.POSTMIX_SPEND;
}
console.error('unknown nodeType', txType, isInput)
}
function findAnyPremix(inputs, outputs, txType) {
switch (txType) {
case TX_TYPE.TX0: return outputs[2];
case TX_TYPE.MIX: return outputs[0];
case TX_TYPE.SPEND:
for (const input of inputs) {
for (const d of POOL_DENOMINATIONS) {
if (input.value == d) {
return input;
}
}
return undefined
}
}
}
function getPool(inputs, outputs, txType) {
const premix = findAnyPremix(inputs, outputs, txType);
if (!premix) return undefined
return (Math.floor(getValue(premix)/APPROX_FACTOR)*APPROX_FACTOR/100000000)+"btc"
}
function toDenomination(value) {
return Math.floor(value/APPROX_FACTOR)*APPROX_FACTOR;
}
function isMixInputValue(value) {
for (const d of POOL_DENOMINATIONS) {
if (d == toDenomination(value)) {
return true;
}
}
return false;
}
function isMixOutputValue(value) {
for (const d of POOL_DENOMINATIONS) {
if (d == value) {
return true;
}
}
return false;
}
function isMix(inputs,outputs,txid) {
var mock = false;
if (mock) return Math.random()>0.5;
if (!inputs || !outputs || inputs.length!= outputs.length || inputs.length <5 || inputs.length>8) return false;
for (const i of inputs) {
const value = getValue(i)
if (!isMixInputValue(value)) {
console.log('Not a mix input: '+txid, value)
return false;
}
}
for (const o of outputs) {
const value = getValue(o)
if (!isMixOutputValue(value)) {
console.log('Not a mix output: '+txid, value)
return false;
}
}
return true;
}
function getAddress(o) {
const addr = o.address || o.addr || (o.prev_out ? o.prev_out.addr : o.pkscript)
/*if (!addr && !o.coinbase) {
console.warn('addr',addr,o)
}*/
return addr;
}
function isPostmixSpend(inputs,outputs,txid) {
if (!inputs || !outputs) return false;
for (const o of inputs) {
const addr = getAddress(o)
if (ADDRESSES_MIX_OUTPUTS[addr]) {
// found spend linked to a mix
return 1;
}
const value = getValue(o)
if (isMixOutputValue(value)) {
// found potential spend
return -1;
}
}
return 0;
}
function isTx0(inputs,outputs,txid) {
if (!inputs || !outputs || outputs.length<3) return false;
let nonPremixs=0;
let opReturns=0;
let fees=0;
for (const o of outputs) {
const addr = getAddress(o)
if (ADDRESSES_MIX_INPUTS[addr]) {
// found tx0 linked to a mix
return 1;
}
const value = getValue(o)
if (value == 0) {
opReturns++;
if (opReturns>1) {
return 0;
}
}
else if (value <= 2500000) {
fees++;
}
if (!isMixInputValue(value)) {
nonPremixs++;
}
}
if (fees < 1 || opReturns != 1 || nonPremixs < 2) {
return 0;
}
if (nonPremixs>3) {
//console.log('not a tx0: '+txid,nonPremixs)
return 0;
}
// found potential tx0
return -1;
}
function confirmUnconfirmeds(txids, links, txType) {
if (txids) {
for (const txid of txids) {
const unconfirmedLinks = LINKS_UNCONFIRMED[txid]
if (unconfirmedLinks) {
console.log('confirmed '+txType+' '+txid,unconfirmedLinks)
links.push(...unconfirmedLinks)
}
}
}
}
function testWebSocket() {
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) }; }
$('#since').html(since)
function onOpen(evt) {
doSend({"op":"unconfirmed_sub"});
}
function onClose(evt) { }
function onTxs(txs) {
var links = []
for (const tx of txs) {
links.push(...onTx(tx))
}
//console.log('txs',links, txs)
// flush the buffer if not empty
if (! paused && linksBuffer.length > 0) {
for(var i=0;i<linksBuffer.length;i++){
var link = linksBuffer[i];
addNodes(link)
graph.addLink(link.from,link.to, {p: link.p, h: link.h});
}
linksBuffer = [];
}
for(var i=0;i<links.length;i++){
var link = links[i];
if(link.value > maxNodeSize){
maxNodeSize = link.value;
}
if (! paused) {
addNodes(link);
graph.addLink(link.from,link.to, {p: link.p, h: link.h});
} else{
// add links to a buffer
linksBuffer.push(link);
}
}
}
function onTx(tx) {
var links = [];
var txHash = tx.txid || tx.hash;
allTxs++;
$('#txHash').html(txHash)
$('#allTxs').html(allTxs)
// uncorfimed transactions
var inputs = tx.inputs;
var outputs = tx.outputs || tx.out;
if (isMix(inputs,outputs,txHash)) {
links = addTx(inputs, outputs, txHash, TX_TYPE.MIX, true);
}
else {
const spend = isPostmixSpend(inputs, outputs, txHash);
if (spend == 1) {
links = addTx(inputs, outputs, txHash, TX_TYPE.SPEND, true);
} else if (spend == -1) {
addTx(inputs, outputs, txHash, TX_TYPE.SPEND, false);
} else {
const tx0 = isTx0(inputs, outputs, txHash)
if (tx0 == 1) {
links = addTx(inputs, outputs, txHash, TX_TYPE.TX0, true);
} else if (tx0 == -1) {
addTx(inputs, outputs, txHash, TX_TYPE.TX0, false);
}
}
}
if (links.length>0) {
console.log('tx: ' + txHash, links)
}
return links
}
function addTx(inputs, outputs, txHash, txType, confirmed) {
const links = []
var pool = getPool(inputs, outputs, txType)
var totalValue = outputs.map(o => getValue(o)).reduce((a,b)=>a+b,0);
// generate from to
if (inputs) {
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
const addr = getAddress(input);
const value = getValue(input);
links.push({
from: addr,
to: txHash,
value: value,
tv: totalValue,
t: getNodeType(txType, true, i),
tt: txType,
p: pool,
h: txHash,
isInput: true
});
if (txType == TX_TYPE.MIX) {
ADDRESSES_MIX_INPUTS[addr] = true;
// confirm tx0s
const txidsToConfirm = ADDRESSES_TX0_OUTPUTS[addr];
confirmUnconfirmeds(txidsToConfirm, links, TX_TYPE.TX0)
delete ADDRESSES_TX0_OUTPUTS[addr];
} else if (txType == TX_TYPE.SPEND) {
if (!ADDRESSES_SPEND_INPUTS[addr]) {
ADDRESSES_SPEND_INPUTS[addr] = []
}
ADDRESSES_SPEND_INPUTS[addr].push(txHash)
}
}
}
if (outputs) {
for (var j = 0; j < outputs.length; j++) {
var output = outputs[j];
const addr = getAddress(output);
links.push({
from: txHash,
to: addr,
value: getValue(output),
tv: totalValue,
t: getNodeType(txType, false, j),
tt: txType,
p: pool,
h: txHash,
isInput: false
});
if (txType == TX_TYPE.MIX) {
ADDRESSES_MIX_OUTPUTS[addr] = true
// confirm spends
const txidsToConfirm = ADDRESSES_SPEND_INPUTS[addr];
confirmUnconfirmeds(txidsToConfirm, links, TX_TYPE.SPEND)
delete ADDRESSES_SPEND_INPUTS[addr];
} else if (txType == TX_TYPE.TX0) {
if (!ADDRESSES_TX0_OUTPUTS[addr]) {
ADDRESSES_TX0_OUTPUTS[addr] = []
}
ADDRESSES_TX0_OUTPUTS[addr].push(txHash)
}
}
}
if (!confirmed) {
LINKS_UNCONFIRMED[txHash] = links
}
console.log('add '+txType+' '+(confirmed?'confirmed':'unconfirmed')+' '+txHash)
return links
}
function onMessage(evt) {
// parse message
var msg = JSON.parse(evt.data);
//console.log('onMessage',msg)
if(msg.op == "utx"){
onTxs([msg.x])
}
//websocket.close();
}
function onError(evt) {
console.error('error: ',evt);
}
function doSend(message) {
websocket.send(JSON.stringify(message));
}
window.addEventListener("load", init, false);
window.l = layout;
window.g = graph;
window.r = renderer;
</script>
</html>