-
Notifications
You must be signed in to change notification settings - Fork 29
/
MultichainClient.php
893 lines (828 loc) · 37.1 KB
/
MultichainClient.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
<?php
namespace be\kunstmaan\multichain;
use JsonRPC\Client as JsonRPCClient;
/**
* Class MultichainClient
*
* @package be\kunstmaan\multichain
* @link http://www.multichain.com/developers/json-rpc-api/
*/
class MultichainClient
{
/**
* The JsonRPC client used to call the multichain api
*
* @var \JsonRPC\Client
*/
private $jsonRPCClient;
/**
* Default HTTP headers to send to the server
*
* @var array
*/
private $headers = array(
'User-Agent: Unofficial Multichain PHP Client <https://github.com/kunstmaan/libphp-multichain>',
);
/**
* Enable debug output to the php error log
*
* @var boolean
*/
private $debug = false;
/**
* Constructor
*
* @param string $url Multichain JSON RPC url + port
* @param string $username Multichain JSON RPC username
* @param string $password Multichain JSON RPC password
* @param integer $timeout HTTP timeout
*/
public function __construct($url, $username, $password, $timeout = 3)
{
$this->jsonRPCClient = new JsonRPCClient($url);
$httpClient = $this->jsonRPCClient->getHttpClient();
$httpClient->withHeaders($this->headers);
$this->jsonRPCClient->authentication($username, $password);
}
/**
* @param boolean $debug
* @return MultichainClient
*/
public function setDebug($debug)
{
$this->debug = $debug;
if($debug){
$httpClient = $this->jsonRPCClient->getHttpClient();
$httpClient->withDebug();
}
return $this;
}
/**
* Returns general information about this node and blockchain. MultiChain adds some fields to Bitcoin Core’s
* response, giving the blockchain’s chainname, description, protocol, peer-to-peer port. The setupblocks field
* gives the length in blocks of the setup phase in which some consensus constraints are not applied. The
* nodeaddress can be passed to other nodes for connecting.
*
* @return mixed
*/
public function getInfo()
{
return $this->jsonRPCClient->execute("getinfo");
}
/**
* Returns information about the other nodes to which this node is connected. If this is a MultiChain blockchain,
* includes handshake and handshakelocal fields showing the remote and local address used during the handshaking
* for that connection.
*
* @return mixed
*/
public function getPeerInfo()
{
return $this->jsonRPCClient->execute("getpeerinfo");
}
/**
* Returns a new address for receiving payments. Omit the account parameter for the default account – see note below
*
* NOTE:
* Bitcoin Core has a notion of “accounts”, whereby each address can belong to specific account, which is credited
* when bitcoin is sent to that address. However the separation of accounts is not preserved when bitcoin is sent
* out, because the internal accounting mechanism has no relationship to the bitcoin protocol itself. Because of
* all the confusion this has caused, Bitcoin Core’s accounts mechanism is to be deprecated in future.
*
* MultiChain preserves the accounts mechanism and parameters for full backwards compatibility with the Bitcoin
* Core API. However, because of its forthcoming deprecation, the mechanism is not applied to native asset
* balances, all of which are considered as belonging to a single global account. Therefore we recommend not using
* accounts at all with MultiChain, and using "" for any account parameter in the API.
*
* To support multiple users in a single MultiChain node’s wallet, call getnewaddress to get a different address
* for each user. You should then use MultiChain’s *from* APIs, such as sendassetfrom and sendfromaddress, to
* control whose funds are spent in each transaction. Unlike bitcoin-style accounts, this method maps directly to
* the blockchain protocol.
*
* @param string $account
* @return mixed
*/
public function getNewAddress()
{
return $this->jsonRPCClient->execute("getnewaddress", array());
}
/**
* Returns the private key associated with address in this node’s wallet. Use with caution – any node with access to this
* private key can perform any action restricted to the address, including granting permissions and spending funds.
*
* @param $address
* @return mixed
*/
public function dumpPrivateKey($address){
return $this->jsonRPCClient->execute("dumpprivkey", array($address));
}
/**
* Adds the privkey private key (as obtained from a prior call to dumpprivkey) to the wallet, together with its
* associated public address. If rescan is true, the entire blockchain is checked for transactions relating to
* all addresses in the wallet, including the added one.
*
* @param $privkey
* @param string $label
* @param bool $rescan
* @return mixed
*/
public function importPrivateKey($privkey, $label="", $rescan=true){
return $this->jsonRPCClient->execute("importprivkey", array($privkey, $label, $rescan));
}
/**
* Creates a pay-to-scripthash (P2SH) multisig address and adds it to the wallet. Funds sent to this address
* can only be spent by transactions signed by nrequired of the specified keys. Each key can be a full public key,
* or an address if the corresponding key is in the node’s wallet. (Public keys for a wallet’s addresses can be
* obtained using the getaddresses call with verbose=true.) Returns the P2SH address.
*
* @param int $nRequired
* @param array $addresses
* @return mixed
*/
public function addMultisigAddress($nRequired, $addresses) {
return $this->jsonRPCClient->execute("addmultisigaddress", array($nRequired, $addresses));
}
/**
* Adds address (or a full public key, or an array of either) to the wallet, without an associated private key.
* This creates one or more watch-only addresses, whose activity and balance can be retrieved via various APIs
* (e.g. with the includeWatchOnly parameter), but whose funds cannot be spent by this node. If rescan is true,
* the entire blockchain is checked for transactions relating to all addresses in the wallet, including the added ones.
* Returns null if successful.
*
* @param $address
* @param string $label
* @param bool $rescan
* @return mixed
*/
public function importAddress($address, $label="", $rescan=true) {
return $this->jsonRPCClient->execute("importaddress", array($address, $label, $rescan));
}
/**
* Returns information about the addresses in the wallet. Provide one or more addresses (comma-delimited or as an array)
* to retrieve information about specific addresses only, or use * for all addresses in the wallet. Use count and start
* to retrieve part of the list only, with negative start values (like the default) indicating the most recently created addresses.
*
* @param $addresses
* @param bool $verbose
* @param string $count
* @param string $start
* @return mixed
*/
public function listAddresses($addresses="*", $verbose=false, $count="MAX", $start="-count") {
return $this->jsonRPCClient->execute("listaddresses", array($addresses, $verbose, $count, $start));
}
/**
* Generates one or more public/private key pairs, which are not stored in the wallet or drawn from the node’s key pool,
* ready for external key management. For each key pair, the address, pubkey (as embedded in transaction inputs) and privkey
* (used for signatures) is provided.
*
* @param int $count
* @return mixed
*/
public function createKeypairs($count=1) {
return $this->jsonRPCClient->execute("createkeypairs", array($count));
}
/**
* Creates a pay-to-scripthash (P2SH) multisig address. Funds sent to this address can only be spent by transactions signed by
* nrequired of the specified keys. Each key can be a full hexadecimal public key, or an address if the corresponding key is
* in the node’s wallet. Returns an object containing the P2SH address and corresponding redeem script.
*
* @param int $nRequired
* @param array $addresses
* @return mixed
*/
public function createMultisig($nRequired, $addresses) {
return $this->jsonRPCClient->execute("createmultisig", array($nRequired, $addresses));
}
/**
* Sends one or more assets to address, returning the txid. In Bitcoin Core, the amount field is the quantity of
* the bitcoin currency. For MultiChain, an {"asset":qty, ...} object can be used for amount, in which each asset
* is an asset name, ref or issuance txid, and each qty is the quantity of that asset to send (see native assets).
* Use "" as the asset inside this object to specify a quantity of the native blockchain currency. See also
* sendassettoaddress for sending a single asset and sendfromaddress to control the address whose funds are used.
*
* @param string $address
* @param string $amount
* @param string $comment
* @param string $commentTo
* @return mixed
*/
public function sendToAddress($address, $amount, $comment = '', $commentTo = '')
{
return $this->jsonRPCClient->execute("sendtoaddress", array($address, $amount, $comment, $commentTo));
}
/**
* Outputs a list of available API commands, including MultiChain-specific commands.
*
* @return mixed
*/
public function help()
{
return $this->jsonRPCClient->execute("help");
}
/**
* Adds to the atomic exchange transaction in hexstring given by a previous call to createrawexchange or
* appendrawexchange. This adds an offer to exchange the asset/s in output vout of transaction txid for qty units
* of asset, where asset is an asset name, ref or issuance txid. The txid and vout should generally be taken from
* the response to preparelockunspent or preparelockunspentfrom. Multiple items can be specified within the fourth
* parameter to request multiple assets. Returns a raw hexadecimal transaction in the hex field alongside a
* complete field stating whether the exchange is complete (i.e. balanced) or not. If complete, the transaction can
* be transmitted to the network using sendrawtransaction. If not, it can be passed to a further counterparty, who
* can call decoderawexchange and appendrawexchange as appropriate.
*
* @param $hexString
* @param $txId
* @param $vOut
* @param $extra ({"asset":qty, ...})
* @return mixed
*/
public function appendRawExchange($hexString, $txId, $vOut, $extra)
{
return $this->jsonRPCClient->execute("appendrawexchange", array($hexString, $txId, $vOut, $extra));
}
/**
* Adds a metadata output to the raw transaction in tx-hex given by a previous call to createrawtransaction. The
* metadata is specified in data-hex in hexadecimal form and added in a new OP_RETURN transaction output. The
* transaction can then be signed and transmitted to the network using signrawtransaction and sendrawtransaction.
*
* @param $txHex
* @param $dataHex
* @return mixed
*/
public function appendRawMetadata($txHex, $dataHex)
{
return $this->jsonRPCClient->execute("appendrawmetadata", array($txHex, $dataHex));
}
/**
* Sends transactions to combine large groups of unspent outputs (UTXOs) belonging to the same address into a
* single unspent output, returning a list of txids. This can improve wallet performance, especially for miners in
* a chain with short block times and non-zero block rewards. Set addresses to a comma-separated list of addresses
* to combine outputs for, or * for all addresses in the wallet. Only combine outputs with at least minconf
* confirmations, and use between mininputs and maxinputs per transaction. A single call to combineunspent can
* create up to maxcombines transactions over up to maxtime seconds. See also the autocombine runtime parameters.
*
* @param string $addresses
* @param int $minConf
* @param int $maxCombines
* @param int $minInputs
* @param int $maxInputs
* @param int $maxTime
* @return mixed
*/
public function combineUnspent($addresses = "*", $minConf = 1, $maxCombines = 1, $minInputs = 10, $maxInputs = 100, $maxTime = 30)
{
return $this->jsonRPCClient->execute("combineunspent", array($addresses, $minConf, $maxCombines, $minInputs, $maxInputs, $maxTime));
}
/**
* Creates a new atomic exchange transaction which offers to exchange the asset/s in output vout of transaction
* txid for qty units of asset, where asset is an asset name, ref or issuance txid. The txid and vout should
* generally be taken from the response to preparelockunspent or preparelockunspentfrom. Multiple items can be
* specified within the third parameter to request multiple assets. Returns a raw partial transaction in
* hexadecimal which can be passed to the counterparty, who can call decoderawexchange and appendrawexchange as
* appropriate.
*
* @param $txId
* @param $vOut
* @param $extra
* @return mixed
*/
public function createRawExchange($txId, $vOut, $extra)
{
return $this->jsonRPCClient->execute("createrawexchange", array($txId, $vOut, $extra));
}
/**
* Decodes the raw exchange transaction in hexstring, given by a previous call to createrawexchange or
* appendrawexchange. Returns details on the offer represented by the exchange and its present state. The offer
* field in the response lists the quantity of native currency and/or assets which are being offered for exchange.
* The ask field lists the native currency and/or assets which are being asked for. The candisable field specifies
* whether this wallet can disable the exchange transaction by double-spending against one of its inputs. The
* cancomplete field specifies whether this wallet has the assets required to complete the exchange. The complete
* field specifies whether the exchange is already complete (i.e. balanced) and ready for sending. If verbose is
* true then all of the individual stages in the exchange are listed. Other fields relating to fees are only
* relevant for blockchains which use a native currency.
*
* @param $hexString
* @param bool $verbose
* @return mixed
*/
public function decodeRawExchange($hexString, $verbose = false)
{
return $this->jsonRPCClient->execute("decoderawexchange", array($hexString, $verbose));
}
/**
* Sends a transaction to disable the offer of exchange in hexstring, returning the txid. This is achieved by
* spending one of the exchange transaction’s inputs and sending it back to the wallet. To check whether this can
* be used on an exchange transaction, check the candisable field of the output of decoderawexchange.
*
* @param $hexString
* @return mixed
*/
public function disableRawTransaction($hexString)
{
return $this->jsonRPCClient->execute("disablerawtransaction", array($hexString));
}
/**
* Returns a list of all the asset balances for address in this node’s wallet, with at least minconf confirmations.
* Use includeLocked to include unspent outputs which have been locked, e.g. by a call to preparelockunspent.
*
* @param $address
* @param int $minConf
* @param bool $includeLocked
* @return mixed
*/
public function getAddressBalances($address, $minConf = 1, $includeLocked = false)
{
return $this->jsonRPCClient->execute("getaddressbalances", array($address, $minConf, $includeLocked));
}
/**
* Returns a list of addresses in this node’s wallet. Set verbose to true to get more information about each
* address, formatted like the output of the validateaddress command.
*
* @param bool $verbose
* @return mixed
*/
public function getAddresses($verbose = false)
{
return $this->jsonRPCClient->execute("getaddresses", array($verbose));
}
/**
* Provides information about transaction txid related to address in this node’s wallet, including how it affected
* that address’s balance. Use verbose to provide details of transaction inputs and outputs.
*
* @param $address
* @param $txId
* @param bool $verbose
* @return mixed
*/
public function getAddressTransaction($address, $txId, $verbose = false)
{
return $this->jsonRPCClient->execute("getaddresstransaction", array($address, $txId, $verbose));
}
/**
* Returns a list of all the asset balances for account in this node’s wallet, with at least minconf confirmations.
* Omit the account parameter or use "" for the default account – see note about accounts. Use includeWatchOnly to
* include the balance of watch-only addresses and includeLocked to include unspent outputs which have been locked,
* e.g. by a call to preparelockunspent.
*
* @param string $account
* @param int $minConf
* @param bool $includeWatchOnly
* @param bool $includeLocked
* @return mixed
*/
public function getAssetBalances($account = "", $minConf = 1, $includeWatchOnly = false, $includeLocked = false)
{
return $this->jsonRPCClient->execute("getassetbalances", array($account, $minConf, $includeWatchOnly, $includeLocked));
}
/**
* Returns a list of all the asset balances in this node’s wallet, with at least minconf confirmations. Use
* includeWatchOnly to include the balance of watch-only addresses and includeLocked to include unspent outputs
* which have been locked, e.g. by a call to preparelockunspent.
*
* @param int $minConf
* @param bool $includeWatchOnly
* @param bool $includeLocked
* @return mixed
*/
public function getTotalBalances($minConf = 1, $includeWatchOnly = false, $includeLocked = false)
{
return $this->jsonRPCClient->execute("getassetbalances", array($minConf, $includeWatchOnly, $includeLocked));
}
/**
* Returns information about address including a check for its validity.
*
* @param $address
* @return mixed
*/
public function validateAddress($address)
{
return $this->jsonRPCClient->execute("validateaddress", array($address));
}
/**
* Provides information about transaction txid in this node’s wallet, including how it affected the node’s total
* balance. Use includeWatchOnly to consider watch-only addresses as if they belong to this wallet and verbose to
* provide details of transaction inputs and outputs.
*
* @param $txId
* @param bool $includeWatchOnly
* @param bool $verbose
* @return mixed
*/
public function getWalletTransaction($txId, $includeWatchOnly = false, $verbose = false)
{
return $this->jsonRPCClient->execute("getwallettransaction", array($txId, $includeWatchOnly, $verbose));
}
/**
* Grants permissions to addresses, where addresses is a comma-separated list of addresses and permissions is one
* of connect, send, receive, issue, mine, admin, or a comma-separated list thereof. If the chain uses a native
* currency, you can send some to each recipient using the native-amount parameter. Returns the txid of the
* transaction granting the permissions. For more information, see permissions management.
*
* @param $addresses
* @param $permissions
* @param int $nativeAmount
* @param string $comment
* @param string $commentTo
* @param int $startBlock
* @param null $endBlock
* @return mixed
*/
public function grant($addresses, $permissions, $nativeAmount = 0, $comment = '', $commentTo = '', $startBlock = 0, $endBlock = null)
{
return $this->jsonRPCClient->execute("grant", array($addresses, $permissions, $nativeAmount, $comment, $commentTo, $startBlock, $endBlock));
}
/**
* This works like grant, but with control over the from-address used to grant the permissions. If there are
* multiple addresses with administrator permissions on one node, this allows control over which address is used.
*
* @param $fromAddress
* @param $toAddresses
* @param $permissions
* @param int $nativeAmount
* @param string $comment
* @param string $commentTo
* @param int $startBlock
* @param null $endBlock
* @return mixed
*/
public function grantFrom($fromAddress, $toAddresses, $permissions, $nativeAmount = 0, $comment = '', $commentTo = '', $startBlock = 0, $endBlock = null)
{
return $this->jsonRPCClient->execute("grantfrom", array($fromAddress, $toAddresses, $permissions, $nativeAmount, $comment, $commentTo, $startBlock, $endBlock));
}
/**
* Creates a new asset name on the blockchain, sending the initial qty units to address. The smallest transactable
* unit is given by units, e.g. 0.01. If the chain uses a native currency, you can send some with the new asset
* using the native-amount parameter.
*
* @param $address
* @param $name
* @param $qty
* @param int $units
* @param int $nativeAmount
* @param null $custom
* @param bool $open
* @return mixed
*/
public function issue($address, $name, $qty, $units = 1, $nativeAmount = 0, $custom = null, $open=false)
{
$params = array($address, array('name' => $name, 'open' => $open), $qty, $units, $nativeAmount);
if (!is_null($custom)) {
$params[] = $custom;
}
return $this->jsonRPCClient->execute("issue", $params);
}
/**
* Issues qty additional units of asset, sending them to address. The asset can be specified using its name, ref or
* issuance txid – see native assets for more information. If the chain uses a native currency, you can send some with the
* new asset units using the native-amount parameter. Any custom fields will be attached to the new issuance event, and not
* affect the original values (use listassets with verbose=true to see both sets). Returns the txid of the issuance
* transaction. For more information, see native assets.
*
* @param $address
* @param $asset
* @param $qty
* @param int $nativeAmount
* @param null $custom
* @return mixed
*/
public function issueMore($address, $asset, $qty, $nativeAmount=0, $custom = null){
$params = array($address, $asset, $qty, $nativeAmount);
if (!is_null($custom)) {
$params[] = $custom;
}
return $this->jsonRPCClient->execute("issuemore", $params);
}
/**
* This works like issue, but with control over the from-address used to issue the asset. If there are multiple
* addresses with asset issuing permissions on one node, this allows control over which address is used.
*
* @param $fromAddress
* @param $toAddress
* @param $name
* @param $qty
* @param int $units
* @param int $nativeAmount
* @param null $custom
* @return mixed
*/
public function issueFrom($fromAddress, $toAddress, $name, $qty, $units = 1, $nativeAmount = 0, $custom = null)
{
return $this->jsonRPCClient->execute("issuefrom", array($fromAddress, $toAddress, $name, $qty, $units, $nativeAmount, $custom));
}
/**
* Lists information about the count most recent transactions related to address in this node’s wallet, including
* how they affected that address’s balance. Use skip to go back further in history and verbose to provide details
* of transaction inputs and outputs.
*
* @param $address
* @param int $count
* @param int $skip
* @param bool $verbose
* @return mixed
*/
public function listAddressTransactions($address, $count = 10, $skip = 0, $verbose = false)
{
return $this->jsonRPCClient->execute("listaddresstransactions", array($address, $count, $skip, $verbose));
}
/**
* Returns information about all assets issued on the blockchain. If an issuance txid
* (see native assets) is provided in asset, then information is only returned about that one asset.
*
* @param null $asset
* @return mixed
*/
public function listAssets($asset = null)
{
return $this->jsonRPCClient->execute("listassets", array($asset));
}
/**
* Returns a list of all permissions currently granted to addresses. To list information about specific permissions
* only, set permissions to one of connect, send, receive, issue, mine, admin, or a comma-separated list thereof.
* Omit or pass all to list all permissions. Provide a comma-delimited list in addresses to list the permissions
* for particular addresses only or * for all addresses. If verbose is true, the admins output field lists the
* administrator/s who assigned the corresponding permission, and the pending field lists permission changes which
* are waiting to reach consensus.
*
* @param string $permissions
* @param string $addresses
* @param bool $verbose
* @return mixed
*/
public function listPermissions($permissions = "all", $addresses = "*", $verbose = false)
{
return $this->jsonRPCClient->execute("listpermissions", array($permissions, $addresses, $verbose));
}
/**
* Lists information about the count most recent transactions in this node’s wallet, including how they affected
* the node’s total balance. Use skip to go back further in history and includeWatchOnly to consider watch-only
* addresses as if they belong to this wallet. Use verbose to provide the details of transaction inputs and outputs.
* Note that unlike Bitcoin Core’s listtransactions command, the response contains one element per transaction,
* rather than one per transaction output.
*
* @param int $count
* @param int $skip
* @param bool $includeWatchOnly
* @param bool $verbose
* @return mixed
*/
public function listWalletTransactions($count = 10, $skip = 0, $includeWatchOnly = false, $verbose = false)
{
return $this->jsonRPCClient->execute("listwallettransactions", array($count, $skip, $includeWatchOnly, $verbose));
}
/**
* Prepares an unspent transaction output (useful for building atomic exchange transactions) containing qty units
* of asset, where asset is an asset name, ref or issuance txid. Multiple items can be specified within the first
* parameter to include several assets within the output. The output will be locked against automatic selection for
* spending unless the optional lock parameter is set to false. Returns the txid and vout of the prepared output.
*
* @param $assetsToLock
* @param bool $lock
* @return mixed
*/
public function prepareLockUnspent($assetsToLock, $lock = true)
{
return $this->jsonRPCClient->execute("preparelockunspent", array($assetsToLock, $lock));
}
/**
* This works like preparelockunspent, but with control over the from-address whose funds are used to prepare the
* unspent transaction output. Any change from the transaction is send back to from-address.
*
* @param $fromAddress
* @param $assetsToLock
* @param bool $lock
* @return mixed
*/
public function prepareLockUnspentFrom($fromAddress, $assetsToLock, $lock = true)
{
return $this->jsonRPCClient->execute("preparelockunspentfrom", array($fromAddress, $assetsToLock, $lock));
}
/**
* Revokes permissions from addresses, where addresses is a comma-separated list of addresses and permissions is
* one of connect, send, receive, issue, mine, admin, or a comma-separated list thereof. Equivalent to calling
* grant with start-block=0 and end-block=0. Returns the txid of transaction revoking the permissions. For more
* information, see permissions management.
*
* @param $addresses
* @param $permissions
* @param int $nativeAmount
* @param string $comment
* @param string $commentTo
* @return mixed
*/
public function revoke($addresses, $permissions, $nativeAmount = 0, $comment = '', $commentTo = '')
{
return $this->jsonRPCClient->execute("revoke", array($addresses, $permissions, $nativeAmount, $comment, $commentTo));
}
/**
* This works like revoke, but with control over the from-address used to revoke the permissions. If there are
* multiple addresses with administrator permissions on one node, this allows control over which address is used.
*
* @param $fromAddress
* @param $toAddresses
* @param $permissions
* @param int $nativeAmount
* @param string $comment
* @param string $commentTo
* @return mixed
*/
public function revokeFrom($fromAddress, $toAddresses, $permissions, $nativeAmount = 0, $comment = '', $commentTo = '')
{
return $this->jsonRPCClient->execute("revokefrom", array($fromAddress, $toAddresses, $permissions, $nativeAmount, $comment, $commentTo));
}
/**
* This works like sendassettoaddress, but with control over the from-address whose funds are used. Any change from
* the transaction is sent back to from-address. See also sendfromaddress for sending multiple assets in one
* transaction.
*
* @param $fromAddress
* @param $toAddress
* @param $asset
* @param $qty
* @param null $nativeAmount
* @param string $comment
* @param string $commentTo
* @return mixed
*/
public function sendAssetFrom($fromAddress, $toAddress, $asset, $qty, $nativeAmount = null, $comment = '', $commentTo = '')
{
$nativeAmount = $this->findDefaultMinimumPerOutput($nativeAmount);
return $this->jsonRPCClient->execute("sendassetfrom", array($fromAddress, $toAddress, $asset, $qty, $nativeAmount, $comment, $commentTo));
}
/**
* Returns a list of all the parameters of this blockchain, reflecting the content of its params.dat file.
*
* @return mixed
*/
public function getBlockchainParams()
{
return $this->jsonRPCClient->execute("getblockchainparams");
}
/**
* Sends qty of asset to address, returning the txid. The asset can be specified using its name, ref or issuance
* txid – see native assets for more information. See also sendassetfrom to control the address whose funds are
* used, sendtoaddress for sending multiple assets in one transaction, and sendfromaddress to combine both of these.
*
* @param $address
* @param $asset
* @param $qty
* @param null $nativeAmount
* @param string $comment
* @param string $commentTo
* @return mixed
*/
public function sendAssetToAddress($address, $asset, $qty, $nativeAmount = null, $comment = '', $commentTo = '')
{
$nativeAmount = $this->findDefaultMinimumPerOutput($nativeAmount);
return $this->jsonRPCClient->execute("sendassettoaddress", array($address, $asset, $qty, $nativeAmount, $comment, $commentTo));
}
/**
* This works like sendtoaddress, but with control over the from-address whose funds are used. Any
* change from the transaction is sent back to from-address.
*
* @param $fromAddress
* @param $toAddress
* @param $amount
* @param string $comment
* @param string $commentTo
* @return mixed
*/
public function sendFromAddress($fromAddress, $toAddress, $amount, $comment = '', $commentTo = '')
{
return $this->jsonRPCClient->execute("sendfromaddress", array($fromAddress, $toAddress, $amount, $comment, $commentTo));
}
/**
* This works like sendtoaddress (listed above), but includes the data-hex hexadecimal metadata in an additional
* OP_RETURN transaction output.
*
* @param $address
* @param $amount
* @param $dataHex
* @return mixed
*/
public function sendWithMetadata($address, $amount, $dataHex)
{
return $this->jsonRPCClient->execute("sendwithmetadata", array($address, $amount, $dataHex));
}
/**
* This works like sendtoaddress (listed above), but with control over the from-address whose funds are used, and
* with the data-hex hexadecimal metadata added in an additional OP_RETURN transaction output. Any change from the
* transaction is sent back to from-address.
*
* @param $fromAddress
* @param $toAddress
* @param $amount
* @param $dataHex
* @return mixed
*/
public function sendWithMetadataFrom($fromAddress, $toAddress, $amount, $dataHex)
{
return $this->jsonRPCClient->execute("sendwithmetadatafrom", array($fromAddress, $toAddress, $amount, $dataHex));
}
/**
* Creates a transaction spending the specified inputs, sending to the given addresses. In Bitcoin Core, each
* amount field is a quantity of the bitcoin currency. For MultiChain, an {"asset":qty, ...} object can be used for
* amount, in which each asset is an asset name, ref or issuance txid, and each qty is the quantity of that asset
* to send (see native assets). Use "" as the asset inside this object to specify a quantity of the native
* blockchain currency.
*
* @param $inputs
* @param $addresses
* @return mixed
*/
public function createRawTransaction($inputs, $addresses)
{
return $this->jsonRPCClient->execute("createrawtransaction", array($inputs, $addresses));
}
/**
* Returns a JSON object describing the serialized transaction in hexstring. For a MultiChain blockchain, each
* transaction output includes assets and permissions fields listing any assets or permission changes encoded
* within that output. There will also be a data field listing the content of any OP_RETURN outputs in the
* transaction.
*
* @param $hexString
* @return mixed
*/
public function decodeRawTransaction($hexString)
{
return $this->jsonRPCClient->execute("decoderawtransaction", array($hexString));
}
/**
* Returns information about the block with hash. If this is a MultiChain blockchain and format is true or omitted,
* then the output includes a field miner showing the address of the miner of the block.
*
* @param $hash
* @param bool $format
* @return mixed
*/
public function getBlock($hash, $format = true)
{
return $this->jsonRPCClient->execute("getblock", array($hash, $format));
}
/**
* If verbose is 1, returns a JSON object describing transaction txid. For a MultiChain blockchain, each transaction
* output includes assets and permissions fields listing any assets or permission changes encoded within that
* output. There will also be a data field listing the content of any OP_RETURN outputs in the transaction.
*
* @param $txId
* @param int $verbose
* @return mixed
*/
public function getRawTransaction($txId, $verbose = 0)
{
return $this->jsonRPCClient->execute("getrawtransaction", array($txId, $verbose));
}
/**
* Returns details about an unspent transaction output vout of txid. For a MultiChain blockchain, includes assets
* and permissions fields listing any assets or permission changes encoded within the output. Set confirmed to true
* to include unconfirmed transaction outputs.
*
* @param $txId
* @param $vOut
* @param bool $unconfirmed
* @return mixed
*/
public function getTxOut($txId, $vOut, $unconfirmed = false)
{
return $this->jsonRPCClient->execute("gettxout", array($txId, $vOut, $unconfirmed));
}
/**
* Returns a list of unspent transaction outputs in the wallet, with between minconf and maxconf confirmations. For
* a MultiChain blockchain, each transaction output includes assets and permissions fields listing any assets or
* permission changes encoded within that output. If addresses is provided, only outputs which pay an address in
* this array will be included.
*
* @param int $minConf
* @param int $maxConf
* @param null $addresses
* @return mixed
*/
public function listUnspent($minConf = 1, $maxConf = 999999, $addresses = null)
{
return $this->jsonRPCClient->execute("listunspent", array($minConf, $maxConf, $addresses));
}
/**
* @param $nativeAmount
* @return mixed
*/
private function findDefaultMinimumPerOutput($nativeAmount)
{
if (is_null($nativeAmount)) {
$blockchainParams = $this->getBlockchainParams();
$nativeAmount = $blockchainParams["minimum-per-output"];
return $nativeAmount;
}
return $nativeAmount;
}
/**
* Submits raw transaction (serialized, hex-encoded) to local node and network.
* Returns the transaction hash in hex
*
* @param $hex
* @param bool $allowHighFees
* @return mixed
*/
public function sendRawTransaction($hex, $allowHighFees = false)
{
return $this->jsonRPCClient->execute("sendrawtransaction", array($hex, $allowHighFees));
}
}