-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoindwrapper.php
More file actions
1356 lines (1228 loc) · 49.9 KB
/
Copy pathcoindwrapper.php
File metadata and controls
1356 lines (1228 loc) · 49.9 KB
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
/**
* Created by PhpStorm.
* Author: James Kirkby
* www.cryptowallet.io
* Date: 14/05/2015
* Time: 15:30
*/
require_once('rpcfunctions/RpcFactory.php');
use cryptocoindwrapper\rpcfunctions\Rpc\RpcFactory;
class coindWrapper
{
function __construct($coind_server){
$this->client = RpcFactory::coind($coind_server['user'],$coind_server['pass'],$coind_server['host'],$coind_server['port']);
return $this->client;
}
/**
* Add a nrequired-to-sign multisignature address to the wallet
*
* Each key is a address or hex-encoded public key. If $account is specified, assign address to $account.
*
* Returns the the multi-signature address.
*
* @param int $nrequired Number of keys needed to redeem
* @param array $keys Array of public keys
* @param string $account Name of account which receives the address
* @return string
*/
public function addMultiSignatureAddress($nrequired, array $keys, $account = null)
{
// Can't use null for $account. Must be left out of the args completely when not specified.
$nrequired= (int)$nrequired;
$account = (string)$account;
return $this->client->addmultisigaddress($nrequired,$keys,$account);
}
/**
* Attempts add or remove a node from the addnode list or try a connection to it once
*
* @param string $node The node ip address and port in <ip>:<port> format (see getPeerInfo() for nodes)
* @param string $type Use "add" to add a node to the list, "remove" to remove a node from the list, "onetry" to try a connection to the node once
* @return bool
*/
public function addNode($node, $type)
{
$node = (string)$node;
$type = (string)$type;
return null === $this->client->addnode($node, $type);
}
/**
* Safely copies wallet.dat to $destination
*
* The destination can be a directory or a path with filename.
*
* @param string $destination The destination directory or file
* @return bool
*/
public function backup($destination)
{
$destination = (string)$destination;
return null === $this->client->backup($destination);
}
/**
* Returns a new multi-signature address
*
* Returns an array with the following keys:
* ```
* "address" - (string) The multi-signature address
* "redeemScript" - (string) The redeem script
* ```
*
* @param int $nrequired Number of keys needed to redeem
* @param array $keys Array of public keys
* @return array
*/
public function getNewMultiSignatureAddress($nrequired, array $keys)
{
$nrequired = (int)$nrequired;
return $this->client->createmultisig($nrequired,$keys);
}
/**
* Returns an array containing various state info
*
* The returned array contains the following keys:
* ```
* "version" - (int) The server version.
* "protocolversion" - (int) The protocol version.
* "walletversion" - (int) The wallet version.
* "balance" - (double) The total bitcoin balance of the wallet.
* "blocks" - (int) The current number of blocks processed in the server.
* "timeoffset" - (int) The time offset.
* "connections" - (int) The number of connections.
* "proxy" - (string) The proxy used by the server.
* "difficulty" - (double) The current difficulty.
* "testnet" - (boolean) If the server is using testnet or not.
* "keypoololdest" - (int) The timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool.
* "keypoolsize" - (int) How many new keys are pre-generated.
* "unlocked_until" - (int) The timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked.
* "paytxfee" - (double) The transaction fee set in btc/kb.
* "errors" - (string) Any error messages.
* ```
* @return array
*/
/**
* Returns a hex-encoded raw transaction spending the given inputs and sending to the given addresses
*
* The $transactions argument is a multidimensional array, which each value being an array with the following keys:
* ```
* "txid" - (string) The transaction id.
* "vout" - (int) The output number.
* ```
*
* The $addresses argument is an associative array using addresses for keys, and amounts to send to the address
* as values. For example:
* ```php
* [
* "1Headz2mYtpBRo6KFaaUEtcm5Kce6BZRJM" => 0.5,
* "1FVCaRTKQtpxeE4gypz69NvDkyZUd7Y3SJ" => 0.08
* ]
* ```
*
* **Note:** This method only creates the raw transaction data. The transaction's inputs are not signed, and it is not
* stored in the wallet or transmitted to the network.
*
* Example:
* ```php
* $transactions = [
* [
* "txid" => "7de4c9a1e715a9aaf6f8573ce16f8bc3c06f927826e2d0c39424e1524eccda89",
* "vout" => 1
* ],
* [
* "tdid" => "d2e611dcb3348c315dadeaa959cff662328f124e3a3e80fe8f33056bac95b9fe",
* "vout" => 2
* ]
* ];
* $addresses = [
* "1Headz2mYtpBRo6KFaaUEtcm5Kce6BZRJM" => 0.5,
* "13P4LpjYyBvWt283DffjsHpoFWFprr9dVq" => 0.08
* ];
* $raw = $api->createRawTransaction($transactions, $addresses);
* ```
*
* @param array $transactions The transactions
* @param array $addresses Array using addresses for keys, and amounts for values
* @return array
*/
public function createRawTransaction(array $transactions, array $addresses)
{
return $this->client->createrawtransaction($transactions,$addresses);
}
/**
* Decodes a raw serialized transaction
*
* Given a serialized, hex-encoded transaction, the method decodes it, and returns an array of the transaction
* information.
*
* Returns an array with the following keys:
* ```
* "hex" - (string) The serialized, hex-encoded data.
* "txid" - (string) The transaction id.
* "version" - (int) The version.
* "locktime" - (int) The lock time.
* "vin" - (array) An array with the following keys:
* "txid" - (string) The transaction id.
* "vout" - (int) The vout index.
* "scriptSig" - (array) The script, an array with keys:
* "asm" - (string) Script in asm format.
* "hex" - (string) Script in hex format.
* "sequence" - (int) The script sequence number.
* "vout" - (array) An array with the following keys:
* "value" - (double) The amount sent.
* "n" - (int) The index.
* "scriptPubKey" - (array) An array with the following keys:
* "asm" - (string) The script in asm format.
* "hex" - (string) The script in hex format.
* "reqSigs" - (int) The number of required sigs.
* "type" - (string) The type, eg 'pubkeyhash'.
* "addresses" - (array) An array of addresses.
* "blockhash" - (string) The block hash.
* "confirmations" - (int) The number of confirmations.
* "time" - (int) The transaction time in seconds since epoch (Jan 1 1970 GMT).
* "blocktime" - (int) The block time in seconds since epoch (Jan 1 1970 GMT).
* ```
*
* @param string $hex_string The serialized, hex-encoded transaction data
* @return array
*/
public function decodeRawTransaction($hex_string)
{
$hex_string = (string)$hex_string;
return $this->client->decoderawtransaction($hex_string);
}
/**
* Returns the private key for the given address
*
* Returns null when the address does not belong to any wallet account.
*
* @param string $address The address for the private key
* @return string
*/
public function getPrivateKeyByAddress($address)
{
$address = (string)$address;
return $this->client->dumpprivkey($address);
}
/**
* Encrypts the wallet with the given pass phrase
*
* After this, any calls that interact with private keys such as sending or signing will require the passphrase to
* be set prior the making these calls. Use the unlock() for this, and then lock().
*
* **Note:** This will shutdown the server.
*
* @param string $pass_phrase The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long
* @return bool
*/
public function encrypt($pass_phrase)
{
$pass_phrase = (string)$pass_phrase;
return null === $this->client->encryptwallet($pass_phrase);
}
/**
* Returns the account associated with the given address
*
* Returns the account associated with the given address.
*
* @param string $address The address for account lookup
* @return string|null
*/
public function getAccount($address) {
$address = (string)$address;
return $this->client->getaccount($address);
}
/**
* Returns the address associated with the given account
*
* Returns null when an address does not exist for the given account.
*
* @param string $address The address for account lookup
* @return string|null
*/
public function getAccountAddress($account) {
$account = (string)$account;
return $this->client->getaccountaddress($account);
}
/**
* Returns information about the given added node, or all added nodes
*
* If dns is false, only a list of added nodes will be provided, otherwise connected information will also
* be available.
*
* **Note:** Nodes added using the addnode configuration and "onetry" nodes are not returned.
*
* When $dns is false, returns multidimensional array, with sub-arrays containing the keys:
* ```
* "addednode" - (string) The node ip address and port in format <ip>:<port>.
* ```
*
* When $dns is true, returns a mutlidimentional array, with the sub-arrays containing the keys:
* ```
* "addednode" - (string) The node ip address and port in format <ip>:<port>.
* "connected" - (boolean) If connected.
* "addresses" - (array) Array of node peers. Each sub-array contains the keys:
* "address" - (string) The node ip address and port in format <ip>:<port>.
* "connected" - (bool) If connected.
* ```
*
* @param bool $dns If false, only a list of added nodes will be provided, otherwise connected information will also be available
* @param string $node If provided, return information about this specific node, otherwise all nodes are returned
* @return array
*/
public function getNodeInfo($dns, $node = null)
{
// Can't pass null as the second arg. The arg must not exist.
$dns =(bool)$dns;
if (null !== $node) {
$node = (string)$node;
}
return $this->client->getaddednodeinfo($dns,$node);
}
/**
* Returns the addresses for the given account
*
* @param string $account The account name, using "" to represent the default account
* @return array
*/
public function getAddressesByAccount($account)
{
$account = (string)$account;
return $this->client->getaddressesbyaccount($account);
}
/**
* Returns the balance for the entire wallet
*
* @return double
*/
public function getBalance($account)
{
return $this->client->getbalance($account);
}
/**
* Returns the hash of the best (tip) block in the longest block chain
*
* @return string
*/
public function getBestBlockHash()
{
return $this->client->getbestblockhash();
}
/**
* Returns information about the block with the given hash
*
* When $verbose is set to false, this method returns the serialized and hex-encoded block data.
*
* When $verbose is set to true, the return value will be an array with the following keys:
* ```
* "hash" - (string) The block hash (same as provided).
* "confirmations" - (int) The number of confirmations.
* "size" - (int) The block size.
* "height" - (int) The block height or index.
* "version" - (int) The block version.
* "merkleroot" - (string) The merkle root.
* "tx" - (array) The transaction ids.
* "time" - (int) The block time in seconds since epoch (Jan 1 1970 GMT).
* "nonce" - (double) The nonce.
* "bits" - (string) The bits.
* "difficulty" - (double) The difficulty.
* "previousblockhash" - (string) The hash of the previous block.
* "nextblockhash" - (string) The hash of the next block.
* ```
*
* @param string $hash The block hash
* @param bool $verbose True for an array, false for the hex encoded data
* @return array|string
*/
public function getBlock($hash, $verbose = true)
{
$hash = (string)$hash;
$verbose = (bool)$verbose;
return $this->client->getblock($hash, $verbose);
}
/**
* Returns the number of blocks in the longest block chain
*
* @return int
*/
public function getBlockCount()
{
return $this->client->getblockcount();
}
/**
* Returns hash of block in best-block-chain at $index
*
* Index 0 is the genesis block.
*
* @param int $index The block index
* @return string
*/
public function getBlockHash($index)
{
$index = (int)$index;
return $this->client->getblockhash($index);
}
/**
* Returns data needed to construct a block to work on
*
* If the $mode argument is set, that is used to explicitly select between the default "template"
* request or a "proposal".
*
* The returned array contains the following keys:
* ```
* "version" - (int) The block version.
* "previousblockhash" - (string) The hash of current highest block.
* "transactions" - (array) Array of non-coinbase transactions which should be included in the block. Each contains the following keys:
* "data" - (string) Transaction data encoded in hexadecimal (byte-for-byte).
* "hash" - (string) Hash/id encoded in little-endian hexadecimal.
* "depends" - (array) Array of numbers.
* "fee" - (int) Difference in value between transaction inputs and outputs (in Satoshis); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one.
* "sigops" - (int) Total number of SigOps, as counted for purposes of block limits; if key is not present, sigop count is unknown and clients MUST NOT assume there aren't any.
* "required" - (boolean) If provided and true, this transaction must be in the final block.
* "coinbaseaux" - (array) Array of data that should be included in the coinbase's scriptSig content. Contains the following key:
* "flags" - (string) The data to include.
* "coinbasevalue" - (double) Maximum allowable input to coinbase transaction, including the generation award and transaction fees (in Satoshis).
* "coinbasetxn" - (array) Information for coinbase transaction.
* "target" - (string) The hash target.
* "mintime" - (int) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT).
* "mutable" - (array) List of ways the block template may be changed. Contains the following keys:
* "value" - (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'.
* "noncerange" - (string) A range of valid nonces.
* "sigoplimit" - (int) Limit of sigops in blocks.
* "sizelimit" - (int) Limit of block size.
* "curtime" - (int) Current timestamp in seconds since epoch (Jan 1 1970 GMT).
* "bits" - (string) Compressed target of next block.
* "height" - (int) The height of the next block.
* ```
*
* @see https://en.bitcoin.it/wiki/BIP_0022
* @param array $capabilities An array of supported features, "longpoll", "coinbasetxn", "coinbasevalue", "proposal", "serverlist", "workid"
* @param string|null $mode This must be set to "template" or omitted
* @return array
*/
public function getBlockTemplate(array $capabilities = [], $mode = null)
{
$params = new \stdClass();
$params->capabilities = $capabilities;
if (null !== $mode) {
$params->mode = $mode;
}
return $this->client->getblocktemplate($params);
}
/**
* Returns the number of connections to other nodes
*
* @return int
*/
public function getConnectionCount()
{
return $this->client->getconnectioncount();
}
/**
* Returns the proof-of-work difficulty as a multiple of the minimum difficulty
*
* @return double
*/
public function getDifficulty()
{
return $this->client->getdifficulty();
}
/**
* Returns true or false whether the wallet is currently generating hashes
*
* @return bool
*/
public function getGenerate()
{
return $this->client->getgenerate();
}
/**
* Returns a recent hashes per second performance measurement while generating
*
* See the getGenerate() and setGenerate() calls to turn generation on and off.
*
* @return int
*/
public function getHashesPerSec()
{
return $this->client->gethashespersec();
}
/**
* Returns an object containing various state info.
* @return mixed
*/
public function getInfo()
{
return $this->client->getinfo();
}
/**
* Returns an array of mining related information
*
* The returned array contains the following keys:
* ```
* "blocks" - (int) The current block.
* "currentblocksize" - (int) The last block size.
* "currentblocktxt" - (int) The last block transaction.
* "difficulty" - (double) The current difficulty.
* "errors" - (string) Current errors.
* "generate" - (boolean) If the generation is on or off.
* "genproclimit" - (int) The processor limit for generation. -1 if no generation.
* "hashespersec" - (int) The hashes per second of the generation, or 0 if no generation.
* "networkhashps" - (double) The estimated network hashes per second based on the last n blocks.
* "pooledtxt" - (int) The size of the mem pool.
* "testnet" - (boolean) If using testnet or not.
* ```
*
* @return array
*/
public function getMiningInfo()
{
return $this->client->getmininginfo();
}
/**
* Returns a new address for receiving payments
*
* If $account is specified (recommended), it is added to the address book so payments received with the address
* will be credited to $account.
*
* @param string $account The account name for the address to be linked to, using "" to represent the default account
* @return string
*/
public function getNewAddress($account)
{
$account = (string)$account;
return $this->client->getnewaddress($account);
}
/**
* Returns an array describing each connected node
*
* Returns an mutlidimentional array, which each sub-array containing the following keys:
* ```
* "addr" - (string) The ip address and port of the peer.
* "addrlocal" - (string) The local address.
* "services" - (string) The supported services.
* "lastsend" - (int) The time in seconds since epoch (Jan 1 1970 GMT) of the last send.
* "lastrecv" - (int) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive.
* "bytessent" - (int) The total bytes sent.
* "bytesrecv" - (int) The total bytes received.
* "conntime" - (int) The connection time in seconds since epoch (Jan 1 1970 GMT).
* "pingtime" - (double) The ping time.
* "version" - (int) The peer version, such as 7001.
* "subver" - (string) The string version, such as "Satoshi:0.8.5".
* "inbound" - (boolean) Inbound (true) or Outbound (false).
* "startingheight" - (int) The starting height (block) of the peer.
* "banscore" - (int) The ban score (stats.nMisbehavior).
* "syncnode" - (boolean) True if sync node.
* ```
*
* @return array
*/
public function getPeerInfo()
{
return $this->client->getpeerinfo();
}
/**
* Returns a new address for receiving change
*
* This is for use with raw transactions, NOT normal use.
*
* @param string $account Name of the account, using "" to represent the default account
* @return string
*/
public function getRawChangeAddress($account)
{
$args = [
(string)$account
];
return $this->client->getrawchangeaddress($args);
}
/**
* Returns an array of transaction ids in memory pool
*
* @return array
*/
public function getTransactionsFromMemoryPool()
{
return $this->client->query("getrawmempool");
}
/**
* Returns raw transaction representation for given transaction id
*
* Returns the raw transaction data as a string when $verbose is 0. Use decodeRawTransaction() to convert the
* transaction data into an array.
*
* Returns an array with the following keys when $verbose is 1.
* ```
* "hex" - (string) The serialized, hex-encoded data.
* "txid" - (string) The transaction id.
* "version" - (int) The version.
* "locktime" - (int) The lock time.
* "vin" - (array) An array with the following keys:
* "txid" - (string) The transaction id.
* "vout" - (int) The vout index.
* "scriptSig" - (array) The script, an array with keys:
* "asm" - (string) Script in asm format.
* "hex" - (string) Script in hex format.
* "sequence" - (int) The script sequence number.
* "vout" - (array) An array with the following keys:
* "value" - (double) The amount sent.
* "n" - (int) The index.
* "scriptPubKey" - (array) An array with the following keys:
* "asm" - (string) The script in asm format.
* "hex" - (string) The script in hex format.
* "reqSigs" - (int) The number of required sigs.
* "type" - (string) The type, eg 'pubkeyhash'.
* "addresses" - (array) An array of addresses.
* "blockhash" - (string) The block hash.
* "confirmations" - (int) The number of confirmations.
* "time" - (int) The transaction time in seconds since epoch (Jan 1 1970 GMT).
* "blocktime" - (int) The block time in seconds since epoch (Jan 1 1970 GMT).
* ```
*
* @param string $txid The transaction id
* @param int $verbose If 0, return a string, other return a json object
* @return array
*/
public function getRawTransaction($txid, $verbose = 0)
{
$txid = (string)$txid;
$verbose =(int)$verbose;
return $this->client->getrawtransaction($txid,$verbose);
}
/**
* Returns a new bitcoin address for receiving payments.
* If [account] is specified payments received with the address will be credited to [account].
*/
public function getReceivedByAccount($account) {
(string)$account;
return $this->client->getreceivedbyaccount($account);
}
/**
* Returns the balance for a given address
*
* @param string $address The address
* @return double
*/
public function getReceivedByAddress($address)
{
$address = (string)$address;
return $this->client->getreceivedbyaddress($address);
}
/**
* Returns detailed information about in-wallet transaction
*
* This method cannot be used to get information about non-wallet transactions. Use getRawTransaction() for
* non-wallet transactions.
*
* The returned array will contain the following keys:
* ```
* "amount" - (double) The transaction amount.
* "fee" - (double) The transaction fee.
* "confirmations" - (int) The number of confirmations.
* "blockhash" - (string) The block hash.
* "blockindex" - (int) The block index.
* "blocktime" - (int) The time in seconds since epoch (1 Jan 1970 GMT).
* "txid" - (string) The transaction id.
* "time" - (int) The transaction time in seconds since epoch (1 Jan 1970 GMT).
* "timereceived" - (int) The time received in seconds since epoch (1 Jan 1970 GMT).
* "details" - (array) The transaction details. Each array contains the following keys:
* "account" - (string) The account name involved in the transaction, using "" to represent the default account.
* "address" - (string) The address involved in the transaction.
* "category" - (string) The category, either "send" or "receive".
* "amount" - (double) The amount.
* "fee" - (double) The transaction fee.
* ```
*
* @param string $txid The transaction id
* @return array
*/
public function getTransaction($txid)
{
$txid = (string)$txid;
return $this->client->gettransaction($txid);
}
/**
* Returns details about an unspent transaction output
*
* Returns an array with the following keys:
* ```
* "bestblock" - (string) The block hash.
* "confirmations" - (int) The number of confirmations.
* "value" - (double) The transaction value.
* "scriptPubKey" - (array) The script, an array with the following keys:
* "asm" - (string) The code in asm format.
* "hex" - (string) The code in hex format.
* "regSigs" - (int) Number of required signatures.
* "type" - (string) The type, eg "pubkeyhash".
* "addresses" - (array) An array of addresses.
* "version" - (int) The version.
* "coinbase" - (bool) Coinbase transaction or not.
* ```
*
* @param string $txid The transaction id
* @param int $n The vout value
* @param bool $include_mem_pool Whether to included the mem pool
* @return array
*/
public function getTransactionOut($txid, $n, $include_mem_pool = true)
{
$txid = (string)$txid;
$n = (int)$n;
$include_mem_pool = (bool)$include_mem_pool;
return $this->client->gettxout($txid,$n,$include_mem_pool);
}
/**
* Returns statistics about the unspent transaction output set
*
* Note this call may take some time.
*
* Returns an array with the following keys:
* ```
* "height" - (int) The current block height.
* "bestblock" - (string) The best block hash hex.
* "transactions" - (int) The number of transactions.
* "txouts" - (int) The number of output transactions.
* "bytes_serialized" - (int) The serialized size.
* "hash_serialized" - (string) The serialized hash.
* "total_amount" - (double) The total amount.
* ```
*
* @return array
*/
public function getTransactionOutSet()
{
return $this->client->gettxoutsetinfo();
}
/**
* Returns work data, or works on existing data
*
* Returns formatted hash data to work on if $data is not specified. Tries to solve the block if $data is provided,
* and returns a boolean value indicating success or failure.
*
* When $data is not specified, the return value will be an array with the following keys:
* ```
* "midstate" - (string) The precomputed hash state after hashing the first half of the data (DEPRECATED).
* "data" - (string) The serialized block data.
* "hash1" - (string) The formatted hash buffer for second hash (DEPRECATED).
* "target" - (string) The little endian hash target.
* ```
*
* @param string $data The hex-encoded data to solve
* @return array|bool
*/
public function getWork($data = null)
{
// No arguments should be sent when $data is null.
if (null === $data) {
$args = [];
} else {
$args = [
(string)$data
];
}
return $this->client->getWork($args);
}
/**
* Adds a private key to the wallet
*
* Rescanning may take a while looking for existing transactions, and may even freeze up the wallet.
*
* @param string $priv_key The private key
* @param string $label An optional label
* @param bool $rescan Whether to rescan the wallet for transactions
* @return bool
*/
public function addPrivateKey($priv_key, $label, $rescan = true)
{
$priv_key = (string)$priv_key;
$label = (string)$label;
$rescan = (bool)$rescan;
return null === $this->client->importPrivKey($priv_key,$label,$rescan);
}
/**
* Fills the keypool
*
* @return bool
*/
public function fillKeyPool()
{
return null === $this->client->keypoolrefill();
}
/**
* Returns the wallet accounts
*
* Example return value:
* ```php
* [
* "",
* "Paper1",
* "Mining"
* ]
* ```
*
* @return array
*/
public function getAccounts()
{
$accounts = [];
$groups = $this->client->getaccounts("listAccounts", [0]);
foreach($groups as $account => $balance) {
$accounts[] = $account;
}
return $accounts;
}
/**
* Returns the wallet addresses
*
* Example return value:
* ```php
* [
* "1Headz2mYtpBRo6KFaaUEtcm5Kce6BZRJM",
* "1JBKAM8W9jEnuGNvPRFjtpmeDGvfQx6PLU",
* "19tjsa4nBeAtn48kcmW9Gg2wRFtm24GRG2"
* ]
* ```
*
* @return array
*/
public function getAddresses()
{
$addresses = [];
$groups = $this->client->getaddresses("listAddressGroupings");
foreach($groups as $group) {
foreach($group as $info) {
$addresses[] = $info[0];
}
}
return $addresses;
}
/**
* Returns balances by for every address
*
* Returns an mutlidimentional array, which each sub-array containing the following keys:
* ```
* "address" - (string) The receiving address.
* "account" - (string) The account of the receiving address, using "" to represent the default account.
* "amount" - (double) The total amount received by the address.
* "confirmations" - (int) The number of confirmations of the most recent transaction included.
* "txids" - (array) An array of transaction ids.
* ```
*
* To get a list of accounts on the system, call getReceivedByAddress(0, true).
*
* @param bool $include_empty Whether to include addresses that haven't received any payments
* @return array
*/
public function getBalances($include_empty = false)
{
$include_empty = (bool)$include_empty;
return $this->client->listreceivedbyaddress($include_empty);
}
/**
* Returns an array of objects containing:
* "account" : the account of the receiving addresses
* "amount" : total amount received by addresses with this account
* "confirmations" : number of confirmations of the most recent transaction included
*/
public function listreceivedbyaccount($include_empty = false){
return $this->client->listreceivedbyaccount($include_empty);
}
/**
* Get all transactions in blocks since block $hash
*
* Returns all transactions if $hash is omitted.
*
* The return value will be an mutlidimentional array with the following keys:
* ```
* "lastblock" - (string) The hash of the last block.
* "transactions" - (array) One or more transactions. Each transaction will contain the following keys:
* "account" - (string) The account name associated with the transaction, using "" to represent the default account.
* "address" - (string) The address of the transaction. Not present for move transactions (category = move).
* "category" - (string) The type of transaction, eg "send", "receive", or "move".
* "amount" - (double) The transaction amount. This is negative for the "send" category, and for the 'move' category for moves outbound, otherwise it's positive.
* "fee" - (double) The transaction fee. This is negative and only available for the 'send' category of transactions.
* "confirmations" - (int) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.
* "blockhash" - (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.
* "blockindex" - (int) The block index containing the transaction. Available for 'send' and 'receive' category of transactions.
* "blocktime" - (int) The block time in seconds since epoch (1 Jan 1970 GMT).
* "txid" - (string) The transaction id.
* "time" - (int) The transaction time in seconds since epoch (Jan 1 1970 GMT).
* "timereceived" - (int) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.
* "comment" - (string) If a comment is associated with the transaction.
* "to" - (string) If a comment to is associated with the transaction.
* ```
*
* @param string $hash The block hash to list transactions since
* @param int $target_confirmations The confirmations required, must be 1 or more
* @return array
*/
public function getSinceBlock($hash = null, $target_confirmations = 1)
{
$hash = (string)$hash;
$target_confirmations = (int)$target_confirmations;
return $this->client->listsinceblock($hash, $target_confirmations);
}
/**
* Returns up to $count most recent transactions
*
* The first $from transactions are skipped. If $account not provided will return recent transaction from all
* accounts.
*
* The return value will be an mutlidimentional array, with each sub-array containing the following keys:
* ```
* "account" - (string) The account name associated with the transaction, using "" to represent the default account.
* "address" - (string) The address of the transaction. Not present for move transactions (category = move).
* "category" - (string) The type of transaction, eg "send", "receive", or "move".
* "amount" - (double) The transaction amount. This is negative for the "send" category, and for the 'move' category for moves outbound, otherwise it's positive.
* "fee" - (double) The transaction fee. This is negative and only available for the 'send' category of transactions.
* "confirmations" - (int) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.
* "blockhash" - (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.
* "blockindex" - (int) The block index containing the transaction. Available for 'send' and 'receive' category of transactions.
* "blocktime" - (int) The block time in seconds since epoch (1 Jan 1970 GMT).
* "txid" - (string) The transaction id.
* "time" - (int) The transaction time in seconds since epoch (Jan 1 1970 GMT).
* "timereceived" - (int) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.
* "comment" - (string) If a comment is associated with the transaction.
* ```
*
* @param string $account The name of the account
* @param int $count Number of transactions to return
* @param int $from Offset from the last transaction
* @return array
*/
public function getTransactions($account, $count = 100, $from = 0)
{
$account = (string)$account;
$count = (int)$count;
$from = (int)$from;
return $this->client->listtransactions($account,$count,$from);
}
/**
* Returns array of unspent transaction inputs in the wallet between $minconf and $maxconf
*
* The returned array will contain the following keys:
* ```
* "txid" - (string) The transaction id.
* "vout" - (int) The vout value.
* "address" - (string) The address.
* "account" - (string) The associated account, using "" to represent the default account.
* "scriptPubKey" - (string) The script key.
* "amount" - (double) The transaction amount.
* "confirmations" - (int) The number of confirmations.
* ```
*
* @param int $minconf The minimum confirmations to filter
* @param int $maxconf The maximum confirmations to filter
* @return array