-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmodules_wallets_ExplorerWallet.js.html
799 lines (680 loc) · 47.2 KB
/
modules_wallets_ExplorerWallet.js.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
modules/wallets/ExplorerWallet.js - Documentation
</title>
<link href="https://www.braintreepayments.com/images/favicon-ccda0b14.png" rel="icon" type="image/png">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.3.0/highlightjs-line-numbers.min.js"></script>
<script>
hljs.initHighlightingOnLoad();
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/monokai-sublime.css">
<!-- start Mixpanel -->
<script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
mixpanel.init("1919205b2da72e4da3b9b6639b444d59");</script>
<!-- end Mixpanel -->
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
js-oip
</h3>
<h3>Classes</h3><ul><li id="Artifact-nav"><a href="Artifact.html">Artifact</a><ul class='methods'><li data-type="method" id="Artifact-getArtifactSubtype-nav"><a href="Artifact.html#.getArtifactSubtype">getArtifactSubtype</a></li><li data-type="method" id="Artifact-getArtifactType-nav"><a href="Artifact.html#.getArtifactType">getArtifactType</a></li><li data-type="method" id="Artifact-addFile-nav"><a href="Artifact.html#addFile">addFile</a></li><li data-type="method" id="Artifact-addSinglePaymentAddress-nav"><a href="Artifact.html#addSinglePaymentAddress">addSinglePaymentAddress</a></li><li data-type="method" id="Artifact-addTokenRule-nav"><a href="Artifact.html#addTokenRule">addTokenRule</a></li><li data-type="method" id="Artifact-createPreimage-nav"><a href="Artifact.html#createPreimage">createPreimage</a></li><li data-type="method" id="Artifact-fromJSON-nav"><a href="Artifact.html#fromJSON">fromJSON</a></li><li data-type="method" id="Artifact-getArtifact-nav"><a href="Artifact.html#getArtifact">getArtifact</a></li><li data-type="method" id="Artifact-getBlock-nav"><a href="Artifact.html#getBlock">getBlock</a></li><li data-type="method" id="Artifact-getBlockHash-nav"><a href="Artifact.html#getBlockHash">getBlockHash</a></li><li data-type="method" id="Artifact-getClassName-nav"><a href="Artifact.html#getClassName">getClassName</a></li><li data-type="method" id="Artifact-getDeactivated-nav"><a href="Artifact.html#getDeactivated">getDeactivated</a></li><li data-type="method" id="Artifact-getDescription-nav"><a href="Artifact.html#getDescription">getDescription</a></li><li data-type="method" id="Artifact-getDetail-nav"><a href="Artifact.html#getDetail">getDetail</a></li><li data-type="method" id="Artifact-getDuration-nav"><a href="Artifact.html#getDuration">getDuration</a></li><li data-type="method" id="Artifact-getEditVersion-nav"><a href="Artifact.html#getEditVersion">getEditVersion</a></li><li data-type="method" id="Artifact-getFiles-nav"><a href="Artifact.html#getFiles">getFiles</a></li><li data-type="method" id="Artifact-getLocation-nav"><a href="Artifact.html#getLocation">getLocation</a></li><li data-type="method" id="Artifact-getMaxDiscount-nav"><a href="Artifact.html#getMaxDiscount">getMaxDiscount</a></li><li data-type="method" id="Artifact-getMeta-nav"><a href="Artifact.html#getMeta">getMeta</a></li><li data-type="method" id="Artifact-getNetwork-nav"><a href="Artifact.html#getNetwork">getNetwork</a></li><li data-type="method" id="Artifact-getNSFW-nav"><a href="Artifact.html#getNSFW">getNSFW</a></li><li data-type="method" id="Artifact-getOriginalTXID-nav"><a href="Artifact.html#getOriginalTXID">getOriginalTXID</a></li><li data-type="method" id="Artifact-getPaymentAddress-nav"><a href="Artifact.html#getPaymentAddress">getPaymentAddress</a></li><li data-type="method" id="Artifact-getPaymentAddresses-nav"><a href="Artifact.html#getPaymentAddresses">getPaymentAddresses</a></li><li data-type="method" id="Artifact-getPaymentFiat-nav"><a href="Artifact.html#getPaymentFiat">getPaymentFiat</a></li><li data-type="method" id="Artifact-getPaymentScale-nav"><a href="Artifact.html#getPaymentScale">getPaymentScale</a></li><li data-type="method" id="Artifact-getPromoterCut-nav"><a href="Artifact.html#getPromoterCut">getPromoterCut</a></li><li data-type="method" id="Artifact-getPubAddress-nav"><a href="Artifact.html#getPubAddress">getPubAddress</a></li><li data-type="method" id="Artifact-getPublisherName-nav"><a href="Artifact.html#getPublisherName">getPublisherName</a></li><li data-type="method" id="Artifact-getRetailerCut-nav"><a href="Artifact.html#getRetailerCut">getRetailerCut</a></li><li data-type="method" id="Artifact-getSignature-nav"><a href="Artifact.html#getSignature">getSignature</a></li><li data-type="method" id="Artifact-getSubtype-nav"><a href="Artifact.html#getSubtype">getSubtype</a></li><li data-type="method" id="Artifact-getSuggestedTip-nav"><a href="Artifact.html#getSuggestedTip">getSuggestedTip</a></li><li data-type="method" id="Artifact-getSupportedCoins-nav"><a href="Artifact.html#getSupportedCoins">getSupportedCoins</a></li><li data-type="method" id="Artifact-getTags-nav"><a href="Artifact.html#getTags">getTags</a></li><li data-type="method" id="Artifact-getThumbnail-nav"><a href="Artifact.html#getThumbnail">getThumbnail</a></li><li data-type="method" id="Artifact-getTime-nav"><a href="Artifact.html#getTime">getTime</a></li><li data-type="method" id="Artifact-getTimestamp-nav"><a href="Artifact.html#getTimestamp">getTimestamp</a></li><li data-type="method" id="Artifact-getTipAddresses-nav"><a href="Artifact.html#getTipAddresses">getTipAddresses</a></li><li data-type="method" id="Artifact-getTitle-nav"><a href="Artifact.html#getTitle">getTitle</a></li><li data-type="method" id="Artifact-getTokenRules-nav"><a href="Artifact.html#getTokenRules">getTokenRules</a></li><li data-type="method" id="Artifact-getTXID-nav"><a href="Artifact.html#getTXID">getTXID</a></li><li data-type="method" id="Artifact-getType-nav"><a href="Artifact.html#getType">getType</a></li><li data-type="method" id="Artifact-getVersion-nav"><a href="Artifact.html#getVersion">getVersion</a></li><li data-type="method" id="Artifact-getYear-nav"><a href="Artifact.html#getYear">getYear</a></li><li data-type="method" id="Artifact-import041-nav"><a href="Artifact.html#import041">import041</a></li><li data-type="method" id="Artifact-import042-nav"><a href="Artifact.html#import042">import042</a></li><li data-type="method" id="Artifact-importAlexandriaMedia-nav"><a href="Artifact.html#importAlexandriaMedia">importAlexandriaMedia</a></li><li data-type="method" id="Artifact-isPaid-nav"><a href="Artifact.html#isPaid">isPaid</a></li><li data-type="method" id="Artifact-isValid-nav"><a href="Artifact.html#isValid">isValid</a></li><li data-type="method" id="Artifact-setBlock-nav"><a href="Artifact.html#setBlock">setBlock</a></li><li data-type="method" id="Artifact-setBlockHash-nav"><a href="Artifact.html#setBlockHash">setBlockHash</a></li><li data-type="method" id="Artifact-setDeactivated-nav"><a href="Artifact.html#setDeactivated">setDeactivated</a></li><li data-type="method" id="Artifact-setDescription-nav"><a href="Artifact.html#setDescription">setDescription</a></li><li data-type="method" id="Artifact-setDetail-nav"><a href="Artifact.html#setDetail">setDetail</a></li><li data-type="method" id="Artifact-setEditVersion-nav"><a href="Artifact.html#setEditVersion">setEditVersion</a></li><li data-type="method" id="Artifact-setLocation-nav"><a href="Artifact.html#setLocation">setLocation</a></li><li data-type="method" id="Artifact-setMaxDiscount-nav"><a href="Artifact.html#setMaxDiscount">setMaxDiscount</a></li><li data-type="method" id="Artifact-setNetwork-nav"><a href="Artifact.html#setNetwork">setNetwork</a></li><li data-type="method" id="Artifact-setNSFW-nav"><a href="Artifact.html#setNSFW">setNSFW</a></li><li data-type="method" id="Artifact-setOriginalTXID-nav"><a href="Artifact.html#setOriginalTXID">setOriginalTXID</a></li><li data-type="method" id="Artifact-setPaymentFiat-nav"><a href="Artifact.html#setPaymentFiat">setPaymentFiat</a></li><li data-type="method" id="Artifact-setPaymentScale-nav"><a href="Artifact.html#setPaymentScale">setPaymentScale</a></li><li data-type="method" id="Artifact-setPromoterCut-nav"><a href="Artifact.html#setPromoterCut">setPromoterCut</a></li><li data-type="method" id="Artifact-setPubAddress-nav"><a href="Artifact.html#setPubAddress">setPubAddress</a></li><li data-type="method" id="Artifact-setPublisherName-nav"><a href="Artifact.html#setPublisherName">setPublisherName</a></li><li data-type="method" id="Artifact-setRetailerCut-nav"><a href="Artifact.html#setRetailerCut">setRetailerCut</a></li><li data-type="method" id="Artifact-setSignature-nav"><a href="Artifact.html#setSignature">setSignature</a></li><li data-type="method" id="Artifact-setSubtype-nav"><a href="Artifact.html#setSubtype">setSubtype</a></li><li data-type="method" id="Artifact-setSuggestedTip-nav"><a href="Artifact.html#setSuggestedTip">setSuggestedTip</a></li><li data-type="method" id="Artifact-setTags-nav"><a href="Artifact.html#setTags">setTags</a></li><li data-type="method" id="Artifact-setTime-nav"><a href="Artifact.html#setTime">setTime</a></li><li data-type="method" id="Artifact-setTimestamp-nav"><a href="Artifact.html#setTimestamp">setTimestamp</a></li><li data-type="method" id="Artifact-setTitle-nav"><a href="Artifact.html#setTitle">setTitle</a></li><li data-type="method" id="Artifact-setTXID-nav"><a href="Artifact.html#setTXID">setTXID</a></li><li data-type="method" id="Artifact-setType-nav"><a href="Artifact.html#setType">setType</a></li><li data-type="method" id="Artifact-setVersion-nav"><a href="Artifact.html#setVersion">setVersion</a></li><li data-type="method" id="Artifact-setYear-nav"><a href="Artifact.html#setYear">setYear</a></li><li data-type="method" id="Artifact-toJSON-nav"><a href="Artifact.html#toJSON">toJSON</a></li><li data-type="method" id="Artifact-toString-nav"><a href="Artifact.html#toString">toString</a></li></ul></li><li id="DaemonApi-nav"><a href="DaemonApi.html">DaemonApi</a><ul class='methods'><li data-type="method" id="DaemonApi-createQs-nav"><a href="DaemonApi.html#createQs">createQs</a></li><li data-type="method" id="DaemonApi-get041Artifact-nav"><a href="DaemonApi.html#get041Artifact">get041Artifact</a></li><li data-type="method" id="DaemonApi-get041Artifacts-nav"><a href="DaemonApi.html#get041Artifacts">get041Artifacts</a></li><li data-type="method" id="DaemonApi-getAlexandriaMediaArtifact-nav"><a href="DaemonApi.html#getAlexandriaMediaArtifact">getAlexandriaMediaArtifact</a></li><li data-type="method" id="DaemonApi-getAlexandriaMediaArtifacts-nav"><a href="DaemonApi.html#getAlexandriaMediaArtifacts">getAlexandriaMediaArtifacts</a></li><li data-type="method" id="DaemonApi-getArtifact-nav"><a href="DaemonApi.html#getArtifact">getArtifact</a></li><li data-type="method" id="DaemonApi-getArtifacts-nav"><a href="DaemonApi.html#getArtifacts">getArtifacts</a></li><li data-type="method" id="DaemonApi-getFloData-nav"><a href="DaemonApi.html#getFloData">getFloData</a></li><li data-type="method" id="DaemonApi-getHistorianData-nav"><a href="DaemonApi.html#getHistorianData">getHistorianData</a></li><li data-type="method" id="DaemonApi-getLastestHistorianData-nav"><a href="DaemonApi.html#getLastestHistorianData">getLastestHistorianData</a></li><li data-type="method" id="DaemonApi-getLatest041Artifacts-nav"><a href="DaemonApi.html#getLatest041Artifacts">getLatest041Artifacts</a></li><li data-type="method" id="DaemonApi-getLatest042Artifacts-nav"><a href="DaemonApi.html#getLatest042Artifacts">getLatest042Artifacts</a></li><li data-type="method" id="DaemonApi-getLatestAlexandriaMediaArtifacts-nav"><a href="DaemonApi.html#getLatestAlexandriaMediaArtifacts">getLatestAlexandriaMediaArtifacts</a></li><li data-type="method" id="DaemonApi-getLatestArtifacts-nav"><a href="DaemonApi.html#getLatestArtifacts">getLatestArtifacts</a></li><li data-type="method" id="DaemonApi-getLatestOip5Records-nav"><a href="DaemonApi.html#getLatestOip5Records">getLatestOip5Records</a></li><li data-type="method" id="DaemonApi-getLatestOip5Templates-nav"><a href="DaemonApi.html#getLatestOip5Templates">getLatestOip5Templates</a></li><li data-type="method" id="DaemonApi-getMultipart-nav"><a href="DaemonApi.html#getMultipart">getMultipart</a></li><li data-type="method" id="DaemonApi-getMultiparts-nav"><a href="DaemonApi.html#getMultiparts">getMultiparts</a></li><li data-type="method" id="DaemonApi-getNetwork-nav"><a href="DaemonApi.html#getNetwork">getNetwork</a></li><li data-type="method" id="DaemonApi-getOip5Mapping-nav"><a href="DaemonApi.html#getOip5Mapping">getOip5Mapping</a></li><li data-type="method" id="DaemonApi-getOip5Record-nav"><a href="DaemonApi.html#getOip5Record">getOip5Record</a></li><li data-type="method" id="DaemonApi-getOip5Records-nav"><a href="DaemonApi.html#getOip5Records">getOip5Records</a></li><li data-type="method" id="DaemonApi-getOip5Template-nav"><a href="DaemonApi.html#getOip5Template">getOip5Template</a></li><li data-type="method" id="DaemonApi-getOip5Templates-nav"><a href="DaemonApi.html#getOip5Templates">getOip5Templates</a></li><li data-type="method" id="DaemonApi-getRecord-nav"><a href="DaemonApi.html#getRecord">getRecord</a></li><li data-type="method" id="DaemonApi-getSyncStatus-nav"><a href="DaemonApi.html#getSyncStatus">getSyncStatus</a></li><li data-type="method" id="DaemonApi-getUrl-nav"><a href="DaemonApi.html#getUrl">getUrl</a></li><li data-type="method" id="DaemonApi-getVersion-nav"><a href="DaemonApi.html#getVersion">getVersion</a></li><li data-type="method" id="DaemonApi-searchArtifacts-nav"><a href="DaemonApi.html#searchArtifacts">searchArtifacts</a></li><li data-type="method" id="DaemonApi-searchArtifactsByType-nav"><a href="DaemonApi.html#searchArtifactsByType">searchArtifactsByType</a></li><li data-type="method" id="DaemonApi-searchFloData-nav"><a href="DaemonApi.html#searchFloData">searchFloData</a></li><li data-type="method" id="DaemonApi-searchOip5Records-nav"><a href="DaemonApi.html#searchOip5Records">searchOip5Records</a></li><li data-type="method" id="DaemonApi-searchOip5Templates-nav"><a href="DaemonApi.html#searchOip5Templates">searchOip5Templates</a></li><li data-type="method" id="DaemonApi-setUrl-nav"><a href="DaemonApi.html#setUrl">setUrl</a></li></ul></li><li id="ExplorerWallet-nav"><a href="ExplorerWallet.html">ExplorerWallet</a><ul class='methods'><li data-type="method" id="ExplorerWallet-addSpentTransaction-nav"><a href="ExplorerWallet.html#addSpentTransaction">addSpentTransaction</a></li><li data-type="method" id="ExplorerWallet-broadcastRawHex-nav"><a href="ExplorerWallet.html#broadcastRawHex">broadcastRawHex</a></li><li data-type="method" id="ExplorerWallet-buildInputsAndOutputs-nav"><a href="ExplorerWallet.html#buildInputsAndOutputs">buildInputsAndOutputs</a></li><li data-type="method" id="ExplorerWallet-buildTXHex-nav"><a href="ExplorerWallet.html#buildTXHex">buildTXHex</a></li><li data-type="method" id="ExplorerWallet-createManualUtxos-nav"><a href="ExplorerWallet.html#createManualUtxos">createManualUtxos</a></li><li data-type="method" id="ExplorerWallet-deleteHistory-nav"><a href="ExplorerWallet.html#deleteHistory">deleteHistory</a></li><li data-type="method" id="ExplorerWallet-deserialize-nav"><a href="ExplorerWallet.html#deserialize">deserialize</a></li><li data-type="method" id="ExplorerWallet-getCoinInfo-nav"><a href="ExplorerWallet.html#getCoinInfo">getCoinInfo</a></li><li data-type="method" id="ExplorerWallet-getECPair-nav"><a href="ExplorerWallet.html#getECPair">getECPair</a></li><li data-type="method" id="ExplorerWallet-getNetwork-nav"><a href="ExplorerWallet.html#getNetwork">getNetwork</a></li><li data-type="method" id="ExplorerWallet-getPubAddress-nav"><a href="ExplorerWallet.html#getPubAddress">getPubAddress</a></li><li data-type="method" id="ExplorerWallet-getSpentTransactions-nav"><a href="ExplorerWallet.html#getSpentTransactions">getSpentTransactions</a></li><li data-type="method" id="ExplorerWallet-getTxHistory-nav"><a href="ExplorerWallet.html#getTxHistory">getTxHistory</a></li><li data-type="method" id="ExplorerWallet-getUTXO-nav"><a href="ExplorerWallet.html#getUTXO">getUTXO</a></li><li data-type="method" id="ExplorerWallet-removeSpent-nav"><a href="ExplorerWallet.html#removeSpent">removeSpent</a></li><li data-type="method" id="ExplorerWallet-save-nav"><a href="ExplorerWallet.html#save">save</a></li><li data-type="method" id="ExplorerWallet-sendDataToChain-nav"><a href="ExplorerWallet.html#sendDataToChain">sendDataToChain</a></li><li data-type="method" id="ExplorerWallet-sendTx-nav"><a href="ExplorerWallet.html#sendTx">sendTx</a></li><li data-type="method" id="ExplorerWallet-serialize-nav"><a href="ExplorerWallet.html#serialize">serialize</a></li></ul></li><li id="IpfsHttpApi-nav"><a href="IpfsHttpApi.html">IpfsHttpApi</a><ul class='methods'><li data-type="method" id="IpfsHttpApi-onProgress-nav"><a href="IpfsHttpApi.html#onProgress">onProgress</a></li><li data-type="method" id="IpfsHttpApi-start-nav"><a href="IpfsHttpApi.html#start">start</a></li></ul></li><li id="IpfsXml-nav"><a href="IpfsXml.html">IpfsXml</a><ul class='methods'><li data-type="method" id="IpfsXml-onProgress-nav"><a href="IpfsXml.html#onProgress">onProgress</a></li><li data-type="method" id="IpfsXml-start-nav"><a href="IpfsXml.html#start">start</a></li></ul></li><li id="MPSingle-nav"><a href="MPSingle.html">MPSingle</a><ul class='methods'><li data-type="method" id="MPSingle-fromInput-nav"><a href="MPSingle.html#fromInput">fromInput</a></li><li data-type="method" id="MPSingle-getAddress-nav"><a href="MPSingle.html#getAddress">getAddress</a></li><li data-type="method" id="MPSingle-getAssembled-nav"><a href="MPSingle.html#getAssembled">getAssembled</a></li><li data-type="method" id="MPSingle-getBlock-nav"><a href="MPSingle.html#getBlock">getBlock</a></li><li data-type="method" id="MPSingle-getBlockHash-nav"><a href="MPSingle.html#getBlockHash">getBlockHash</a></li><li data-type="method" id="MPSingle-getData-nav"><a href="MPSingle.html#getData">getData</a></li><li data-type="method" id="MPSingle-getMax-nav"><a href="MPSingle.html#getMax">getMax</a></li><li data-type="method" id="MPSingle-getMeta-nav"><a href="MPSingle.html#getMeta">getMeta</a></li><li data-type="method" id="MPSingle-getPart-nav"><a href="MPSingle.html#getPart">getPart</a></li><li data-type="method" id="MPSingle-getReference-nav"><a href="MPSingle.html#getReference">getReference</a></li><li data-type="method" id="MPSingle-getSignature-nav"><a href="MPSingle.html#getSignature">getSignature</a></li><li data-type="method" id="MPSingle-getSignatureData-nav"><a href="MPSingle.html#getSignatureData">getSignatureData</a></li><li data-type="method" id="MPSingle-getTXID-nav"><a href="MPSingle.html#getTXID">getTXID</a></li><li data-type="method" id="MPSingle-hasValidSignature-nav"><a href="MPSingle.html#hasValidSignature">hasValidSignature</a></li><li data-type="method" id="MPSingle-isComplete-nav"><a href="MPSingle.html#isComplete">isComplete</a></li><li data-type="method" id="MPSingle-isStale-nav"><a href="MPSingle.html#isStale">isStale</a></li><li data-type="method" id="MPSingle-setAddress-nav"><a href="MPSingle.html#setAddress">setAddress</a></li><li data-type="method" id="MPSingle-setAssembled-nav"><a href="MPSingle.html#setAssembled">setAssembled</a></li><li data-type="method" id="MPSingle-setBlock-nav"><a href="MPSingle.html#setBlock">setBlock</a></li><li data-type="method" id="MPSingle-setBlockHash-nav"><a href="MPSingle.html#setBlockHash">setBlockHash</a></li><li data-type="method" id="MPSingle-setData-nav"><a href="MPSingle.html#setData">setData</a></li><li data-type="method" id="MPSingle-setIsComplete-nav"><a href="MPSingle.html#setIsComplete">setIsComplete</a></li><li data-type="method" id="MPSingle-setIsStale-nav"><a href="MPSingle.html#setIsStale">setIsStale</a></li><li data-type="method" id="MPSingle-setMax-nav"><a href="MPSingle.html#setMax">setMax</a></li><li data-type="method" id="MPSingle-setPart-nav"><a href="MPSingle.html#setPart">setPart</a></li><li data-type="method" id="MPSingle-setReference-nav"><a href="MPSingle.html#setReference">setReference</a></li><li data-type="method" id="MPSingle-setSignature-nav"><a href="MPSingle.html#setSignature">setSignature</a></li><li data-type="method" id="MPSingle-setTXID-nav"><a href="MPSingle.html#setTXID">setTXID</a></li><li data-type="method" id="MPSingle-signSelf-nav"><a href="MPSingle.html#signSelf">signSelf</a></li><li data-type="method" id="MPSingle-toString-nav"><a href="MPSingle.html#toString">toString</a></li></ul></li><li id="MultipartX-nav"><a href="MultipartX.html">MultipartX</a><ul class='methods'><li data-type="method" id="MultipartX-fromMultiparts-nav"><a href="MultipartX.html#fromMultiparts">fromMultiparts</a></li><li data-type="method" id="MultipartX-fromString-nav"><a href="MultipartX.html#fromString">fromString</a></li><li data-type="method" id="MultipartX-getMultiparts-nav"><a href="MultipartX.html#getMultiparts">getMultiparts</a></li><li data-type="method" id="MultipartX-toString-nav"><a href="MultipartX.html#toString">toString</a></li></ul></li><li id="OIP-nav"><a href="OIP.html">OIP</a><ul class='methods'><li data-type="method" id="OIP-broadcastRecord-nav"><a href="OIP.html#broadcastRecord">broadcastRecord</a></li><li data-type="method" id="OIP-edit-nav"><a href="OIP.html#edit">edit</a></li><li data-type="method" id="OIP-publish-nav"><a href="OIP.html#publish">publish</a></li><li data-type="method" id="OIP-publishMultiparts-nav"><a href="OIP.html#publishMultiparts">publishMultiparts</a></li><li data-type="method" id="OIP-signRecord-nav"><a href="OIP.html#signRecord">signRecord</a></li></ul></li><li id="Peer-nav"><a href="Peer.html">Peer</a><ul class='methods'><li data-type="method" id="Peer-announceTX-nav"><a href="Peer.html#announceTX">announceTX</a></li><li data-type="method" id="Peer-connect-nav"><a href="Peer.html#connect">connect</a></li><li data-type="method" id="Peer-handleGetData-nav"><a href="Peer.html#handleGetData">handleGetData</a></li><li data-type="method" id="Peer-onPacket-nav"><a href="Peer.html#onPacket">onPacket</a></li></ul></li><li id="RPCWallet-nav"><a href="RPCWallet.html">RPCWallet</a><ul class='methods'><li data-type="method" id="RPCWallet-addAncestor-nav"><a href="RPCWallet.html#addAncestor">addAncestor</a></li><li data-type="method" id="RPCWallet-checkAncestorCount-nav"><a href="RPCWallet.html#checkAncestorCount">checkAncestorCount</a></li><li data-type="method" id="RPCWallet-connectToPeers-nav"><a href="RPCWallet.html#connectToPeers">connectToPeers</a></li><li data-type="method" id="RPCWallet-createAndSignTransaction-nav"><a href="RPCWallet.html#createAndSignTransaction">createAndSignTransaction</a></li><li data-type="method" id="RPCWallet-destroyPeers-nav"><a href="RPCWallet.html#destroyPeers">destroyPeers</a></li><li data-type="method" id="RPCWallet-getUTXOs-nav"><a href="RPCWallet.html#getUTXOs">getUTXOs</a></li><li data-type="method" id="RPCWallet-initialize-nav"><a href="RPCWallet.html#initialize">initialize</a></li><li data-type="method" id="RPCWallet-rebroadcastTransactions-nav"><a href="RPCWallet.html#rebroadcastTransactions">rebroadcastTransactions</a></li><li data-type="method" id="RPCWallet-rpcRequest-nav"><a href="RPCWallet.html#rpcRequest">rpcRequest</a></li><li data-type="method" id="RPCWallet-sendDataToChain-nav"><a href="RPCWallet.html#sendDataToChain">sendDataToChain</a></li><li data-type="method" id="RPCWallet-sendTX-nav"><a href="RPCWallet.html#sendTX">sendTX</a></li><li data-type="method" id="RPCWallet-signMessage-nav"><a href="RPCWallet.html#signMessage">signMessage</a></li><li data-type="method" id="RPCWallet-updateAncestorStatus-nav"><a href="RPCWallet.html#updateAncestorStatus">updateAncestorStatus</a></li></ul></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#createPatch">createPatch</a></li><li><a href="global.html#createPatchedRecord">createPatchedRecord</a></li><li><a href="global.html#createRFC6902Patch">createRFC6902Patch</a></li><li><a href="global.html#decodeArtifact">decodeArtifact</a></li><li><a href="global.html#fromJSON">fromJSON</a></li><li><a href="global.html#getClassName">getClassName</a></li><li><a href="global.html#isValidWIF">isValidWIF</a></li><li><a href="global.html#signSelf">signSelf</a></li><li><a href="global.html#toJSON">toJSON</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
modules/wallets/ExplorerWallet.js
</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import { sign } from 'bitcoinjs-message'
import { ECPair, payments, address } from 'bitcoinjs-lib'
import coinselect from 'coinselect'
import Insight from '@oipwg/insight-explorer'
// This dependency was not found:
//
// * fs in ./node_modules/bindings/bindings.js
import floTx from 'fcoin/lib/primitives/tx'
import { isValidWIF } from '../../util'
import { floMainnet, floTestnet } from '../../config'
import FLOTransactionBuilder from '../flo/FLOTransactionBuilder'
if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') {
if (typeof localStorage === 'undefined') { // eslint-disable-line
// var is needed her for the javascript hoisting effect or else localstorage won't be scoped
var LocalStorage = require('node-localstorage').LocalStorage
var localStorage = new LocalStorage('./localStorage')
}
} else {
localStorage = window.localStorage
}
/**
* @typedef {Object} utxo
* @param {string} address - pay to public key hash (pub address)
* @param {TXID} txid - transaction id
* @param {number} vout - index of output in transaction
* @param {string} scriptPubKey - script which ensures that the script supplied in the redeeming transaction hashes to the script used to create the address
* @param {number} amount - the amount spent
* @param {number} satoshis - the amount spent in satoshis
* @param {number} height - the block height of the transaction
* @param {number} confirmations - number of blocks that have been confirmed after the transaction's block
*
* @example
* {
* address: 'ofbB67gqjgaYi45u8Qk2U3hGoCmyZcgbN4',
* txid: '40bf49a02731b04b71951d2e7782b93bd30678c5f5608f0cfe9cdaed6d392903',
* vout: 1,
* scriptPubKey: '76a914f93aef4f4ef998b7ae44bd5bc8f6627b79cdc07588ac',
* amount: 659.9999325,
* satoshis: 65999993250,
* height: 295680,
* confirmations: 6933
* }
*/
/**
* Class to use a web explorer wallet
*/
class ExplorerWallet {
/**
* ##### Example
* ```javascript
* import {OIP} from 'js-oip'
*
* let wif = "cRVa9rNx5N1YKBw8PhavegJPFCiYCfC4n8cYmdc3X1Y6TyFZGG4B"
* let oip = new OIP(wif, "testnet")
* ```
* @param {string} options.wif - private key in Wallet Import Format (WIF) see: {@link https://en.bitcoin.it/wiki/Wallet_import_format}
* @param {string} [options.network="mainnet"] - Use "testnet" for testnet
*/
// ToDo:: Switch to mainnet for prod
constructor (options) {
let network = floMainnet
if (options.network === 'testnet') { network = floTestnet }
if (options.explorerUrl) { network.explorer = new Insight(options.explorerUrl) }
if (!isValidWIF(options.wif, network.network)) {
return { success: false, message: 'Invalid WIF', wif: options.wif, network: network.network }
}
this.coin = network
this.network = network.network
this.explorer = network.explorer
this.ECPair = ECPair.fromWIF(options.wif, this.network)
this.p2pkh = payments.p2pkh({ pubkey: this.ECPair.publicKey, network: this.network }).address
this.spentTransactions = []
this.history = []
this.deserialize()
}
signMessage (message) {
let privateKeyBuffer = this.ECPair.privateKey
let compressed = this.ECPair.compressed || true
let signatureBuffer
try {
signatureBuffer = sign(message, privateKeyBuffer, compressed, this.ECPair.network.messagePrefix)
} catch (e) {
throw new Error(e)
}
let signature = signatureBuffer.toString('base64')
return signature
}
/**
* Send string data to the FLO Chain
* @param {string} data - String data. Must be below or equal to 1040 characters
* @return {Promise<string>} txid - Returns the id of the transaction that contains the published data
* @example
* let oip = new OIP(wif, "testnet")
* let txid = await oip.sendDataToChain('Hello, world')
*/
async sendDataToChain (data) {
if (typeof data !== 'string') {
throw new Error(`Data must be of type string. Got: ${typeof data}`)
}
if (data.length > 1040) {
throw new Error(`Error: data length exceeds 1040 characters. Try using OIPPublisher.publish(data) instead.`)
}
let hex
try {
hex = await this.buildTXHex(data)
} catch (err) {
throw new Error(`Error building TX Hex: ${err}`)
}
let txid
try {
txid = await this.broadcastRawHex(hex)
} catch (err) {
throw new Error(`Error broadcasting TX Hex: ${err}`)
}
// Add txid to spentTransactions for each spent input
for (let inp of this.selected.inputs) {
if (this.p2pkh === inp.address) {
this.addSpentTransaction(inp.txId)
}
}
this.save(txid, hex)
return txid
}
/**
* Build a valid FLO Raw TX Hex containing floData
* @param {String} [floData=""] - String data to send with tx. Defaults to an empty string
* @param {object|Array.<object>} [output] - Custom output object
* @return {Promise<string>} hex - Returns raw transaction hex
* @example
* //if no output is designed, it will send 0.0001 * 1e8 FLO to yourself
* let output = {
* address: "ofbB67gqjgaYi45u8Qk2U3hGoCmyZcgbN4",
* value: 1e8 //satoshis
* }
* let op = new OIP(wif, "testnet")
* let hex = await op.buildTXHex("floData", output)
*/
async buildTXHex (floData = '', output) {
let selected
try {
selected = await this.buildInputsAndOutputs(floData, output)
} catch (err) {
throw new Error(`Failed to build inputs and outputs: ${err}`)
}
this.selected = selected
// console.log('selected: ', selected)
let { inputs, outputs } = selected
// inputs and outputs will be undefined if no solution was found
if (!inputs || !outputs) {
throw new Error('No Inputs or Outputs selected! Fail!')
}
let txb = new FLOTransactionBuilder(this.network)
inputs.forEach(input => txb.addInput(input.txId, input.vout))
// Check if we are paying to ourself, if so, merge the outputs to just a single output.
// Check if we have two outputs (i.e. pay to and change)
if (outputs.length === 2) {
// If the first input is sending to the from address, and there is a change output,
// then merge the outputs.
if (outputs[0].address === this.p2pkh && !outputs[1].address) {
let totalToSend = outputs[0].value + outputs[1].value
outputs = [{
address: this.p2pkh,
value: totalToSend
}]
} else {
// send the original amount to the first address and send the rest to yourself as change
if (outputs[0].address !== this.p2pkh && !outputs[1].address) {
outputs[1].address = this.p2pkh
}
}
}
outputs.forEach(output => {
if (!output.address) {
throw new Error(`Missing output address: ${outputs}`)
}
txb.addOutput(output.address, output.value)
})
txb.setFloData(floData)
for (let i in inputs) {
if (this.p2pkh !== inputs[i].address) throw new Error(`Invalid inputs. Addresses don't match: ${inputs} & ${this.p2pkh}`)
txb.sign(parseInt(i), this.ECPair)
}
let builtHex
try {
builtHex = txb.build().toHex()
} catch (err) {
throw new Error(`Unable to build Transaction Hex!: ${err}`)
}
return builtHex
}
/**
* Builds the inputs and outputs to form a valid transaction hex for the FLO Chain
* @param {string} [floData=""] - defaults to an empty string
* @param {object|Array.<object>} [outputs] - Output or an array of Outputs to send to
* @return {Promise<Object>} Returns the selected inputs, outputs, and fee to use for the transaction hex
* @example
* //basic
* let oip = new OIP(wif, "testnet")
* let selected = await oip.buildInputsAndOutputs("floData") //returns selected inputs, outputs, and fee
* @example
* //with custom output and object destructuring
* let oip = new OIP(wif, "testnet")
* let output = {
* address: "ofbB67gqjgaYi45u8Qk2U3hGoCmyZcgbN4",
* value: 1e8 //in satoshis
* }
* let {inputs, outputs, fee} = await oip.buildInputsAndOutputs("floData", output)
*/
async buildInputsAndOutputs (floData = '', outputs) {
let utxo
try {
utxo = await this.getUTXO()
} catch (err) {
throw new Error(`Failed to get utxo: ${err}`)
}
// backup in case insight api hasn't given us updated responses
if (utxo.length === 0) {
let start = Date.now(); let finish = 0
console.log('Insight API returned stale results. Waiting on Insight API for update...')
while (utxo.length === 0 && finish < 6000) {
// console.log('while', finish)
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
await delay(500)
try {
utxo = await this.getUTXO()
} catch (err) {
throw new Error(`Failed to get utxo from insight explorer: ${err}`)
}
finish = Date.now() - start
}
}
let formattedUtxos
if (utxo.length === 0) {
// second backup in case insight really is not liking us
console.log('Insight API failed to update. Attempting to manually create utxos...')
formattedUtxos = this.createManualUtxos()
if (formattedUtxos.length === 0) {
throw new Error(`P2PKH: ${this.p2pkh} has no unspent transaction outputs`)
}
} else {
formattedUtxos = utxo.map(utxo => {
return {
address: utxo.address,
txId: utxo.txid,
vout: utxo.vout,
scriptPubKey: utxo.scriptPubKey,
value: utxo.satoshis,
confirmations: utxo.confirmations
}
})
}
// console.log('formatted utxos', formattedUtxos)
outputs = outputs || {
address: this.p2pkh,
value: Math.floor(0.0001 * this.coin.satPerCoin)
}
if (!Array.isArray(outputs)) {
outputs = [outputs]
}
let targets = outputs
let extraBytes = this.coin.getExtraBytes({ floData })
let extraBytesLength = extraBytes.length
// console.log(formattedUtxos)
// let utxosNoUnconfirmed = formattedUtxos.filter(utx => utx.confirmations > 0) //ToDo
// console.log(utxosNoUnconfirmed)
let selected = coinselect(formattedUtxos, targets, Math.ceil(this.coin.feePerByte), extraBytesLength)
// Check if we are able to build inputs/outputs off only unconfirmed transactions with confirmations > 0
if (!selected.inputs || selected.inputs.length === 0 || !selected.outputs || selected.outputs.length === 0 || !selected.fee) {
selected = coinselect(formattedUtxos, targets, Math.ceil(this.coin.feePerByte), extraBytesLength)
}
return selected
}
/**
* Get Unspent Transaction Outputs for the given keypair
* @return {Promise<Array.<utxo>>}
* @example
* const wif = 'cRVa9rNx5N1YKBw8PhavegJPFCiYCfC4n8cYmdc3X1Y6TyFZGG4B'
* let oip = new OIP(wif, "testnet")
* let utxos = await oip.getUTXO()
* for (let tx of utxos) {
* console.log(tx)
* // [ { address: 'ofbB67gqjgaYi45u8Qk2U3hGoCmyZcgbN4',
* // txid: '40bf49a02731b04b71951d2e7782b93bd30678c5f5608f0cfe9cdaed6d392903',
* // vout: 1,
* // scriptPubKey: '76a914f93aef4f4ef998b7ae44bd5bc8f6627b79cdc07588ac',
* // amount: 659.9999325,
* // satoshis: 65999993250,
* // height: 295680,
* // confirmations: 5706
* // } ]
* }
*/
async getUTXO () {
let utxo
try {
utxo = await this.explorer.getAddressUtxo(this.p2pkh)
} catch (err) {
throw new Error(`Error fetching UTXOs: ${err}`)
}
// console.log('preutxo: ', utxo)
// console.log(utxo, this.getSpentTransactions())
return this.removeSpent(utxo)
}
/**
* Removes already spent transactions (that are kept in local memory)
* @param {Array.<utxo>} unspentTransactions - An array of utxos
* @return {Array.<utxo>}
* @example
* //shouldn't ever have to write this. Use `OIP.getUTXO()` instead
* let oip = new OIP(wif, 'testnet')
* let utxo
* try {
* utxo = await oip.explorer.getAddressUtxo(pubAddr)
* } catch (err) {
* throw new Error(`${err}`)
* }
* return oip.removeSpent(utxo)
*/
removeSpent (unspentTransactions) {
if (!unspentTransactions || !Array.isArray(unspentTransactions)) { return }
let unspent = []
for (let tx of unspentTransactions) {
let spent = false
for (let txid of this.getSpentTransactions()) {
if (txid === tx.txid) {
spent = true
}
}
if (!spent) { unspent.push(tx) }
}
return unspent
}
/**
* Manually create Unspent Transaction Outputs from previous known transactions.
* Loops through spent transaction IDs in localStorage and created txs to find outputs to use.
* @return {Array.<utxo>}
*/
createManualUtxos () {
// console.log('manually creating utxos')
let unspents = []
for (let txObj of this.history) {
let match = false
for (let tx of this.getSpentTransactions()) {
for (let txid in txObj) {
if (txid === tx) {
match = true
}
}
}
if (!match) {
// console.log(txObj)
unspents.push(txObj)
}
}
let floTxs = []
for (let txObj of unspents) {
for (let txid in txObj) {
floTxs.push(floTx.fromRaw(txObj[txid], 'hex'))
}
}
// console.log(floTxs)
let utxos = []
for (let f of floTxs) {
// console.log(f)
let outputs = f.outputs
for (let i = 0; i < outputs.length; i++) {
let addr = outputs[i].getAddress()
// console.log(addr)
if (Array.isArray(addr)) {
throw new Error(`Can't handle array output`)
}
// convert mainnet addr -> testnet addr
addr = addr.toBase58()
let { hash } = address.fromBase58Check(addr)
let testnetAddr = address.toBase58Check(hash, 115)
if (testnetAddr === this.p2pkh) {
let tmpObj = {
address: testnetAddr,
txId: f.txid(),
vout: i,
value: outputs[i].value,
scriptPubKey: outputs[i].script.toRaw().toString('hex'),
confirmations: 0
}
// console.log(tmpObj)
utxos.push(tmpObj)
}
}
}
return utxos
}
/**
* Add a spent transaction to local memory
* @param {TXID} txid - transaction id
* @return {void}
* @example
* let oip = new OIP(wif, "testnet")
* let output = {
* address: "oNAydz5TjkhdP3RPuu3nEirYQf49Jrzm4S",
* value: Math.floor(0.001 * floTestnet.satPerCoin)
* }
* let txid = await oip.createAndSendFloTx(output, "sending floData to testnet")
* oip.addSpentTransaction(txid)
* let spentTxs = oip.getSpentTransactions()
* spentTxs === [txid] //true
*/
addSpentTransaction (txid) {
this.spentTransactions.push(txid)
}
/**
* Returns an array of spent transaction ids
* @return {Array.<TXID>}
* @example
* let oip = new OIP(wif, "testnet")
* oip.addSpentTransaction(txid)
* let txids = oip.getSpentTransactions()
* txids = [txid] //true
*/
getSpentTransactions () {
return this.spentTransactions
}
/**
* Broadcast raw transaction hex to the FLO chain
* @param hex
* @return {Promise<string>} txid - Returns a transaction id
*/
async broadcastRawHex (hex) {
let response
try {
response = await this.explorer.broadcastRawTransaction(hex)
} catch (err) {
throw new Error(`Failed to broadcast TX Hex: ${err}`)
}
let txid
/** Handle { txid: "txid" } */
if (response && typeof response.txid === 'string') { txid = response.txid }
/**
* Handle
* {
* txid: {
* result: '05d2dd88d69cc32717d315152bfb474b0b1b561ae9a477aae091714c4ab216ac',
* error: null,
* id: 47070
* }
* }
*/
if (response && response.txid && response.txid.result) {
txid = response.txid.result
}
/**
* Handle
* {
* result: '05d2dd88d69cc32717d315152bfb474b0b1b561ae9a477aae091714c4ab216ac',
* error: null,
* id: 47070
* }
*/
if (response && response.result) {
txid = response.result
}
return txid
}
/**
* Create and send a FLO tx with a custom output
* @param {object|Array.<object>} outputs
* @param {string} floData
* @return {Promise<TXID>}
* @example
* let oip = new OIP(wif, "testnet")
* let output = {
* address: "oNAydz5TjkhdP3RPuu3nEirYQf49Jrzm4S",
* value: 100000000
* }
* let txid = await oip.createAndSendFloTx(output, "to testnet")
*/
async sendTx (outputs, floData = '') {
if (floData && typeof floData !== 'string') {
throw new Error(`Data must be of type string. Got: ${typeof floData}`)
}
if (floData.length > 1040) {
return `Error: data length exceeds 1040 characters.`
}
let hex
try {
hex = await this.buildTXHex(floData, outputs)
} catch (err) {
throw new Error(`Error building TX Hex: ${err}`)
}
let txid
try {
txid = await this.broadcastRawHex(hex)
} catch (err) {
throw new Error(`Error broadcasting TX Hex: ${err}`)
}
// Add txid to spentTransactions for each spent input
for (let inp of this.selected.inputs) {
if (this.p2pkh === inp.address) {
this.addSpentTransaction(inp.txId)
}
}
this.save(txid, hex)
return txid
}
/**
* Saves a transaction to localStorage and memory
* @param {string} txid
* @param {string} hex
* @example
* let oip = new OIP(wif)
* oip.save(`${txid}`, `${hex}`)
*/
save (txid, hex) {
let tmpObj = {}
tmpObj[txid] = hex
this.history.push(tmpObj)
this.serialize()
}
/**
* Stores important local variables to localStorage such as spent transactions and publish history
* @example
* let oip = new OIP(wif)
* oip.serialize() //saves this.spentTransactions and this.history to localStorage memory
*/
serialize () {
let serialized = {
spentTransactions: this.spentTransactions,
history: this.history
}
localStorage.setItem('tx_history', JSON.stringify(serialized))
}
/**
* Imports publisher history from localStorage
* @example
* let oip = new OIP(wif)
* oip.deserialize() //sets this.spentTransactions and this.history from localStorage memory variables
*/
deserialize () {
let deserialized = JSON.parse(localStorage.getItem('tx_history'))
if (!deserialized) { deserialized = {} }
if (deserialized.spentTransactions) {
this.spentTransactions = deserialized.spentTransactions
}
if (deserialized.history) {
this.history = deserialized.history
}
}
/**
* Returns tx history variables
* @example
* let oip = new OIP(wif)
* oip.getTxHistory()
* //returns
* // {
* // history: this.history,
* // spentTransactions: this.spentTransactions
* // }
* @return {{history: Array, spentTransactions: Array}}
*/
getTxHistory () {
return {
history: this.history,
spentTransactions: this.spentTransactions
}
}
/**
* WARNING!!! Deleting history may cause publishing to temporary fail as it might attempt to use spent transactions. Deletes the publisher history from localStorage
* @example
* let oip = new OIP(wif)
* oip.deleteHistory()
*/
deleteHistory () {
localStorage.removeItem('tx_history')
this.spentTransactions = []
this.history = []
}
/**
* Returns the pay-to-pubkey-hash address generated from the given wif
* @return {string}
*/
getPubAddress () {
return this.p2pkh
}
/**
* Returns the ECPair (private/public key pair) generated from the given wif
* @return {object}
*/
getECPair () {
return this.ECPair
}
/**
* Returns information about the current coin (either FLO or FLO_Testnet)
* @return {CoinInfo}
*/
getCoinInfo () {
return this.coin
}
/**
* Returns coin network information needed for address generation
* @return {CoinNetwork}
*/
getNetwork () {
return this.network
}
}
export default ExplorerWallet
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>