forked from electronero-project/electronero-network-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathetnxcWalletRPC.php
1772 lines (1666 loc) · 51.5 KB
/
etnxcWalletRPC.php
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
<?php
/**
*
* monerophp/walletRPC
*
* A class for making calls to monero-wallet-rpc using PHP
* https://github.com/monero-integrations/monerophp
*
* Using work from
* CryptoChangements [Monero_RPC] <[email protected]> (https://github.com/cryptochangements34)
* Serhack [Monero Integrations] <[email protected]> (https://serhack.me)
* TheKoziTwo [xmr-integration] <[email protected]>
* Kacper Rowinski [jsonRPCClient] <[email protected]>
*
* @author Monero Integrations Team <[email protected]> (https://github.com/monero-integrations)
* @copyright 2018
* @license MIT
*
* ============================================================================
*
* // See example.php for more examples
*
* // Initialize class
* $walletRPC = new walletRPC();
*
* // Examples:
* $address = $walletRPC->get_address();
* $signed = $walletRPC->sign('The Times 03/Jan/2009 Chancellor on brink of second bailout for banks');
*
*/
require_once('jsonRPCClient.php');
class etnxcWalletRPC
{
private $client;
private $protocol;
private $host;
private $port;
private $url;
private $user;
private $password;
/**
*
* Start a connection with the Monero wallet RPC interface (monero-wallet-rpc)
*
* @param string $host monero-wallet-rpc hostname (optional)
* @param int $port monero-wallet-rpc port (optional)
* @param string $protocol monero-wallet-rpc protocol (eg. 'http') (optional)
* @param string $user monero-wallet-rpc username (optional)
* @param string $password monero-wallet-rpc passphrase (optional)
*
*/
function __construct ($host = '127.0.0.1', $port = 18083, $protocol = 'http', $user = null, $password = null)
{
if (is_array($host)) { // Parameters passed in as object/dictionary
$params = $host;
if (array_key_exists('host', $params)) {
$host = $params['host'];
} else {
$host = '127.0.0.1';
}
if (array_key_exists('port', $params)) {
$port = $params['port'];
}
if (array_key_exists('protocol', $params)) {
$protocol = $params['protocol'];
}
if (array_key_exists('user', $params)) {
$user = $params['user'];
}
if (array_key_exists('password', $params)) {
$password = $params['password'];
}
}
$this->host = $host;
$this->port = $port;
$this->protocol = $protocol;
$this->user = $user;
$this->password = $password;
$this->url = $protocol.'://'.$host.':'.$port.'/json_rpc';
$this->client = new jsonRPCClient($this->url, $this->user, $this->password);
}
/**
*
* Execute command via jsonRPCClient
*
* @param string $method RPC method to call
* @param object $params Parameters to pass (optional)
*
* @return string Call result
*
*/
private function _run($method, $params = null)
{
$result = $this->client->_run($method, $params);
return $result;
}
/**
*
* Print JSON object (for API)
*
* @param object $json JSON object to print
*
* @return none
*
*/
public function _print($json)
{
echo json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
/**
*
* Convert from moneroj to tacoshi (piconero)
*
* @param number $method Amount (in monero) to transform to tacoshi (piconero) (optional)
*
* @return number
*
*/
public function _transform($amount = 0)
{
//
return $amount * 100;
}
/**
*
* Look up an account's balance
*
* @param number $account_index Index of account to look up (optional)
*
* @return object Example: {
* "balance": 140000000000,
* "unlocked_balance": 50000000000
* }
*
*/
public function get_balance($account_index = 0)
{
$params = array('account_index' => $account_index);
return $this->_run('get_balance', $params);
}
/**
*
* Alias of get_balance()
*
*/
public function getbalance($account_index = 0)
{
return $this->get_balance($account_index);
}
/**
*
* Look up wallet address(es)
*
* @param number $account_index Index of account to look up (optional)
* @param number $address_index Index of subaddress to look up (optional)
*
* @return object Example: {
* "address": "A2XE6ArhRkVZqepY2DQ5QpW8p8P2dhDQLhPJ9scSkW6q9aYUHhrhXVvE8sjg7vHRx2HnRv53zLQH4ATSiHHrDzcSFqHpARF",
* "addresses": [
* {
* "address": "A2XE6ArhRkVZqepY2DQ5QpW8p8P2dhDQLhPJ9scSkW6q9aYUHhrhXVvE8sjg7vHRx2HnRv53zLQH4ATSiHHrDzcSFqHpARF",
* "address_index": 0,
* "label": "Primary account",
* "used": true
* }, {
* "address": "Bh3ttLbjGFnVGCeGJF1HgVh4DfCaBNpDt7PQAgsC2GFug7WKskgfbTmB6e7UupyiijiHDQPmDC7wSCo9eLoGgbAFJQaAaDS",
* "address_index": 1,
* "label": "",
* "used": true
* }
* ]
* }
*
*/
public function get_address($account_index = 0, $address_index = 0)
{
$params = array('account_index' => $account_index, 'address_index' => $address_index);
return $this->_run('get_address', $params);
}
/**
*
* Alias of get_address()
*
* @param number $account_index Index of account to look up (optional)
* @param number $address_index Index of subaddress to look up (optional)
*
* @return object Example: {
* "address": "427ZuEhNJQRXoyJAeEoBaNW56ScQaLXyyQWgxeRL9KgAUhVzkvfiELZV7fCPBuuB2CGuJiWFQjhnhhwiH1FsHYGQGaDsaBA"
* }
*
*/
public function getaddress($account_index = 0, $address_index = 0)
{
return $this->get_address($account_index = 0, $address_index = 0);
}
/**
*
* Create a new subaddress
*
* @param number $account_index The subaddress account index
* @param string $label A label to apply to the new subaddress
*
* @return object Example: {
* "address": "Bh3ttLbjGFnVGCeGJF1HgVh4DfCaBNpDt7PQAgsC2GFug7WKskgfbTmB6e7UupyiijiHDQPmDC7wSCo9eLoGgbAFJQaAaDS"
* "address_index": 1
* }
*
*/
public function create_address($account_index = 0, $label = '')
{
$params = array('account_index' => $account_index, 'label' => $label);
$create_address_method = $this->_run('create_address', $params);
$save = $this->store(); // Save wallet state after subaddress creation
return $create_address_method;
}
/**
*
* Label a subaddress
*
* @param number The index of the subaddress to label
* @param string The label to apply
*
* @return none
*
*/
public function label_address($index, $label)
{
$params = array('index' => $index ,'label' => $label);
return $this->_run('label_address', $params);
}
/**
*
* Look up wallet accounts
*
* @param none
*
* @return object Example: {
* "subaddress_accounts": {
* "0": {
* "account_index": 0,
* "balance": 2808597352948771,
* "base_address": "A2XE6ArhRkVZqepY2DQ5QpW8p8P2dhDQLhPJ9scSkW6q9aYUHhrhXVvE8sjg7vHRx2HnRv53zLQH4ATSiHHrDzcSFqHpARF",
* "label": "Primary account",
* "tag": "",
* "unlocked_balance": 2717153096298162
* },
* "1": {
* "account_index": 1,
* "balance": 0,
* "base_address": "BcXKsfrvffKYVoNGN4HUFfaruAMRdk5DrLZDmJBnYgXrTFrXyudn81xMj7rsmU5P9dX56kRZGqSaigUxUYoaFETo9gfDKx5",
* "label": "Secondary account",
* "tag": "",
* "unlocked_balance": 0
* },
* "total_balance": 2808597352948771,
* "total_unlocked_balance": 2717153096298162
* }
*
*/
public function get_accounts()
{
return $this->_run('get_accounts');
}
/**
*
* Create a new account
*
* @param string $label Label to apply to new account
*
* @return none
*
*/
public function create_account($label = '')
{
$params = array('label' => $label);
$create_account_method = $this->_run('create_account', $params);
$save = $this->store(); // Save wallet state after account creation
return $create_account_method;
}
/**
*
* Label an account
*
* @param number $account_index Index of account to label
* @param string $label Label to apply
*
* @return none
*
*/
public function label_account($account_index, $label)
{
$params = array('account_index' => $account_index, 'label' => $label);
$label_account_method = $this->_run('label_account', $params);
$save = $this->store(); // Save wallet state after account label
return $label_account_method;
}
/**
*
* Look up account tags
*
* @param none
*
* @return object Example: {
* "account_tags": {
* "0": {
* "accounts": {
* "0": 0,
* "1": 1
* },
* "label": "",
* "tag": "Example tag"
* }
* }
* }
*
*/
public function get_account_tags()
{
return $this->_run('get_account_tags');
}
/**
*
* Tag accounts
*
* @param array $accounts The indices of the accounts to tag
* @param string $tag Tag to apply
*
* @return none
*
*/
public function tag_accounts($accounts, $tag)
{
$params = array('accounts' => $accounts, 'tag' => $tag);
$tag_accounts_method = $this->_run('tag_accounts', $params);
$save = $this->store(); // Save wallet state after account tagging
return $tag_accounts_method;
}
/**
*
* Untag accounts
*
* @param array $accounts The indices of the accounts to untag
*
* @return none
*
*/
public function untag_accounts($accounts)
{
$params = array('accounts' => $accounts);
$untag_accounts_method = $this->_run('untag_accounts', $params);
$save = $this->store(); // Save wallet state after untagging accounts
return $untag_accounts_method;
}
/**
*
* Describe a tag
*
* @param string $tag Tag to describe
* @param string $description Description to apply to tag
*
* @return object Example: {
* // TODO example
* }
*
*/
public function set_account_tag_description($tag, $description)
{
$params = array('tag' => $tag, 'description' => $description);
$set_account_tag_description_method = $this->_run('set_account_tag_description', $params);
$save = $this->store(); // Save wallet state after describing tag
return $set_account_tag_description_method;
}
/**
*
* Look up how many blocks are in the longest chain known to the wallet
*
* @param none
*
* @return object Example: {
* "height": 994310
* }
*
*/
public function get_height()
{
return $this->_run('get_height');
}
/**
*
* Alias of get_height()
*
*/
public function getheight()
{
return $this->get_height();
}
/**
*
* Send monero
* Parameters can be passed in individually (as listed below) or as an object/dictionary (as listed at bottom)
* To send to multiple recipients, use the object/dictionary (bottom) format and pass an array of recipient addresses and amount arrays in the destinations field (as in "destinations = [['amount' => 1, 'address' => ...], ['amount' => 2, 'address' => ...]]")
*
* @param string $amount Amount of monero to send
* @param string $address Address to receive funds
* @param string $payment_id Payment ID (optional)
* @param number $mixin Mixin number (ringsize - 1) (optional)
* @param number $account_index Account to send from (optional)
* @param string $subaddr_indices Comma-separated list of subaddress indices to spend from (optional)
* @param number $priority Transaction priority (optional)
* @param number $unlock_time UNIX time or block height to unlock output (optional)
* @param boolean $do_not_relay Do not relay transaction (optional)
*
* OR
*
* @param object $params Array containing any of the options listed above, where only amount and address or a destionation's array are required
*
* @return object Example: {
* "amount": "1000000000000",
* "fee": "1000020000",
* "tx_hash": "c60a64ddae46154a75af65544f73a7064911289a7760be8fb5390cb57c06f2db",
* "tx_key": "805abdb3882d9440b6c80490c2d6b95a79dbc6d1b05e514131a91768e8040b04"
* }
*
*/
public function transfer($amount, $address = '', $payment_id = '', $mixin = 6, $account_index = 0, $subaddr_indices = '', $priority = 2, $unlock_time = 0, $do_not_relay = false)
{
if (is_array($amount)) { // Parameters passed in as object/dictionary
$params = $amount;
if (array_key_exists('destinations', $params)) {
$destinations = $params['destinations'];
if (!is_array($destinations)) {
throw new Exception('Error: destinations must be an array');
}
foreach ($destinations as $destination) {
if (array_key_exists('amount', $destinations[$destination])) {
$destinations[$destination]['amount'] = $this->_transform($destinations[$destination]['amount']);
} else {
throw new Exception('Error: Amount required');
}
if (!array_key_exists('address', $destinations[$destination])) {
throw new Exception('Error: Address required');
}
}
} else {
if (array_key_exists('amount', $params)) {
$amount = $params['amount'];
} else {
throw new Exception('Error: Amount required');
}
if (array_key_exists('address', $params)) {
$address = $params['address'];
} else {
throw new Exception('Error: Address required');
}
$destinations = array(array('amount' => $this->_transform($amount), 'address' => $address));
}
if (array_key_exists('payment_id', $params)) {
$payment_id = $params['payment_id'];
}
if (array_key_exists('mixin', $params)) {
$mixin = $params['mixin'];
}
if (array_key_exists('account_index', $params)) {
$account_index = $params['account_index'];
}
if (array_key_exists('subaddr_indices', $params)) {
$subaddr_indices = $params['subaddr_indices'];
}
if (array_key_exists('priority', $params)) {
$priority = $params['priority'];
}
if (array_key_exists('unlock_time', $params)) {
$unlock_time = $params['unlock_time'];
}
if (array_key_exists('do_not_relay', $params)) {
$do_not_relay = $params['do_not_relay'];
}
} else { // Legacy parameters used
$destinations = array(array('amount' => $this->_transform($amount), 'address' => $address));
}
$params = array('destinations' => $destinations, 'mixin' => $mixin, 'get_tx_key' => true, 'payment_id' => $payment_id, 'account_index' => $account_index, 'subaddr_indices' => $subaddr_indices, 'priority' => $priority, 'do_not_relay' => $do_not_relay);
$transfer_method = $this->_run('transfer', $params);
$save = $this->store(); // Save wallet state after transfer
return $transfer_method;
}
/**
*
* Same as transfer, but splits transfer into more than one transaction if necessary
*
*/
public function transfer_split($amount, $address = '', $payment_id = '', $mixin = 6, $account_index = 0, $subaddr_indices = '', $priority = 2, $unlock_time = 0, $do_not_relay = false)
{
if (is_array($amount)) { // Parameters passed in as object/dictionary
$params = $amount;
if (array_key_exists('destinations', $params)) {
$destinations = $params['destinations'];
if (!is_array($destinations)) {
throw new Exception('Error: destinations must be an array');
}
foreach ($destinations as $destination) {
if (array_key_exists('amount', $destinations[$destination])) {
$destinations[$destination]['amount'] = $this->_transform($destinations[$destination]['amount']);
} else {
throw new Exception('Error: Amount required');
}
if (!array_key_exists('address', $destinations[$destination])) {
throw new Exception('Error: Address required');
}
}
} else {
if (array_key_exists('amount', $params)) {
$amount = $params['amount'];
} else {
throw new Exception('Error: Amount required');
}
if (array_key_exists('address', $params)) {
$address = $params['address'];
} else {
throw new Exception('Error: Address required');
}
$destinations = array(array('amount' => $this->_transform($amount), 'address' => $address));
}
if (array_key_exists('mixin', $params)) {
$mixin = $params['mixin'];
}
if (array_key_exists('payment_id', $params)) {
$payment_id = $params['payment_id'];
}
if (array_key_exists('account_index', $params)) {
$account_index = $params['account_index'];
}
if (array_key_exists('subaddr_indices', $params)) {
$subaddr_indices = $params['subaddr_indices'];
}
if (array_key_exists('priority', $params)) {
$priority = $params['priority'];
}
if (array_key_exists('unlock_time', $params)) {
$unlock_time = $params['unlock_time'];
}
if (array_key_exists('do_not_relay', $params)) {
$do_not_relay = $params['do_not_relay'];
}
} else { // Legacy parameters used
$destinations = array(array('amount' => $this->_transform($amount), 'address' => $address));
}
$params = array('destinations' => $destinations, 'mixin' => $mixin, 'get_tx_key' => true, 'account_index' => $account_index, 'subaddr_indices' => $subaddr_indices, 'payment_id' => $payment_id, 'priority' => $priority, 'unlock_time' => $unlock_time, 'do_not_relay' => $do_not_relay);
$transfer_method = $this->_run('transfer_split', $params);
$save = $this->store(); // Save wallet state after transfer
return $transfer_method;
}
/**
*
* Send all dust outputs back to the wallet
*
* @param none
*
* @return object Example: {
* // TODO example
* }
*
*/
public function sweep_dust()
{
return $this->_run('sweep_dust');
}
/**
*
* Send all unmixable outputs back to the wallet
*
* @param none
*
* @return object Example: {
* // TODO example
* }
*
*/
public function sweep_unmixable()
{
return $this->_run('sweep_unmixable');
}
/**
*
* Send all unlocked outputs from an account to an address
*
* @param string $address Address to receive funds
* @param string $subaddr_indices Comma-separated list of subaddress indices to sweep (optional)
* @param number $account_index Index of the account to sweep (optional)
* @param string $payment_id Payment ID (optional)
* @param number $mixin Mixin number (ringsize - 1) (optional)
* @param number $priority Payment ID (optional)
* @param number $below_amount Only send outputs below this amount (optional)
* @param number $unlock_time UNIX time or block height to unlock output (optional)
* @param boolean $do_not_relay Do not relay transaction (optional)
*
* OR
*
* @param object $params Array containing any of the options listed above, where only address is required
*
* @return object Example: {
* "amount": "1000000000000",
* "fee": "1000020000",
* "tx_hash": "c60a64ddae46154a75af65544f73a7064911289a7760be8fb5390cb57c06f2db",
* "tx_key": "805abdb3882d9440b6c80490c2d6b95a79dbc6d1b05e514131a91768e8040b04"
* }
*
*/
public function sweep_all($address, $subaddr_indices = '', $account_index = 0, $payment_id = '', $mixin = 6, $priority = 2, $below_amount = 0, $unlock_time = 0, $do_not_relay = false)
{
if (is_array($address)) { // Parameters passed in as object/dictionary
$params = $address;
if (array_key_exists('address', $params)) {
$address = $params['address'];
} else {
throw new Exception('Error: Address required');
}
if (array_key_exists('subaddr_indices', $params)) {
$subaddr_indices = $params['subaddr_indices'];
}
if (array_key_exists('account_index', $params)) {
$account_index = $params['account_index'];
}
if (array_key_exists('payment_id', $params)) {
$payment_id = $params['payment_id'];
}
if (array_key_exists('mixin', $params)) {
$mixin = $params['mixin'];
}
if (array_key_exists('priority', $params)) {
$priority = $params['priority'];
}
if (array_key_exists('below_amount', $params)) {
$below_amount = $params['below_amount'];
}
if (array_key_exists('unlock_time', $params)) {
$unlock_time = $params['unlock_time'];
}
if (array_key_exists('do_not_relay', $params)) {
$do_not_relay = $params['do_not_relay'];
}
}
$params = array('address' => $address, 'mixin' => $mixin, 'get_tx_key' => true, 'subaddr_indices' => $subaddr_indices, 'account_index' => $account_index, 'payment_id' => $payment_id, 'priority' => $priority, 'below_amount' => $this->_transform($below_amount), 'unlock_time' => $unlock_time, 'do_not_relay' => $do_not_relay);
$sweep_all_method = $this->_run('sweep_all', $params);
$save = $this->store(); // Save wallet state after transfer
return $sweep_all_method;
}
/**
*
* Sweep a single key image to an address
*
* @param string $key_image Key image to sweep
* @param string $address Address to receive funds
* @param string $payment_id Payment ID (optional)
* @param number $below_amount Only send outputs below this amount (optional)
* @param number $mixin Mixin number (ringsize - 1) (optional)
* @param number $priority Payment ID (optional)
* @param number $unlock_time UNIX time or block height to unlock output (optional)
* @param boolean $do_not_relay Do not relay transaction (optional)
*
* OR
*
* @param object $params Array containing any of the options listed above, where only address is required
*
* @return object Example: {
* "amount": "1000000000000",
* "fee": "1000020000",
* "tx_hash": "c60a64ddae46154a75af65544f73a7064911289a7760be8fb5390cb57c06f2db",
* "tx_key": "805abdb3882d9440b6c80490c2d6b95a79dbc6d1b05e514131a91768e8040b04"
* }
*
*/
public function sweep_single($key_image, $address, $payment_id = '', $mixin = 6, $priority = 2, $below_amount = 0, $unlock_time = 0, $do_not_relay = 0)
{
if (is_array($key_image)) { // Parameters passed in as object/dictionary
$params = $key_image;
if (array_key_exists('key_image', $params)) {
$key_image = $params['key_image'];
} else {
throw new Exception('Error: Key image required');
}
if (array_key_exists('address', $params)) {
$address = $params['address'];
} else {
throw new Exception('Error: Address required');
}
if (array_key_exists('payment_id', $params)) {
$payment_id = $params['payment_id'];
}
if (array_key_exists('mixin', $params)) {
$mixin = $params['mixin'];
}
if (array_key_exists('account_index', $params)) {
$account_index = $params['account_index'];
}
if (array_key_exists('priority', $params)) {
$priority = $params['priority'];
}
if (array_key_exists('unlock_time', $params)) {
$unlock_time = $params['unlock_time'];
}
if (array_key_exists('unlock_time', $params)) {
$unlock_time = $params['unlock_time'];
}
if (array_key_exists('below_amount', $params)) {
$below_amount = $params['below_amount'];
}
if (array_key_exists('do_not_relay', $params)) {
$do_not_relay = $params['do_not_relay'];
}
}
$params = array('address' => $address, 'mixin' => $mixin, 'get_tx_key' => true, 'account_index' => $account_index, 'payment_id' => $payment_id, 'priority' => $priority, 'below_amount' => $this->_transform($below_amount), 'unlock_time' => $unlock_time, 'do_not_relay' => $do_not_relay);
$sweep_single_method = $this->_run('sweep_single', $params);
$save = $this->store(); // Save wallet state after transfer
return $sweep_single_method;
}
/**
*
* Relay a transaction
*
* @param string $hex Blob of transaction to relay
*
* @return object // TODO example
*
*/
public function relay_tx($hex)
{
$params = array('hex' => $hex);
$relay_tx_method = $this->_run('relay_tx_method', $params);
$save = $this->store(); // Save wallet state after transaction relay
return $this->_run('relay_tx');
}
/**
*
* Save wallet
*
* @param none
*
* @return object Example:
*
*/
public function store()
{
return $this->_run('store');
}
/**
*
* Look up incoming payments by payment ID
*
* @param string $payment_id Payment ID to look up
*
* @return object Example: {
* "payments": [{
* "amount": 10350000000000,
* "block_height": 994327,
* "payment_id": "4279257e0a20608e25dba8744949c9e1caff4fcdafc7d5362ecf14225f3d9030",
* "tx_hash": "c391089f5b1b02067acc15294e3629a463412af1f1ed0f354113dd4467e4f6c1",
* "unlock_time": 0
* }]
* }
*
*/
public function get_payments($payment_id)
{
// $params = array('payment_id' => $payment_id); // does not work
$params = [];
$params['payment_id'] = $payment_id;
return $this->_run('get_payments', $params);
}
/**
*
* Look up incoming payments by payment ID (or a list of payments IDs) from a given height
*
* @param array $payment_ids Array of payment IDs to look up
* @param string $min_block_height Height to begin search
*
* @return object Example: {
* "payments": [{
* "amount": 10350000000000,
* "block_height": 994327,
* "payment_id": "4279257e0a20608e25dba8744949c9e1caff4fcdafc7d5362ecf14225f3d9030",
* "tx_hash": "c391089f5b1b02067acc15294e3629a463412af1f1ed0f354113dd4467e4f6c1",
* "unlock_time": 0
* }]
* }
*
*/
public function get_bulk_payments($payment_ids, $min_block_height)
{
// $params = array('payment_ids' => $payment_ids, 'min_block_height' => $min_block_height); // does not work
$params = array('min_block_height' => $min_block_height); // does not work
$params = [];
if (!is_array($payment_ids)) {
throw new Exception('Error: Payment IDs must be array.');
}
if ($payment_ids) {
$params['payment_ids'] = [];
foreach ($payment_ids as $payment_id) {
array_push($params['payment_ids'], $payment_id);
}
}
return $this->_run('get_bulk_payments', $params);
}
/**
*
* Look up incoming transfers
*
* @param string $type Type of transfer to look up; must be 'all', 'available', or 'unavailable' (incoming transfers which have already been spent)
* @param number $account_index Index of account to look up (optional)
* @param string $subaddr_indices Comma-separated list of subaddress indices to look up (optional)
*
* @return object Example: {
* "transfers": [{
* "amount": 10000000000000,
* "global_index": 711506,
* "spent": false,
* "tx_hash": "c391089f5b1b02067acc15294e3629a463412af1f1ed0f354113dd4467e4f6c1",
* "tx_size": 5870
* },{
* "amount": 300000000000,
* "global_index": 794232,
* "spent": false,
* "tx_hash": "c391089f5b1b02067acc15294e3629a463412af1f1ed0f354113dd4467e4f6c1",
* "tx_size": 5870
* },{
* "amount": 50000000000,
* "global_index": 213659,
* "spent": false,
* "tx_hash": "c391089f5b1b02067acc15294e3629a463412af1f1ed0f354113dd4467e4f6c1",
* "tx_size": 5870
* }]
* }
*/
public function incoming_transfers($type = 'all', $account_index = 0, $subaddr_indices = '')
{
$params = array('transfer_type' => $type, 'account_index' => $account_index, 'subaddr_indices' => $subaddr_indices);
return $this->_run('incoming_transfers', $params);
}
/**
*
* Look up a wallet key
*
* @param string $key_type Type of key to look up; must be 'view_key', 'spend_key', or 'mnemonic'
*
* @return object Example: {
* "key": "7e341d..."
* }
*
*/
public function query_key($key_type)
{
$params = array('key_type' => $key_type);
return $this->_run('query_key', $params);
}
/**
*
* Look up wallet view key
*
* @param none
*
* @return object Example: {
* "key": "7e341d..."
* }
*
*/
public function view_key()
{
$params = array('key_type' => 'view_key');
return $this->_run('query_key', $params);
}
/**
*
* Look up wallet spend key
*
* @param none
*
* @return object Example: {
* "key": "2ab810..."
* }
*
*/
public function spend_key()
{
$params = array('key_type' => 'spend_key');
return $this->_run('query_key', $params);
}
/**
*
* Look up wallet mnemonic seed
*
* @param none
*
* @return object Example: {
* "key": "2ab810..."
* }
*
*/
public function mnemonic()
{
$params = array('key_type' => 'mnemonic');
return $this->_run('query_key', $params);
}
/**
*
* Create an integrated address from a given payment ID
*
* @param string $payment_id Payment ID (optional)
*
* @return object Example: {
* "integrated_address": "4BpEv3WrufwXoyJAeEoBaNW56ScQaLXyyQWgxeRL9KgAUhVzkvfiELZV7fCPBuuB2CGuJiWFQjhnhhwiH1FsHYGQQ8H2RRJveAtUeiFs6J"
* }
*
*/
public function make_integrated_address($payment_id = null)
{
$params = array('payment_id' => $payment_id);
return $this->_run('make_integrated_address', $params);
}
/**
*
* Look up the wallet address and payment ID corresponding to an integrated address
*
* @param string $integrated_address Integrated address to split
*
* @return object Example: {
* "payment_id": "420fa29b2d9a49f5",
* "standard_address": "427ZuEhNJQRXoyJAeEoBaNW56ScQaLXyyQWgxeRL9KgAUhVzkvfiELZV7fCPBuuB2CGuJiWFQjhnhhwiH1FsHYGQGaDsaBA"
* }
*
*/
public function split_integrated_address($integrated_address)
{
$params = array('integrated_address' => $integrated_address);
return $this->_run('split_integrated_address', $params);
}
/**
*
* Stop the wallet, saving the state
*
* @param none
*
* @return none