-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
1998 lines (1754 loc) · 67 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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href='fonts/opensans.css' rel='stylesheet' type='text/css'>
<link href="mainstylesheet.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="d3.v3.min.js"></script>
<script type="text/javascript" src="sha1.js"></script>
<script type="text/javascript" src="ripple-0.7.201-debug.js"></script>
<script type="text/javascript" src="selectbox/jquery.selectbox-0.2.min.js"></script>
<link href="selectbox/jquery.selectbox.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="jscrollpane/jquery.mousewheel.js"></script>
<script type="text/javascript" src="jscrollpane/jquery.jscrollpane.js"></script>
<script src="jquery.inview.js"></script>
<link type="text/css" href="jscrollpane/jquery.jscrollpane.css" rel="stylesheet" media="all" />
<title>Ripple Live Network</title>
</head>
<body>
<div class="light heading darkgray">Ripple Live Network</div>
<!-- BEGIN VISUALIZATION DIV -->
<div id="visualization" style="position:relative; border: 1px solid #c8c8c8; height:703px; pointer-events:none" class="fullwidth">
<div class="light midsize mediumgray" style="position: absolute; top: -72px; left:35px; pointer-events:auto">
ledger number: <span id="ledgernumber"></span><br/>
total ripples: <span id="totalripples"></span><br/></div>
<!-- top bar -->
<input id="focus" class="light midsize rounded topbar" style="left:35px; padding:0 10px; width:295px; height:42px; z-index:1" type="text"/>
<input id="searchButton" class="topbar" style="left:360px; width:50px; height:50px; z-index:1" type="button" value="Go" onClick="changeMode('individual'); refocus($('#focus').val().replace(/\s+/g, ''),true);"/>
<div class="topbar" style="right:35px; height:42px; width:230px; outline:none;">
<select id="currency" onchange="changeCurrency(this.value);">
<option value="XRP">All Currencies</option>
<option value="USD">USD - U.S. Dollars</option>
<option value="EUR">EUR - Euro</option>
<option value="CNY">CNY - Chinese Yuan</option>
<option value="JPY">JPY - Japanese Yen</option>
<option value="BTC">BTC - Bitcoins</option>
<option value="___">Other</option>
</select>
<input type="text" id="otherCurrency" value="other" class=" sbSelector sbHolder" onfocus="focusOtherCurrency(this);" onblur="blurOtherCurrency(this);" />
</div>
<div style="position:absolute; left:35px; top:80px; opacity:.8;">
<input style="width:25px; height:25px; font-size:12pt; pointer-events:auto;" type="button" id="zoomInButton" value="+" onclick="zoomIn();" disabled="disabled"/><br/>
<input style="width:25px; height:25px; font-size:12pt; pointer-events:auto;" type="button" value="–" onclick="zoomOut();"/>
</div>
<div id="loading" class="light large" style="color:#aaa; position:absolute; width:100%; top:100px; line-height:50px; text-align:center;">
<img src="throbber4.gif" style="vertical-align: middle;"/>
Loading...
</div>
<!-- begin information below -->
<div id="information" style="opacity:0.8; background-color:#fff; position:absolute; top:704px; width:100%; border: 1px solid #c8c8c8; margin-left:-1px; pointer-events:auto;">
<div class="tab midsize mediumgray unselectedTab" style="margin-top:-36px; margin-left:140px;" onclick="changeMode('feed');" id="feedTab">Network feed</div>
<div id="individualTab" class="tab midsize mediumgray selectedTab" style="margin-top:-35px; margin-left:-1px;" onclick="changeMode('individual',senderAddress);">Wallet info</div>
<div id="focalAddress" class="light mediumgray large" style="margin-bottom:13px; margin-top:13px; padding-left:20px; float:left;"> </div>
<div class="clearboth"></div>
<div class="fullwidth topbordered horizontalrule"></div>
<div class="light midsize mediumgray" id="leftHeading" style="width:50%; border: none; float:left; padding-left:20px;">Balances</div>
<div class="light midsize mediumgray" id="rightHeading" style="border:none; float:left;">History</div>
<div class="clearboth"></div>
<div class="fullwidth bottombordered horizontalrule"></div>
<!-- the table on the left -->
<div class="bottomlist rightbordered" style="width:49%; float:left;">
<div class="scroll-pane" id="transactionInformationContainer" style="z-index:1; width:100%; height:288px; position:absolute; background-color:#fff; display:none;">
<div style="width:100%; overflow-x:hidden;">
<div id="transactionInformation" class="light midsize mediumgray" style="width:100%%; padding:20px; display:none;"></div>
<div id="transactionFeed" class="light midsize mediumgray" style="width:100%; padding:20px; display:none;">
<table id="transactionFeedTable"></table>
</div>
</div>
</div>
<div class="scroll-pane" style="height:288px; margin-left:10px;">
<table style="width:100%; margin-top:4px;" class="outertable" id="balanceTable"></table>
</div>
</div>
<!-- the table on the right -->
<div class="bottomlist" style="width:50%; float:right;">
<div class="scroll-pane" style="height:288px;width:100%; ">
<table class="outertable" id="transactionTable"></table>
</div>
</div>
<div class="clearboth"></div>
</div><!-- end information at the bottom -->
</div><!-- END VISUALIZATION DIV -->
<!-- Javascript for the visualization, using the D3 library -->
<script type="text/javascript">
// CONSTANTS
var UNIX_RIPPLE_TIME = 946684800;
var RECURSION_DEPTH = 1;
var MAX_NUTL = 360;
var REFERENCE_NODE = 'r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV';
var HALO_MARGIN = 6;
var COLOR_TABLE = {
//currency | center | rim |
"__Z": [["#dfe0e1","#999999"], //degree 0
/*GRAY*/ ["#ebecec","#aaa9a9"], //degree 1
["#ededee","#bcbbbb"], //etc.
["#f3f4f4","#d0cece"],
["#fdfdfe","#e5e4e3"]],
"__N": [["#f05656","#ee2d2c"],
/*RED*/ ["#f37a6f","#f16249"],
["#f6998b","#f5886d"],
["#fab9ac","#f9ad95"],
["#fddad1","#fcd4c4"]],
"BTC": [["#e19e41","#b76f2f"],
/*ORANGE*/["#e5af65","#c38a57"],
["#e9c189","#d0a57e"],
["#edd2ad","#dcbfa6"],
["#f1e4d1","#e9dacd"]],
"CNY": [["#fcf5a1","#fedb3d"],
/*YELLOW*/["#fdf7b4","#ffe069"],
["#fdf7c4","#ffe68d"],
["#fefad8","#ffed83"],
["#fffcea","#fff5d6"]],
"USD": [["#99cc66","#669940"],
/*LIME*/ ["#acd585","#82a85d"],
["#c0dea1","#9eb880"],
["#d4e8be","#bbcba4"],
["#e8f2dd","#dae1cd"]],
"AUD": [["#8dc198","#609869"],
/*GREEN*/ ["#a2cbab","#7eab85"],
["#b7d6bd","#9cbda1"],
["#cbe0d0","#b9d0bd"],
["#e0ebe2","#d7e2d9"]],
"XRP": [["#55a7cc","#346aa9"],
/*BLUE*/ ["#83b8d6","#5083b9"],
["#a7cae1","#7ba1cb"],
["#d0e1ed","#a3c2dd"],
["#f2f6fa","#cee8f1"]],
"___": [["#6566ae","#363795"], //I.e., any other currency.
/*INDIGO*/["#7e7cbb","#5855a5"],
["#9896c9","#7a74b6"],
["#b6b4da","#9e99cb"],
["#d7d6eb","#c9c6e3"]],
"CAD": [["#8e68ad","#673695"],
/*VIOLET*/["#9f80ba","#7d58a5"],
["#8e68ad","#673695"],
["#c8b8da","#b29ecc"],
["#e0d8eb","#d4cae4"]],
"EUR": [["#b76e99","#863d66"],
/*PINK*/ ["#c389ab","#9c6283"],
["#d0a4be","#b2879f"],
["#dcbfd0","#c9abbc"],
["#d9dae3","#dfd0d8"]]};
var HIGH_SATURATION_COLORS = {
"__N": "#f00", //RED
"BTC": "#fa0", //ORANGE
"CNY": "#af0", //YELLOW
"USD": "#0f0", //LIME
"AUD": "#0fa", //GREEN
"XRP": "#0af", //BLUE
"___": "#00f", //INDIGO
"CAD": "#a0f", //VIOLET
"EUR": "#f0a" //PINK
};
var HEX_TO_PERCENT = {"0":0,"a":0.67,"f":1};
var REQUEST_REPETITION_INTERVAL = 8*1000; //milliseconds
var param = window.location.hash.replace(/\W/g, '');
var alreadyFailed = false;
var focalNode;
var transaction_id;
var changingFocus = false;
if (param == "") {
focalNode = REFERENCE_NODE;
} else if (param.charAt(0) == "r" ) {
focalNode = param;
} else if ("0123456789ABCDEF".indexOf(param.charAt(0)) != -1) {
transaction_id = param;
} else if (param.charAt(0) == "u" && Sha1.hash(param) == "7d0b25cc0abdcc216e9f26b078c0cb5c9032ed8c") {
//Easter egg!
RECURSION_DEPTH = 999999999;
focalNode = REFERENCE_NODE;
} else {
focalNode = REFERENCE_NODE;
}
function gotoThing() {
var string = $('#focus').val().replace(/\s+/g, '');
if (string.length === 64) {
console.log("HELLO!");
eraseGraph();
window.location.hash = string;
remote.request_tx(string, handleIndividualTransaction);
} else {
changeMode('individual');
refocus(string,true);
}
}
var lastFocalNode = REFERENCE_NODE;
var currentCurrency = "XRP";
var currentLedger = {ledger_current_index: 2011754};
var w = 935; //Width
var h = 1085; //Height
var hh = 710; //Height above the bottom bar
var nodes = [ {x:w/2, y:hh/2, account:{Account:focalNode, Balance:0}, trustLines:[], balances:{} }];
var le_links = [];
var nodeMap = {};
nodeMap[focalNode] = 0;
var degreeMap = {};
degreeMap[focalNode] = 0;
var expandedNodes = {};
var provisionallyExpandedNodes = {};
var txx;
var firstTime = true;
// Setup ripple-lib
var Remote = ripple.Remote;
var remote = new Remote({
trace: false,
trusted: true,
local_signing: true,
connection_offest: 60,
servers: [{
host: 's1.ripple.com'
, port: 443
, secure: true, pool: 3
}]
});
//Opening sequence:
remote.connect(function() {
//Subscriptions
remote.on('ledger_closed', function(x,y){
currentLedger = x;
$("#ledgernumber").text(commas(parseInt(currentLedger.ledger_index)));
remote.request_ledger('closed', handleLedger);
});
remote.on('transaction_all', handleTransaction);
//Get current ledger
remote.request_ledger('closed', handleLedger);
if (firstTime) {
if (transaction_id && transaction_id!="") {
nodeMap = {};
degreeMap = {};
nodes = [];
$('#focus').val(transaction_id);
remote.request_tx(transaction_id, handleIndividualTransaction);
} else {
lastFocalNode = REFERENCE_NODE;
expandNode(focalNode);
addNodes(0);
serverGetInfo(focalNode);
}
}
firstTime = false;
});
var pendingRequests = {};
var requestRepetitionInterval = setInterval(function(){
var now = new Date().getTime();
var idsToDelete = [];
var entriesToAdd = {};
for (var id in pendingRequests) {
if (pendingRequests.hasOwnProperty(id)) {
var req = pendingRequests[id];
if (req.timestamp + REQUEST_REPETITION_INTERVAL <= now) {
console.log("Repeating request");
var newID = req.func();
entriesToAdd[newID] = {func: req.func, timestamp:now};
idsToDelete.push(id);
}
}
}
for (var i=0; i<idsToDelete.length; i++) {
delete pendingRequests[idsToDelete[i]];
}
for (var newID in entriesToAdd) {
if (entriesToAdd.hasOwnProperty(newID)) {
pendingRequests[newID] = entriesToAdd[newID];
}
}
}, REQUEST_REPETITION_INTERVAL);
//Repeatable methods for fetching from server
function serverGetLines(address) {
if ($.isEmptyObject(nodes[nodeMap[address]].trustLines)) {
//Get trust lines for address ? ??current?
var rral = (function() {return function() {
var x = remote.request_account_lines(address, 0, 0, handleLines);
return x.message.id;
}})();
var reqID = rral();
pendingRequests[reqID] = {
func:rral,
timestamp:(new Date().getTime())
}
} else {
addConnections(address, nodes[nodeMap[address]].trustLines);
}
}
function serverGetInfo(address) {
//console.log("serverGetInfo", address);
if (nodes[nodeMap[address]] && nodes[nodeMap[address]].account.index) {
// Don't do anything if we already have information about this account.
// TODO: Why does this never happen?
} else {
//Get account info for address
var rrai = (function() {return function() {
var x = remote.request_account_info(address, handleAccountData);
return x.message.id;
}})();
var reqID = rrai();
pendingRequests[reqID] = {
func:rrai,
timestamp:(new Date().getTime())
};
}
}
var TRANSACTION_PAGE_LENGTH = 13;
function getNextTransactionPage() {
//request transactions for the current account, with offset = nodes[nodeMap[address]].transactions.length
var rrat = (function() {return function(){
var x = remote.request_account_tx({
account: focalNode,
limit: TRANSACTION_PAGE_LENGTH,
ledger_index_min: -1,
ledger_index_max: -1,
forward: false,
marker: nodes[nodeMap[focalNode]].transactionMarker
}, handleAccountTransactions);
return x.message.id;
}})();
var reqID = rrat();
pendingRequests[reqID] = {
func:rrat,
timestamp:(new Date().getTime())
};
//when the answer comes back, see if it's new information.
//if so, update WITH THE NEW INFO ONLY (i.e., don't clear the whole table, only do
//$("#transactionThrobber").remove();
//and add the new stuff.
}
//Handlers
function handleLines(err, obj) {
delete pendingRequests[this.message.id];
if (err && err.remote && (err.remote.error === "actNotFound" || err.remote.error === "actMalformed") ) {
$("#loading").text("Account not found!").css("color","#a00");
} else {
/*if () {
//serverGetLines(address);
addConnections(obj.account, obj.lines);
}*/
//var shouldExpand = (mode=="transaction") || obj.lines.length<MAX_NUTL || confirm('This node has '+obj.lines.length+' unseen trust lines. Expanding it may slow down your browser. Are you sure?');
//addConnections(obj.account, obj.lines, !shouldExpand);
addConnections(obj.account, obj.lines);
//if (
//addConnections(obj.account, obj.lines);
}
}
function handleTransaction(obj) {
var tx = obj.transaction;
tx.meta = obj.meta;
$("#transactionFeedTable").prepend(renderTransaction(tx));
if (obj.transaction.TransactionType == "Payment") {
animateTransaction(tx);
}
}
function handleLedger(err, obj) {
currentLedger = obj.ledger;
$("#ledgernumber").text(commas(parseInt(currentLedger.ledger_index)));
$("#totalripples").text(commas(parseInt(currentLedger.total_coins)/1000000));
}
function handleAccountData(err, obj) {
delete pendingRequests[this.message.id];
if (err && err.remote && (err.remote.error === "actNotFound" || err.remote.error === "actMalformed" )) {
$("#loading").text("Account not found!").css("color","#a00");
} else {
if ($.isEmptyObject(obj.account_data)) {
alert("This address is not valid!");
console.log(obj);
refocus(lastFocalNode,true);
} else {
var n = nodes[nodeMap[obj.account_data.Account]];
n.account = obj.account_data; //XXXX Uncaught TypeError: Cannot set property 'account' of undefined
if (currentCurrency == "XRP") { // Change the size of the circles, and recalculate the arrows.
updated = svg.select("g#nodeGroup").select("circle#_"+obj.account_data.Account);
updated.attr("r", nodeRadius(n));
svg.select("g#haloGroup").select("circle#halo_"+obj.account_data.Account).attr("r", HALO_MARGIN+nodeRadius(n));;
}
if (obj.account_data.Account == focalNode) {
//Update the XRP listing on the table below. (But don't rewrite the whole table)
$("#xrpBalance").text(commas(n.account.Balance/1000000));
}
}
}
}
function handleAccountTransactions(err, obj) {
delete pendingRequests[this.message.id];
var n = nodes[nodeMap[obj.account]];
var noMoreTransactions = true;
if (n.transactions) { //XXXX Uncaught TypeError: Cannot read property 'transactions' of undefined
//You don't want to add the same set of transactions more than once.
//So, only add the transactions if one of the following is true:
//1. We have no marker stored locally.
//2. The message had no marker, and we are not yet finished with the list.
//3. The message did have a marker, but its ledger number is less than that of the locally stored marker.
if (!n.marker || (!obj.marker && !n.transactionsFinished) || (obj.marker && n.marker.ledger>obj.marker.ledger)) {
n.transactions.push.apply(n.transactions, obj.transactions);
}
} else {
n.transactions = obj.transactions;
}
if (obj.marker) {
n.transactionMarker = obj.marker;
} else {
n.transactionsFinished = true;
}
if (obj.account == focalNode) {
updateTransactions(focalNode, true); //appending=true
}
}
function handleIndividualTransaction(err, obj) {
delete pendingRequests[this.message.id];
txx = obj;
changeMode("transaction", txx);
}
// MODE CHANGING
var mode = "individual";
var senderAddress;
function changeMode(newMode, data) {
if (mode != newMode) {
if (mode=="individual") {
exitIndividualMode();
} else if (mode=="transaction") {
exitTransactionMode();
} else if (mode=="feed") {
exitFeedMode();
}
if (newMode=="individual") {
enterIndividualMode(data);
} else if (newMode=="transaction") {
enterTransactionMode(data);
} else if (newMode=="feed") {
enterFeedMode();
}
mode = newMode;
}
}
function enterIndividualMode(data) {
if (mode != "individual") {
$("#leftHeading").text("Balances");
$("#rightHeading").text("History");
$("#focalAddress").css("visibility","visible");
$("#balanceTable").css("visibility","visible");
$("#transactionTable").css("visibility","visible");
$("#transactionInformationContainer").css("display","none"); //This is here because it is used by both feed and transaction modes.
$("#feedTab").addClass("unselectedTab").removeClass("selectedTab").css("visibility","visible");
$("#individualTab").removeClass("unselectedTab").addClass("selectedTab").css("visibility","visible");
if (data) {
expandNode(data);
senderAddress = false;
}
mode = "individual";
}
}
function exitIndividualMode() {
if (mode == "individual") {
$("#rightHeading").text("");
$("#focalAddress").css("visibility","hidden");
$("#balanceTable").css("visibility","hidden");
$("#transactionTable").css("visibility","hidden");
$("#transactionInformationContainer").css("display","inherit");
}
}
function enterFeedMode() {
if (mode != "feed") {
$("#feedTab").removeClass("unselectedTab").addClass("selectedTab");
$("#individualTab").addClass("unselectedTab").removeClass("selectedTab");
$("#transactionFeed").css("display","inherit");
$("#leftHeading").text("Live transaction feed");
mode = "feed";
}
}
function exitFeedMode() {
if (mode == "feed") {
$("#transactionFeed").css("display","none");
}
}
function enterTransactionMode(tx) {
if (mode != "transaction") {
eraseGraph();
txx = tx;
$("#transactionInformation").html(txDescription(tx));
var currency;
if (tx.Amount.currency) {
currency = tx.Amount.currency;
} else {
currency = "XRP";
}
var option = $("select#currency").find("option[value="+currency+"]");
if (option.html()) {
$("select#currency").selectbox("change", currency, option.html());
} else {
$("select#currency").selectbox("change", "___", "SSGSGS");
$("#otherCurrency").attr("value",currency);
$('#otherCurrency').css('font-style','inherit').css('color','inherit');
changeCurrency("___");
}
senderAddress = tx.Account;
walkPaths(tx, true);
setTimeout(function(){animateTransaction(tx);}, 2000);
$("#leftHeading").html("Transaction information <input type='button' style='position:absolute; top:56px; left:200px;' onclick='animateTransaction(txx);' value='Animate'/>");
$("#feedTab").addClass("unselectedTab").removeClass("selectedTab");
$("#individualTab").addClass("unselectedTab").removeClass("selectedTab");
$("#transactionInformation").css("display","inherit");
mode = "transaction";
}
}
function exitTransactionMode() {
if (mode == "transaction") {
$("#transactionInformation").css("display","none");
}
}
function walkPaths(tx, clearing) {
var anyNewNodes = false;
var numberOfExistingNodes = nodes.length-1;
if ("undefined" == typeof nodeMap[tx.Account]) {
nodes.push({x:w*Math.random(), y:hh*Math.random(), account:{Account:tx.Account, Balance:0}, trustLines:[], balances:{} }); //
nodeMap[tx.Account] = nodes.length-1;
degreeMap[tx.Account] = clearing ? 0 : 1;
anyNewNodes = true;
}
if (tx.Paths) {
for (var i=0; i<tx.Paths.length; i++) {
for (var j=0; j<tx.Paths[i].length; j++) {
var address = tx.Paths[i][j].account;
if ("undefined" == typeof nodeMap[address]) {
if (address) {
nodes.push({x:w*Math.random(), y:hh*Math.random(), account:{Account:address, Balance:0}, trustLines:[], balances:{} });
nodeMap[address] = nodes.length-1;
degreeMap[address] = 1;
console.log("Added node");
anyNewNodes = true;
}
}
}
}
}
if ("undefined" == typeof nodeMap[tx.Destination]) {
nodes.push({x:w*Math.random(), y:hh*Math.random(), account:{Account:tx.Destination, Balance:0}, trustLines:[], balances:{} });
nodeMap[tx.Destination] = nodes.length-1;
degreeMap[tx.Destination] = clearing ? 0 : 1;
anyNewNodes = true;
}
if (anyNewNodes) {
addNodes(1);
}
if (clearing) { //Do this if we just cleared the graph and are displaying the transaction.
for (var i=0; i<nodes.length; i++) {
serverGetInfo(nodes[i].account.Account);
serverGetLines(nodes[i].account.Account);
}
} else if (anyNewNodes) { //Do this if we're displaying in place:
//Note: This will NOT display new connections between already existing nodes, even if the transaction uses them.
displayingTransactionInPlace = true;
for (var i=numberOfExistingNodes; i<nodes.length; i++) {
serverGetInfo(nodes[i].account.Account);
serverGetLines(nodes[i].account.Account);
}
}
}
function eraseGraph() {
zoomLevel = 1;
translationX = 0;
translationY = 0;
panAndZoom();
$("#zoomInButton").attr("disabled","disabled");
svg.select("g#nodeGroup").selectAll("circle.node").data([]).exit().remove();
svg.select("g#linkGroup").selectAll("line") .data([]).exit().remove();
svg.select("g#haloGroup").selectAll("circle.halo").data([]).exit().remove();
svg.select("g#arrowheadGroup").selectAll("path.arrowhead").data([]).exit().remove();
nodes = [];
le_links = [];
nodeMap = {};
expandedNodes = {};
provisionallyExpandedNodes = {};
animatorLinks = [];
$("#loading").css("display","block").css("color","#aaa");;
$("#loading").html('<img src="throbber4.gif" style="vertical-align: middle;" /> Loading...');
}
// DATA-TO-HTML FUNCTIONS
function renderTransaction(tx) {
var transactionType;
var from = tx.Account;
var to = null;
var amount = null;
var currency = null;
var secondAmount = null;
var secondCurrency = null;
if (tx.TransactionType == "Payment") {
amount = tx.meta.DeliveredAmount || tx.Amount;
transactionType = "send";
to = tx.Destination;
} else if (tx.TransactionType == "TrustSet") {
amount = tx.LimitAmount;
transactionType = "trustout";
to = tx.LimitAmount.issuer;
} else if (tx.TransactionType == "OfferCreate") {
transactionType = "offerout";
amount = tx.TakerGets;
secondAmount = tx.TakerPays;
} else if (tx.TransactionType == "OfferCancel") {
transactionType = "canceloffer";
} else {return;}
if (amount) {
if (amount.currency) {
currency = amount.currency;
amount = amount.value;
} else {
currency = "XRP";
amount = amount/1000000;
}
}
if (secondAmount) {
if (secondAmount.currency) {
secondCurrency = secondAmount.currency;
secondAmount = secondAmount.value;
} else {
secondCurrency = "XRP";
secondAmount = secondAmount/1000000;
}
}
transactionMap[tx.hash] = tx;
return ('<tr>'+
'<td style="width:80px;">'+absoluteTime(tx.date)+'</td>'+
'<td style="width:1px;">'+clickableAccountSpan(from)+'</td>'+
'<td style="width:40px;"><div '+(transactionType=='send'?'oncontextmenu="animateInPlaceWithHash(\''+tx.hash+'\');return false;" onclick="showTransactionWithHash(\''+tx.hash+'\')"':'')+' class="'+transactionType+' icon" title="'+txAltText[transactionType]+'"> </div></td>'+
( to||secondAmount ?
'<td style="width:1px;"><span class="bold amount small">'+commas(amount)+'</span> <span class="light small darkgray">'+currency+'</span></td>'+
'<td style="text-align:center; width:20px;"><i class="light small darkgray">'+
( to ?
'to</i></td>'+
'<td style="width:1px;">'+clickableAccountSpan(to)+'</td>'
:
'for</i></td>'+
'<td style="width:1px;"><span class="bold amount small">'+commas(secondAmount)+'</span> <span class="light small darkgray">'+secondCurrency+'</span></td>'
)
:
'<td colspan=3></td>'
)+
'</tr>');
}
function clickableAccountSpan(address) {
var o = "<span class='light address' style='cursor:pointer;' "+
"onmouseover='lightenAddress(\""+address+"\");' "+
"onmouseout='darkenAddress(\""+address+"\");' "+
"onclick='expandNode(\""+address+"\");'>"+
address+"</span>";
return o;
}
function txDescription(result) {
console.log("TX INFO:",result);
var xrpExpense;
if (result.meta) {
for (var i=0; i<result.meta.AffectedNodes.length; i++) {
var an = result.meta.AffectedNodes[i];
if (an.ModifiedNode && an.ModifiedNode.LedgerEntryType==="AccountRoot" && an.ModifiedNode.FinalFields.Account===result.Account) {
xrpExpense = {before:an.ModifiedNode.PreviousFields.Balance/1000000 , after:an.ModifiedNode.FinalFields.Balance/1000000};
break;
}
}
}
var amount = result.meta.DeliveredAmount || result.Amount;
var output = (amount?"<b>Amount:</b> <span class='amount'>"+
(amount.currency ? commas(amount.value)+" "+amount.currency : commas(amount/1000000)+" XRP")+"</span><br/>"+
(amount.issuer ? "<b>Issuer:</b> "+clickableAccountSpan(amount.issuer)+"<br/>" : ""):"")+
"<b>Path:</b><ul>"+
(function(){
var output = "";
if (result.Paths) {
for (var i=0; i<result.Paths.length; i++) {
var listItem = "<li>"+clickableAccountSpan(result.Account) + " → ";
for (var j=0; j<result.Paths[i].length; j++) {
if (result.Paths[i][j].account) {
listItem += clickableAccountSpan(result.Paths[i][j].account) + " → ";
}
}
listItem += (clickableAccountSpan(result.Destination) + "</li>");
output += listItem;
}
} else {
output += ("<li>"+clickableAccountSpan(result.Account)+ " → "+clickableAccountSpan(result.Destination)+"</li>");
}
return output;
})()+
"</ul>"+
(result.meta ? "<b>Result:</b> "+(result.meta.TransactionResult=="tesSUCCESS"?"<span>":"<span style='color:#900;'>")+result.meta.TransactionResult+"</span><br/>" : "")+
(xrpExpense||xrpExpense===0 ? "<b>XRP change:</b> "+commas(xrpExpense.before) + " XRP → "+commas(xrpExpense.after)+" XRP ("+(xrpExpense.after>=xrpExpense.before?"+":"–")+commas(Math.round(1000000*Math.abs(xrpExpense.before-xrpExpense.after))/1000000)+" XRP)<br/>" : "")+
(result.date ? "<b>Date:</b> "+absoluteDateOnly(result.date)+" "+absoluteTimeOnly(result.date)+"<br/>" : "")+
(result.InvoiceID ? "<b>Invoice ID:</b> <tt>"+result.InvoiceID+"</tt><br/>" : "")+
(result.DestinationTag ? "<b>Destination tag:</b> "+result.DestinationTag+"<br/>" : "")+
"<b>Hash:</b> <tt>"+result.hash+"</tt><br/>"+
(result.inLedger ? "<b>Ledger:</b> "+result.inLedger+"<br/>" : "")+
"<b>Signing key:</b> <tt>"+result.SigningPubKey+
"</tt><br/><b>Signature:</b><br/><div class='bigString' style='width:"+result.TxnSignature.length*4+"px;'>"+result.TxnSignature+"</div>";
return output;
}
function currentCurrencyBalance(accountNode) {
var output;
if (currentCurrency == "XRP") {
output = accountNode.account.Balance;
} else {
output = accountNode.balances[currentCurrency];
if (!output) { output = 0; }
}
return output;
}
var displayingTransactionInPlace = false;
function addConnections(origin, trustLines) {
var transactionMode = (mode=="transaction") || displayingTransactionInPlace;
$("#loading").css("display","none");
//Receive an array of the format:
//[{"account":"rnziParaNb8nsU4aruQdwYE3j5jUcqjzFm","balance":"0","currency":"BTC","limit":"0","limit_peer":"0.25","quality_in":0,"quality_out":0},
//{"account":"rU5KBPzSyPycRVW1HdgCKjYpU6W9PKQdE8","balance":"0","currency":"BTC","limit":"0","limit_peer":"10","quality_in":0,"quality_out":0}]
nodes[nodeMap[origin]].trustLines = trustLines; //XXXX Uncaught TypeError: Cannot set property 'trustLines' of undefined
nodes[nodeMap[origin]].balances = getBalances(origin);
if (origin == focalNode) {
updateInformation(origin);
}
if (currentCurrency != "XRP") { // Change the size of the circle, if we needed to wait until now to figure out its balance (i.e. we're looking at a currency other than XRP.)
svg.select("g#nodeGroup")
.select("circle#_"+origin)
.attr("r", nodeRadius(nodes[nodeMap[origin]]) );
svg.select("g#haloGroup")
.select("circle#halo_"+origin)
.attr("r", HALO_MARGIN+nodeRadius(nodes[nodeMap[origin]]) );
}
if ((degreeMap[origin] < RECURSION_DEPTH || ( degreeMap[origin] == RECURSION_DEPTH) && transactionMode) && (transactionMode || trustLines.length<MAX_NUTL || confirm('This node has '+trustLines.length+' unseen trust lines. Expanding it may slow down your browser. Are you sure?')) ) {
if (!transactionMode) {
expandedNodes[origin] = true;
} else {
provisionallyExpandedNodes[origin] = true;
}
var newNodes = [];
var newLinks = [];
for (var i=0; i<trustLines.length; i++) {
var linkWasToExisting = false;
// add trustLines[i]["account"] to the list of nodes, if it's not on it already.
// add a link from the current node to trustLines[i]["account"], if it's not there already.
trustLine = trustLines[i];
account = trustLine["account"];
// Fetch the node corresponding to the counterparty of this trust line,
// or if it's not on the list yet, create one and add it to the list.
if ("undefined" == typeof nodeMap[account]) {
if (!transactionMode && (parseFloat(trustLine.limit) != 0.0 || parseFloat(trustLine.limit_peer) != 0.0) ) {
nodeMap[account]=nodes.length;
degreeMap[account] = degreeMap[origin] + 1;
var angle = Math.random() * 6.283185307179586;
var radius= Math.random() * 100;
var node = {
x:nodes[nodeMap[origin]].x+Math.cos(angle)*radius,
y:nodes[nodeMap[origin]].y+Math.sin(angle)*radius,
account: {
Account:account,
Balance:"0",
},
trustLines: [],
balances: {}
}
newNodes.push(node);
nodes.push(node);
//Only add the node if the trust line is non-zero.
degreeMap[account] = degreeMap[origin] + 1;
serverGetInfo(account); //If this node is not on the list yet, we're going to need to get the info and trustLines for it.
serverGetLines(account);
}
} else {
var node = nodes[nodeMap[account]];
linkWasToExisting = true;
}
// Now, create links to all of the counterparties that have not been expanded (ie., had their links displayed.). If we're in transaction mode, only add links to existing nodes.
if ( (!transactionMode && !expandedNodes[account]) || (transactionMode && linkWasToExisting && !provisionallyExpandedNodes[account]) ) {
var link={};
function goon(link) {
if (parseFloat(trustLine.limit) != 0.0 && parseFloat(trustLine.limit_peer) != 0.0) {
link.strength = 0.5;
} else {
link.strength = 1;
}
link.currency=trustLines[i].currency;
le_links.push(link);
}
if (parseFloat(trustLine.limit) != 0.0) {
link.source=nodes[nodeMap[ origin ]];
link.target=node;
link.value= parseFloat(trustLine.limit);
goon(link);
}
if (parseFloat(trustLine.limit_peer) != 0.0) {
var link={};
link.target=nodes[nodeMap[ origin ]];
link.source=node;
link.value= parseFloat(trustLine.limit_peer);
goon(link);
}
}
if (linkWasToExisting) {
//If we're adding a trust line to an already-existing node, check that node again to see if we should put a halo on it.
svg.select("g#haloGroup").select("circle#halo_"+account)
.style("stroke", (numberOfUnseenTrustLines(node)>0)?"#aaa":"none" );
}
}
}
reassignColors(origin);
addNodes(degreeMap[origin]+1);
//should we add a halo to origin?
svg.select("g#haloGroup").select("circle#halo_"+origin)
.style("stroke", (numberOfUnseenTrustLines(nodes[nodeMap[origin]])>0)?"#aaa":"none" );
displayingTransactionInPlace = false; //really?
}
var svg = d3.select("#visualization")
.append("svg:svg")
.attr("width", "100%")
.attr("height", h).attr("pointer-events", "all")
.style("background-color", "#fff").on("click",function(){
if($('.sbOptions').css("display") == "block") {
$('.sbToggle').trigger('click');
}
if($('#otherCurrency').css("display") == "block") {
$('#otherCurrency').trigger('blur');
}
})
.style("float","left")//.style({"border-left":"1px solid #c8c8c8", "border-right":"1px solid #c8c8c8", "border-top":"1px solid #c8c8c8"})
.style("margin-right","10").call(d3.behavior.drag().on("drag", redraw));
var zoomLevel = 1;
var translationX = 0;
var translationY = 0;
var panOffset = [0,0];
function redraw() {
translationX += d3.event.dx;
translationY += d3.event.dy;
panAndZoom();
}
function zoomOut() {
if (zoomLevel >= 1) {
$("#zoomInButton").removeAttr("disabled");
}
translationX += (w/8 * zoomLevel);
translationY += (hh/8 * zoomLevel);
panOffset[0] -= (w/8 * zoomLevel);
panOffset[1] -= (hh/8 * zoomLevel);
zoomLevel *= 0.75;
panAndZoom();
}
function zoomIn() {
zoomLevel /= 0.75;
if (zoomLevel >= 1) {
zoomLevel = 1;
$("#zoomInButton").attr("disabled","disabled");
}
translationX -= (w/8 * zoomLevel);
translationY -= (hh/8 * zoomLevel);
panOffset[0] += (w/8 * zoomLevel);
panOffset[1] += (hh/8 * zoomLevel);
panAndZoom();
}
function panAndZoom() {
linkGroup.attr ("transform","translate(" + [translationX,translationY] + "),scale("+zoomLevel+")");
nodeGroup.attr ("transform","translate(" + [translationX,translationY] + "),scale("+zoomLevel+")");
haloGroup.attr ("transform","translate(" + [translationX,translationY] + "),scale("+zoomLevel+")");
arrowheadGroup.attr("transform","translate(" + [translationX,translationY] + "),scale("+zoomLevel+")");
}
var defs = svg.append("defs");
function defineRadialGradient(name, innerColor, outerColor) {
var radGrad = defs.append("radialGradient")
.attr("id", name)
.attr("fx", "50%")
.attr("fy", "50%")
.attr("r", "100%")
.attr("spreadMethod", "pad");
radGrad.append("stop")
.attr("offset","0%")
.attr("stop-color",innerColor)
.attr("stop-opacity","1");
radGrad.append("stop")
.attr("offset","100%")
.attr("stop-color",outerColor)
.attr("stop-opacity","1");
}
for (var cur in COLOR_TABLE) {
var shades = COLOR_TABLE[cur];
for (var i=0; i<shades.length; i++) {
defineRadialGradient("gradient"+cur+i, shades[i][0], shades[i][1]);
}
}
function defineFilter(name, red, green, blue) {
var filter = defs.append("filter").attr("id",name).attr("x","-200%").attr("y","-200%").attr("width","800%").attr("height","800%");
var fct = filter.append("feComponentTransfer").attr("in","SourceAlpha");
fct.append("feFuncR").attr("type","discrete").attr("tableValues",red+" 1");
fct.append("feFuncG").attr("type","discrete").attr("tableValues",green+" 1");
fct.append("feFuncB").attr("type","discrete").attr("tableValues",blue+" 1");
filter.append("feGaussianBlur").attr("stdDeviation","20");
filter.append("feOffset").attr("dx","0").attr("dy","0").attr("result","shadow");
filter.append("feComposite").attr("in","SourceGraphic").attr("in2","shadow").attr("operator","over");
}