-
Notifications
You must be signed in to change notification settings - Fork 5
/
xemmessage.html
578 lines (480 loc) · 15.1 KB
/
xemmessage.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
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
<title>XEMMessage</title>
<!-- <script src="http://code.jquery.com/jquery-1.10.2.js"></script> -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
var POLO_JPY_XEM;
var lastId = "";
var lastHash = "";
var sum_income = 0;
var sum_outcome = 0;
var account_publicKey;
var isHashAccess = false;
var targetNode = "";
$(function() {
function replacer( str, word , size ) {
var SearchString = '(' + word.replace( ',', '|' ) + ')';
var RegularExp = new RegExp( SearchString, "g" );
var ReplaceString = "<span class='right' style='color:red; font-size:" + size + "px; background-color: yellow;'>$1</span>";
var ResString = str.replace( RegularExp , ReplaceString );
return ResString;
}
$('#search_btn').click(function(){
$('table#transfers tbody *').remove();
sum_income = 0;
sum_outcome = 0;
lastHash = "";
lastId = "";
catapult(getNemTransferData,bulk);
return false;
})
function getNodes(){
var d = $.Deferred();
$.ajax({url: "https://s3-ap-northeast-1.amazonaws.com/xembook.net/data/v3/node.json" ,type: 'GET',timeout: 1000}).then(
function(res){
var nodes;
if(isHashAccess){
nodes = res["apostille"];
}else{
nodes = res["http"];
}
d.resolve(nodes);
},
function(res){
d.resolve(["alice2.nem.ninja","alice3.nem.ninja","alice4.nem.ninja","alice5.nem.ninja","alice6.nem.ninja"]);
}
);
return d.promise();
}
function connectNode(nodes,query2,getData,nodeIndex){
if(targetNode == "" || isHashAccess){
targetNode = nodes[Math.floor(Math.random() * nodes.length)] + ":7890";
}
var d = $.Deferred();
var res = $.ajax({url: "http://" + targetNode + query2 ,type: 'GET',timeout: 3000}).then(
function(res){
d.resolve(res);
}
).catch(
function(res){
if(lastHash != ""){
console.log("ハッシュアクセスモードに切り替えます。");
isHashAccess = true;
}
return catapult(getData,nodeIndex + 1);
}
);
return d.promise();
}
function sendAjax(URL){
return $.ajax({url: URL ,type: 'GET'});
}
var date_format = function(num) {
return ( num < 10 ) ? '0' + num : num;
};
var dispTimeStamp = function(timeStamp){
var NEM_EPOCH = Date.UTC(2015, 2, 29, 0, 6, 25, 0);
var d = new Date(timeStamp * 1000 + NEM_EPOCH);
var strDate = d.getFullYear()%100
+ "-" + date_format( d.getMonth() + 1 )
+ '-' + date_format( d.getDate() )
+ ' ' + date_format( d.getHours() )
+ ':' + date_format( d.getMinutes() ) ;
return strDate;
}
var dispAmount = function(amount){
if(amount != 0){
if(amount < 1000000){
return "0." + paddingright(amount.toString(),0,6);
}else{
var str_amount = amount.toString();
var r = str_amount.slice(-6);
var l = str_amount.substring(0,str_amount.length - 6);
l = l.replace( /(\d)(?=(\d\d\d)+(?!\d))/g, '$1,');
}
}else{
return "0.000000";
}
return l + "." + r;
}
function paddingright(val,char,n){
for(; val.length < n; val= char + val);
return val;
}
var address ="";
var bulk = 10;
if (1 < document.location.search.length) {
var query = document.location.search.substring(1);
var prms = query.split('&');
var item = new Object();
for (var i = 0; i < prms.length; i++) {
var elm = prms[i].split('=');
var idx = decodeURIComponent(elm[0]);
var val = decodeURIComponent(elm[1]);
item[idx] = decodeURIComponent(val);
}
address = item["address"];
if(item["bulk"] == "" || item["bulk"] === undefined){
bulk = 10;
}else{
bulk = Number(item["bulk"]);
}
}
if( address == ""){
var address = prompt('NEMアドレスを入力してください',address);
}
address = address.replace( /-/g , "" ).toUpperCase();
var getNemAccountData = function(nodeIndex){
var res = getNodes()
.then(function(nodes){
account_get_address_query = "/account/get?address=" + address;
return connectNode(nodes,account_get_address_query,getNemAccountData,nodeIndex);
}).then(function(result){
var account = result.account;
var meta = result.meta;
account_balance = account.balance;
account_balance = account_balance.toString();
account_publicKey = account.publicKey;
if(account_balance != "0"){
account_balance = dispAmount(account_balance);
}else{
account_balance = "0.000000";
}
var account_importance = account.importance * 100000000;
account_importance = Math.round( account_importance );
account_importance /= 10000;
$("#account_address" ).text(account.address.substring(0,6) + "-" +account.address.substring(6,12) + "-" + account.address.substring(12,18)+"..." );
$("#account_balance" ).text(account_balance + "XEM");
$("#account_importance").text(account_importance);
$("#transfers_nembex" ).attr("href", "http://explorer.nemchina.com/#/s_account?account=" + account.address);
$("#xemtax" ).attr("href", "xemtax.html?address=" + account.address);
$("#xembook" ).attr("href", "/?address=" + account.address);
$("#xemreceiver" ).attr("href", "xemreceiver2.html?address=" + account.address);
$.when(
sendAjax("https://poloniex.com/public?command=returnTicker"),
sendAjax("https://blockchain.info/ticker?cors=true")
)
.done(function(res1, res2) {
POLO_JPY_XEM = res1[0].BTC_XEM.last * res2[0].JPY.last;
var polo_price = account.balance / 1000000 * POLO_JPY_XEM;
polo_price = String(Math.round(polo_price)).replace( /(\d)(?=(\d\d\d)+(?!\d))/g, '$1,');
POLO_JPY_XEM = Math.round(POLO_JPY_XEM * 1000) / 1000;
$("#polo_price").text(polo_price + "円 (" + POLO_JPY_XEM + "JPY/XEM換算)");
$("#polo_lastprice").text( POLO_JPY_XEM + "円 / XEM");
})
.fail(function(xhr, textStatus, errorThrown) {
alert("時価の取得に失敗しました。");
});
});
return res;
}
var getNemTransferData = function(nodeIndex){
var res = getNodes()
.then(function(nodes){
account_transfers_all_query = "/account/transfers/all?address=" + address;
if(isHashAccess){
if(lastHash != ""){
account_transfers_all_query += "&hash=" + lastHash;
}
}else{
if(lastId != ""){
account_transfers_all_query += "&id=" + lastId;
}
}
return connectNode(nodes,account_transfers_all_query,getNemTransferData,nodeIndex);
}).then(function(res){
lastId = res.data[res.data.length - 1].meta.id;
lastHash = res.data[res.data.length - 1].meta.hash.data;
parse_transfers(res);
});
return res;
}
var catapult = function(api,num){
var nodeIndex = num;
Array.apply(1, {length: num}).reduce(
function(promise){
return promise.then(
function(param){
nodeIndex--;
return api(nodeIndex);
}
);
},
$.Deferred().resolve()
).then(
function(){
console.log("done!");
}
);
}
//アカウント情報の取得
catapult(getNemAccountData,1);
//取引情報の取得
catapult(getNemTransferData,1);
$('#transfers_more').click(function(){
catapult(getNemTransferData,bulk);
return false;
})
var hex2a = function hex2a(hexx) {
var hex = hexx.toString();
var str = '';
for (var i = 0; i < hex.length; i += 2) {
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}
return str;
};
var parse_transfers = function(result){
var search_word = $("#search_word").val();
var dataArray = result.data;
dataArray.forEach(function(val){
var is_hit = true;
if(search_word != ""){
is_hit = false;
}
var meta = val.meta;
// lastId = meta.id;
var meta_hash = meta.hash.data;
// lastHash = meta.hash.data;
var tran = val.transaction;
var tran_amount = 0;
var tran_fee = tran.fee;
if(tran.type == 4100){
tran_fee = tran.otherTrans.fee + tran.fee ;
tran = tran.otherTrans;
}
if (tran.type == 257 || tran.type == 8193 ){
var tran_message = tran.message;
var plain_text = "";
if (tran_message && 'payload' in tran_message){
var o = tran_message.payload;
if(tran_message.type == '2'){
plain_text = "[暗号化されています]";
}else if (o && o.length > 2 && o[0] === 'f' && o[1] === 'e') {
plain_text = "HEX:" + o;
console.log("HEX: " + o);
}else{
try {
// plain_text = decodeURIComponent(escape(hex2a(o)));
plain_text = escape_html(decodeURIComponent( escape(hex2a(o))));
// console.log("plain_text:" + plain_text);
if(plain_text.match(search_word) ){
if(search_word != ""){
plain_text = replacer( plain_text, search_word,15);
is_hit = true;
}
}
} catch (e) {
console.log(tran_message);
console.log('invalid text input: ' + tran_message.payload);
}
}
}
if(is_hit){
//モザイクが存在した場合
var has_mosaic = false;
if(tran.mosaics){
for(key in tran.mosaics){
has_mosaic = true;
var mosaic = tran.mosaics[key];
if(mosaic.mosaicId.name == "xem" && mosaic.mosaicId.namespaceId == "nem"){
tran_amount = mosaic.quantity;
}
}
}
//通常送金
if(!has_mosaic){
if (tran.type == 8193 ){
tran_amount = tran.rentalFee;
}else{
tran_amount = tran.amount;
}
}
var is_appendable = false;
if(address != tran.recipient && tran.signer == account_publicKey){
sum_outcome += tran_amount + tran_fee;
tran_type = "<font color='red'>出金</font>";
tran_amount = dispAmount(tran_amount + tran_fee);
tran_amount = "- " + tran_amount;
is_appendable = true;
}else if(address == tran.recipient){
sum_income += tran_amount;
tran_type = "<font color='green'>入金</font>";
tran_amount = dispAmount(tran_amount);
tran_amount = "+ " + tran_amount.toString();
is_appendable = true;
}
if(is_appendable ){
$( "#transfers tbody" ).append( "<tr>" +
"<td style='white-space: nowrap'>" + dispTimeStamp(tran.timeStamp) + "</td>" +
"<td style='white-space: nowrap'>" + tran_type + "</td>" +
"<td class='text-right' style='white-space: nowrap'><a target='_blank' href='http://explorer.nemchina.com/#/s_tx?hash=" + meta_hash + "'>" + tran_amount + "</a></td>" +
"<td style='text-align: left'>" + plain_text + "</td>" +
"</tr>" );
}
}
}
});
$("#sum_income" ).text(dispAmount(sum_income) + "XEM");
$("#sum_outcome" ).text(dispAmount(sum_outcome) + "XEM");
}
function escape_html (string) {
if(typeof string !== 'string') {
return string;
}
return string.replace(/[&'`"<>]/g, function(match) { //'
return {
'&': '&',
"'": ''',
'`': '`',
'"': '"',
'<': '<',
'>': '>',
}[match]
});
}
});
</script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<style>
/* #F3B232 */
/* #78B6D7 */
/* #56B5A4 */
body {
padding-bottom: 3rem;
}
h1 {
padding: 2rem;
margin: 0;
background-color: #F3B232;
color: white;
}
h2 {
position: relative;
padding-left: 1.5rem;
border-left: 6px solid #F3B232;
}
h2::before {
position: absolute;
left: -6px;
bottom: 0;
content: '';
width: 6px;
height: 50%;
background-color: #ccc;
}
h2::after {
position: absolute;
left: 0;
bottom: 0;
content: '';
width: 100%;
height: 0;
border-bottom: 1px solid #ccc;
}
tr:nth-child(even){
background-color: #eee;
}
th {
border-bottom: 1px dotted #ccc;
text-align: center;
}
td{
text-align: center;
padding: .5rem 1rem;
}
hr {
margin: 0;
border: none;
height: 10px;
}
.zigzag-orange-white {
background:
linear-gradient(-135deg, #F3B232 5px, transparent 0) 0 5px,
linear-gradient(135deg, #F3B232 5px, #fff 0) 0 5px;
background-color: #333538;
background-position: left bottom;
background-repeat: repeat-x;
background-size: 10px 10px;
}
@media (max-width: 767px){
#clipboard {
display: none;
}
}
input#xs_amount { width: 60px; }
</style>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-100421513-1', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<h1>XEMMessage</h1>
<hr class="zigzag-orange-white">
<div class="container">
<div >
<h2>抽出条件</h2>
<form class="form-inline">
<div class="form-group">
<input id="search_word" type="text" name="name" class="form-control">
</div>
<button id="search_btn" class="btn btn-default">再検索</button>
</form>
</div>
<div >
<h2>入出金履歴</h2>
<table id="transfers">
<thead><tr><th>日時</th><th>区分</th><th>金額</th><th>メッセージ</th></tr></thead>
<tbody></tbody>
</table>
<dl>
<dt>ここまでの入金総額:</dt><dd><span id="sum_income"></span></dd>
<dt>ここまでの出金総額:</dt><dd><span id="sum_outcome"></span></dd>
<dd><a id="transfers_more" href="javascript:void(0)" >さらに読み込む</a></dd>
<dd><a id="transfers_nembex">nembexで確認</a></dd>
</dl>
</div>
<div class="row">
<div class="account col-sm-4">
<h2>アカウント</h2>
<dl>
<dt>口座名</dt><dd><span id="account_address"></span></dd>
<dt>残高</dt><dd><span id="account_balance"></span></dd>
<dt>時価総額</dt><dd><span id="polo_price"></span></dd>
<dt>重要度</dt><dd><span id="account_importance"></span></dd>
</dl>
</div>
<div class="account col-sm-4">
<div class="faucet">
<h2>リンク</h2>
<dl>
<dd><a id="xembook" href="">XEMBook</a></dd>
<dd><a id="xemtax" href="">XEMTax</a></dd>
<dd><a id="xemreceiver" href="">XEMReceiver</a></dd>
</dl>
</div>
</div>
<div class="account col-sm-4">
<h2>開発者への寄付</h2>
<ul class="list-inline">
<li>NBZNQL2JDWTGUAW237PXV4SSXSPORY43GUSWGSB7</li>
</ul>
<dl>
<dt>収支報告</dt>
<dd><a href="http://explorer.nemchina.com/#/s_account?account=NBZNQL-2JDWTG-UAW237-PXV4SS-XSPORY-43GUSW-GSB7" >nembexで確認</a></dd>
<dd><a href="/?address=NBZNQL-2JDWTG-UAW237-PXV4SS-XSPORY-43GUSW-GSB7" >XEMBookで確認</a></dd>
</dl>
</div>
</div>
</div>
</body>
</html>