GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MultichainClient   C
last analyzed

Complexity

Total Complexity 53

Size/Duplication

Total Lines 806
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 11
Bugs 0 Features 6
Metric Value
wmc 53
c 11
b 0
f 6
lcom 1
cbo 2
dl 0
loc 806
rs 5.7142

49 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A setDebug() 0 9 2
A getInfo() 0 4 1
A getPeerInfo() 0 4 1
A getNewAddress() 0 4 1
A dumpPrivateKey() 0 3 1
A importPrivateKey() 0 3 1
A sendToAddress() 0 4 1
A help() 0 4 1
A appendRawExchange() 0 4 1
A appendRawMetadata() 0 4 1
A combineUnspent() 0 4 1
A createRawExchange() 0 4 1
A decodeRawExchange() 0 4 1
A disableRawTransaction() 0 4 1
A getAddressBalances() 0 4 1
A getAddresses() 0 4 1
A getAddressTransaction() 0 4 1
A getAssetBalances() 0 4 1
A getTotalBalances() 0 4 1
A validateAddress() 0 4 1
A getWalletTransaction() 0 4 1
A grant() 0 4 1
A grantFrom() 0 4 1
A issue() 0 8 2
A issueMore() 0 7 2
A issueFrom() 0 4 1
A listAddressTransactions() 0 4 1
A listAssets() 0 4 1
A listPermissions() 0 4 1
A listWalletTransactions() 0 4 1
A prepareLockUnspent() 0 4 1
A prepareLockUnspentFrom() 0 4 1
A revoke() 0 4 1
A revokeFrom() 0 4 1
A sendAssetFrom() 0 5 1
A getBlockchainParams() 0 4 1
A sendAssetToAddress() 0 5 1
A sendFromAddress() 0 4 1
A sendWithMetadata() 0 4 1
A sendWithMetadataFrom() 0 4 1
A createRawTransaction() 0 4 1
A decodeRawTransaction() 0 4 1
A getBlock() 0 4 1
A getRawTransaction() 0 4 1
A getTxOut() 0 4 1
A listUnspent() 0 4 1
A findDefaultMinimumPerOutput() 0 9 2
A sendRawTransaction() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like MultichainClient often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use MultichainClient, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace be\kunstmaan\multichain;
4
5
use JsonRPC\Client as JsonRPCClient;
6
7
/**
8
 * Class MultichainClient
9
 *
10
 * @package be\kunstmaan\multichain
11
 * @link http://www.multichain.com/developers/json-rpc-api/
12
 */
13
class MultichainClient
14
{
15
16
    /**
17
     * The JsonRPC client used to call the multichain api
18
     *
19
     * @var \JsonRPC\Client
20
     */
21
    private $jsonRPCClient;
22
23
    /**
24
     * Default HTTP headers to send to the server
25
     *
26
     * @var array
27
     */
28
    private $headers = array(
29
        'User-Agent: Unofficial Multichain PHP Client <https://github.com/kunstmaan/libphp-multichain>',
30
    );
31
32
    /**
33
     * Enable debug output to the php error log
34
     *
35
     * @var boolean
36
     */
37
    private $debug = false;
38
39
    /**
40
     * Constructor
41
     *
42
     * @param  string $url Multichain JSON RPC url + port
43
     * @param  string $username Multichain JSON RPC username
44
     * @param  string $password Multichain JSON RPC password
45
     * @param  integer $timeout HTTP timeout
46
     */
47
    public function __construct($url, $username, $password, $timeout = 3)
0 ignored issues
show
Unused Code introduced by
The parameter $timeout is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        $this->jsonRPCClient = new JsonRPCClient($url);
50
        $httpClient = $this->jsonRPCClient->getHttpClient();
51
        $httpClient->withHeaders($this->headers);
52
        $this->jsonRPCClient->authentication($username, $password);
53
    }
54
55
    /**
56
     * @param boolean $debug
57
     * @return MultichainClient
58
     */
59
    public function setDebug($debug)
60
    {
61
        $this->debug = $debug;
62
        if($debug){
63
            $httpClient = $this->jsonRPCClient->getHttpClient();
64
            $httpClient->withDebug();
65
        }
66
        return $this;
67
    }
68
69
    /**
70
     * Returns general information about this node and blockchain. MultiChain adds some fields to Bitcoin Core’s
71
     * response, giving the blockchain’s chainname, description, protocol, peer-to-peer port. The setupblocks field
72
     * gives the length in blocks of the setup phase in which some consensus constraints are not applied. The
73
     * nodeaddress can be passed to other nodes for connecting.
74
     *
75
     * @return mixed
76
     */
77
    public function getInfo()
78
    {
79
        return $this->jsonRPCClient->execute("getinfo");
80
    }
81
82
    /**
83
     * Returns information about the other nodes to which this node is connected. If this is a MultiChain blockchain,
84
     * includes handshake and handshakelocal fields showing the remote and local address used during the handshaking
85
     * for that connection.
86
     *
87
     * @return mixed
88
     */
89
    public function getPeerInfo()
90
    {
91
        return $this->jsonRPCClient->execute("getpeerinfo");
92
    }
93
94
    /**
95
     * Returns a new address for receiving payments. Omit the account parameter for the default account – see note below
96
     *
97
     * NOTE:
98
     * Bitcoin Core has a notion of “accounts”, whereby each address can belong to specific account, which is credited
99
     * when bitcoin is sent to that address. However the separation of accounts is not preserved when bitcoin is sent
100
     * out, because the internal accounting mechanism has no relationship to the bitcoin protocol itself. Because of
101
     * all the confusion this has caused, Bitcoin Core’s accounts mechanism is to be deprecated in future.
102
     *
103
     * MultiChain preserves the accounts mechanism and parameters for full backwards compatibility with the Bitcoin
104
     * Core API. However, because of its forthcoming deprecation, the mechanism is not applied to native asset
105
     * balances, all of which are considered as belonging to a single global account. Therefore we recommend not using
106
     * accounts at all with MultiChain, and using "" for any account parameter in the API.
107
     *
108
     * To support multiple users in a single MultiChain node’s wallet, call getnewaddress to get a different address
109
     * for each user. You should then use MultiChain’s *from* APIs, such as sendassetfrom and sendfromaddress, to
110
     * control whose funds are spent in each transaction. Unlike bitcoin-style accounts, this method maps directly to
111
     * the blockchain protocol.
112
     *
113
     * @param string $account
114
     * @return mixed
115
     */
116
    public function getNewAddress($account = '')
117
    {
118
        return $this->jsonRPCClient->execute("getnewaddress", array($account));
119
    }
120
121
    /**
122
     * Returns the private key associated with address in this node’s wallet. Use with caution – any node with access to this
123
     * private key can perform any action restricted to the address, including granting permissions and spending funds.
124
     *
125
     * @param $address
126
     * @return mixed
127
     */
128
    public function dumpPrivateKey($address){
129
        return $this->jsonRPCClient->execute("dumpprivkey", array($address));
130
    }
131
132
    /**
133
     * Adds the privkey private key (as obtained from a prior call to dumpprivkey) to the wallet, together with its
134
     * associated public address. If rescan is true, the entire blockchain is checked for transactions relating to
135
     * all addresses in the wallet, including the added one.
136
     *
137
     * @param $privkey
138
     * @param string $label
139
     * @param bool $rescan
140
     * @return mixed
141
     */
142
    public function importPrivateKey($privkey, $label="", $rescan=true){
143
        return $this->jsonRPCClient->execute("importprivkey", array($privkey, $label, $rescan));
144
    }
145
146
    /**
147
     * Sends one or more assets to address, returning the txid. In Bitcoin Core, the amount field is the quantity of
148
     * the bitcoin currency. For MultiChain, an {"asset":qty, ...} object can be used for amount, in which each asset
149
     * is an asset name, ref or issuance txid, and each qty is the quantity of that asset to send (see native assets).
150
     * Use "" as the asset inside this object to specify a quantity of the native blockchain currency. See also
151
     * sendassettoaddress for sending a single asset and sendfromaddress to control the address whose funds are used.
152
     *
153
     * @param string $address
154
     * @param string $amount
155
     * @param string $comment
156
     * @param string $commentTo
157
     * @return mixed
158
     */
159
    public function sendToAddress($address, $amount, $comment = '', $commentTo = '')
160
    {
161
        return $this->jsonRPCClient->execute("sendtoaddress", array($address, $amount, $comment, $commentTo));
162
    }
163
164
    /**
165
     * Outputs a list of available API commands, including MultiChain-specific commands.
166
     *
167
     * @return mixed
168
     */
169
    public function help()
170
    {
171
        return $this->jsonRPCClient->execute("help");
172
    }
173
174
    /**
175
     * Adds to the atomic exchange transaction in hexstring given by a previous call to createrawexchange or
176
     * appendrawexchange. This adds an offer to exchange the asset/s in output vout of transaction txid for qty units
177
     * of asset, where asset is an asset name, ref or issuance txid. The txid and vout should generally be taken from
178
     * the response to preparelockunspent or preparelockunspentfrom. Multiple items can be specified within the fourth
179
     * parameter to request multiple assets. Returns a raw hexadecimal transaction in the hex field alongside a
180
     * complete field stating whether the exchange is complete (i.e. balanced) or not. If complete, the transaction can
181
     * be transmitted to the network using sendrawtransaction. If not, it can be passed to a further counterparty, who
182
     * can call decoderawexchange and appendrawexchange as appropriate.
183
     *
184
     * @param $hexString
185
     * @param $txId
186
     * @param $vOut
187
     * @param $extra ({"asset":qty, ...})
188
     * @return mixed
189
     */
190
    public function appendRawExchange($hexString, $txId, $vOut, $extra)
191
    {
192
        return $this->jsonRPCClient->execute("appendrawexchange", array($hexString, $txId, $vOut, $extra));
193
    }
194
195
    /**
196
     * Adds a metadata output to the raw transaction in tx-hex given by a previous call to createrawtransaction. The
197
     * metadata is specified in data-hex in hexadecimal form and added in a new OP_RETURN transaction output. The
198
     * transaction can then be signed and transmitted to the network using signrawtransaction and sendrawtransaction.
199
     *
200
     * @param $txHex
201
     * @param $dataHex
202
     * @return mixed
203
     */
204
    public function appendRawMetadata($txHex, $dataHex)
205
    {
206
        return $this->jsonRPCClient->execute("appendrawmetadata", array($txHex, $dataHex));
207
    }
208
209
    /**
210
     * Sends transactions to combine large groups of unspent outputs (UTXOs) belonging to the same address into a
211
     * single unspent output, returning a list of txids. This can improve wallet performance, especially for miners in
212
     * a chain with short block times and non-zero block rewards. Set addresses to a comma-separated list of addresses
213
     * to combine outputs for, or * for all addresses in the wallet. Only combine outputs with at least minconf
214
     * confirmations, and use between mininputs and maxinputs per transaction. A single call to combineunspent can
215
     * create up to maxcombines transactions over up to maxtime seconds. See also the autocombine runtime parameters.
216
     *
217
     * @param string $addresses
218
     * @param int $minConf
219
     * @param int $maxCombines
220
     * @param int $minInputs
221
     * @param int $maxInputs
222
     * @param int $maxTime
223
     * @return mixed
224
     */
225
    public function combineUnspent($addresses = "*", $minConf = 1, $maxCombines = 1, $minInputs = 10, $maxInputs = 100, $maxTime = 30)
226
    {
227
        return $this->jsonRPCClient->execute("combineunspent", array($addresses, $minConf, $maxCombines, $minInputs, $maxInputs, $maxTime));
228
    }
229
230
    /**
231
     * Creates a new atomic exchange transaction which offers to exchange the asset/s in output vout of transaction
232
     * txid for qty units of asset, where asset is an asset name, ref or issuance txid. The txid and vout should
233
     * generally be taken from the response to preparelockunspent or preparelockunspentfrom. Multiple items can be
234
     * specified within the third parameter to request multiple assets. Returns a raw partial transaction in
235
     * hexadecimal which can be passed to the counterparty, who can call decoderawexchange and appendrawexchange as
236
     * appropriate.
237
     *
238
     * @param $txId
239
     * @param $vOut
240
     * @param $extra
241
     * @return mixed
242
     */
243
    public function createRawExchange($txId, $vOut, $extra)
244
    {
245
        return $this->jsonRPCClient->execute("createrawexchange", array($txId, $vOut, $extra));
246
    }
247
248
    /**
249
     * Decodes the raw exchange transaction in hexstring, given by a previous call to createrawexchange or
250
     * appendrawexchange. Returns details on the offer represented by the exchange and its present state. The offer
251
     * field in the response lists the quantity of native currency and/or assets which are being offered for exchange.
252
     * The ask field lists the native currency and/or assets which are being asked for. The candisable field specifies
253
     * whether this wallet can disable the exchange transaction by double-spending against one of its inputs. The
254
     * cancomplete field specifies whether this wallet has the assets required to complete the exchange. The complete
255
     * field specifies whether the exchange is already complete (i.e. balanced) and ready for sending. If verbose is
256
     * true then all of the individual stages in the exchange are listed. Other fields relating to fees are only
257
     * relevant for blockchains which use a native currency.
258
     *
259
     * @param $hexString
260
     * @param bool $verbose
261
     * @return mixed
262
     */
263
    public function decodeRawExchange($hexString, $verbose = false)
264
    {
265
        return $this->jsonRPCClient->execute("decoderawexchange", array($hexString, $verbose));
266
    }
267
268
    /**
269
     * Sends a transaction to disable the offer of exchange in hexstring, returning the txid. This is achieved by
270
     * spending one of the exchange transaction’s inputs and sending it back to the wallet. To check whether this can
271
     * be used on an exchange transaction, check the candisable field of the output of decoderawexchange.
272
     *
273
     * @param $hexString
274
     * @return mixed
275
     */
276
    public function disableRawTransaction($hexString)
277
    {
278
        return $this->jsonRPCClient->execute("disablerawtransaction", array($hexString));
279
    }
280
281
    /**
282
     * Returns a list of all the asset balances for address in this node’s wallet, with at least minconf confirmations.
283
     * Use includeLocked to include unspent outputs which have been locked, e.g. by a call to preparelockunspent.
284
     *
285
     * @param $address
286
     * @param int $minConf
287
     * @param bool $includeLocked
288
     * @return mixed
289
     */
290
    public function getAddressBalances($address, $minConf = 1, $includeLocked = false)
291
    {
292
        return $this->jsonRPCClient->execute("getaddressbalances", array($address, $minConf, $includeLocked));
293
    }
294
295
    /**
296
     * Returns a list of addresses in this node’s wallet. Set verbose to true to get more information about each
297
     * address, formatted like the output of the validateaddress command.
298
     *
299
     * @param bool $verbose
300
     * @return mixed
301
     */
302
    public function getAddresses($verbose = false)
303
    {
304
        return $this->jsonRPCClient->execute("getaddresses", array($verbose));
305
    }
306
307
    /**
308
     * Provides information about transaction txid related to address in this node’s wallet, including how it affected
309
     * that address’s balance. Use verbose to provide details of transaction inputs and outputs.
310
     *
311
     * @param $address
312
     * @param $txId
313
     * @param bool $verbose
314
     * @return mixed
315
     */
316
    public function getAddressTransaction($address, $txId, $verbose = false)
317
    {
318
        return $this->jsonRPCClient->execute("getaddresstransaction", array($address, $txId, $verbose));
319
    }
320
321
    /**
322
     * Returns a list of all the asset balances for account in this node’s wallet, with at least minconf confirmations.
323
     * Omit the account parameter or use "" for the default account – see note about accounts. Use includeWatchOnly to
324
     * include the balance of watch-only addresses and includeLocked to include unspent outputs which have been locked,
325
     * e.g. by a call to preparelockunspent.
326
     *
327
     * @param string $account
328
     * @param int $minConf
329
     * @param bool $includeWatchOnly
330
     * @param bool $includeLocked
331
     * @return mixed
332
     */
333
    public function getAssetBalances($account = "", $minConf = 1, $includeWatchOnly = false, $includeLocked = false)
334
    {
335
        return $this->jsonRPCClient->execute("getassetbalances", array($account, $minConf, $includeWatchOnly, $includeLocked));
336
    }
337
338
    /**
339
     * Returns a list of all the asset balances in this node’s wallet, with at least minconf confirmations. Use
340
     * includeWatchOnly to include the balance of watch-only addresses and includeLocked to include unspent outputs
341
     * which have been locked, e.g. by a call to preparelockunspent.
342
     *
343
     * @param int $minConf
344
     * @param bool $includeWatchOnly
345
     * @param bool $includeLocked
346
     * @return mixed
347
     */
348
    public function getTotalBalances($minConf = 1, $includeWatchOnly = false, $includeLocked = false)
349
    {
350
        return $this->jsonRPCClient->execute("getassetbalances", array($minConf, $includeWatchOnly, $includeLocked));
351
    }
352
353
    /**
354
     * Returns information about address including a check for its validity.
355
     *
356
     * @param $address
357
     * @return mixed
358
     */
359
    public function validateAddress($address)
360
    {
361
        return $this->jsonRPCClient->execute("validateaddress", array($address));
362
    }
363
364
    /**
365
     * Provides information about transaction txid in this node’s wallet, including how it affected the node’s total
366
     * balance. Use includeWatchOnly to consider watch-only addresses as if they belong to this wallet and verbose to
367
     * provide details of transaction inputs and outputs.
368
     *
369
     * @param $txId
370
     * @param bool $includeWatchOnly
371
     * @param bool $verbose
372
     * @return mixed
373
     */
374
    public function getWalletTransaction($txId, $includeWatchOnly = false, $verbose = false)
375
    {
376
        return $this->jsonRPCClient->execute("getwallettransaction", array($txId, $includeWatchOnly, $verbose));
377
    }
378
379
    /**
380
     * Grants permissions to addresses, where addresses is a comma-separated list of addresses and permissions is one
381
     * of connect, send, receive, issue, mine, admin, or a comma-separated list thereof. If the chain uses a native
382
     * currency, you can send some to each recipient using the native-amount parameter. Returns the txid of the
383
     * transaction granting the permissions. For more information, see permissions management.
384
     *
385
     * @param $addresses
386
     * @param $permissions
387
     * @param int $nativeAmount
388
     * @param string $comment
389
     * @param string $commentTo
390
     * @param int $startBlock
391
     * @param null $endBlock
392
     * @return mixed
393
     */
394
    public function grant($addresses, $permissions, $nativeAmount = 0, $comment = '', $commentTo = '', $startBlock = 0, $endBlock = null)
395
    {
396
        return $this->jsonRPCClient->execute("grant", array($addresses, $permissions, $nativeAmount, $comment, $commentTo, $startBlock, $endBlock));
397
    }
398
399
    /**
400
     * This works like grant, but with control over the from-address used to grant the permissions. If there are
401
     * multiple addresses with administrator permissions on one node, this allows control over which address is used.
402
     *
403
     * @param $fromAddress
404
     * @param $toAddresses
405
     * @param $permissions
406
     * @param int $nativeAmount
407
     * @param string $comment
408
     * @param string $commentTo
409
     * @param int $startBlock
410
     * @param null $endBlock
411
     * @return mixed
412
     */
413
    public function grantFrom($fromAddress, $toAddresses, $permissions, $nativeAmount = 0, $comment = '', $commentTo = '', $startBlock = 0, $endBlock = null)
414
    {
415
        return $this->jsonRPCClient->execute("grantfrom", array($fromAddress, $toAddresses, $permissions, $nativeAmount, $comment, $commentTo, $startBlock, $endBlock));
416
    }
417
418
    /**
419
     * Creates a new asset name on the blockchain, sending the initial qty units to address. The smallest transactable
420
     * unit is given by units, e.g. 0.01. If the chain uses a native currency, you can send some with the new asset
421
     * using the native-amount parameter.
422
     *
423
     * @param $address
424
     * @param $name
425
     * @param $qty
426
     * @param int $units
427
     * @param int $nativeAmount
428
     * @param null $custom
429
     * @param bool $open
430
     * @return mixed
431
     */
432
    public function issue($address, $name, $qty, $units = 1, $nativeAmount = 0, $custom = null, $open=false)
433
    {
434
        $params = array($address, array('name'=>$name, 'open'=>$open), $qty, $units, $nativeAmount);
435
        if (!is_null($custom)) {
436
            $params[] = $custom;
437
        }
438
        return $this->jsonRPCClient->execute("issue", $params);
439
    }
440
441
    /**
442
     * Issues qty additional units of asset, sending them to address. The asset can be specified using its name, ref or
443
     * issuance txid – see native assets for more information. If the chain uses a native currency, you can send some with the
444
     * new asset units using the native-amount parameter. Any custom fields will be attached to the new issuance event, and not
445
     * affect the original values (use listassets with verbose=true to see both sets). Returns the txid of the issuance
446
     * transaction. For more information, see native assets.
447
     *
448
     * @param $address
449
     * @param $asset
450
     * @param $qty
451
     * @param int $nativeAmount
452
     * @param null $custom
453
     * @return mixed
454
     */
455
    public function issueMore($address, $asset, $qty, $nativeAmount=0, $custom = null){
456
        $params = array($address, $asset, $qty, $nativeAmount);
457
        if (!is_null($custom)) {
458
            $params[] = $custom;
459
        }
460
        return $this->jsonRPCClient->execute("issuemore", $params);
461
    }
462
463
    /**
464
     * This works like issue, but with control over the from-address used to issue the asset. If there are multiple
465
     * addresses with asset issuing permissions on one node, this allows control over which address is used.
466
     *
467
     * @param $fromAddress
468
     * @param $toAddress
469
     * @param $name
470
     * @param $qty
471
     * @param int $units
472
     * @param int $nativeAmount
473
     * @param null $custom
474
     * @return mixed
475
     */
476
    public function issueFrom($fromAddress, $toAddress, $name, $qty, $units = 1, $nativeAmount = 0, $custom = null)
477
    {
478
        return $this->jsonRPCClient->execute("issuefrom", array($fromAddress, $toAddress, $name, $qty, $units, $nativeAmount, $custom));
479
    }
480
481
    /**
482
     * Lists information about the count most recent transactions related to address in this node’s wallet, including
483
     * how they affected that address’s balance. Use skip to go back further in history and verbose to provide details
484
     * of transaction inputs and outputs.
485
     *
486
     * @param $address
487
     * @param int $count
488
     * @param int $skip
489
     * @param bool $verbose
490
     * @return mixed
491
     */
492
    public function listAddressTransactions($address, $count = 10, $skip = 0, $verbose = false)
493
    {
494
        return $this->jsonRPCClient->execute("listaddresstransactions", array($address, $count, $skip, $verbose));
495
    }
496
497
    /**
498
     * Returns information about all assets issued on the blockchain. If an issuance txid
499
     * (see native assets) is provided in asset, then information is only returned about that one asset.
500
     *
501
     * @param null $asset
502
     * @return mixed
503
     */
504
    public function listAssets($asset = null)
505
    {
506
        return $this->jsonRPCClient->execute("listassets", array($asset));
507
    }
508
509
    /**
510
     * Returns a list of all permissions currently granted to addresses. To list information about specific permissions
511
     * only, set permissions to one of connect, send, receive, issue, mine, admin, or a comma-separated list thereof.
512
     * Omit or pass all to list all permissions. Provide a comma-delimited list in addresses to list the permissions
513
     * for particular addresses only or * for all addresses. If verbose is true, the admins output field lists the
514
     * administrator/s who assigned the corresponding permission, and the pending field lists permission changes which
515
     * are waiting to reach consensus.
516
     *
517
     * @param string $permissions
518
     * @param string $addresses
519
     * @param bool $verbose
520
     * @return mixed
521
     */
522
    public function listPermissions($permissions = "all", $addresses = "*", $verbose = false)
523
    {
524
        return $this->jsonRPCClient->execute("listpermissions", array($permissions, $addresses, $verbose));
525
    }
526
527
    /**
528
     * Lists information about the count most recent transactions in this node’s wallet, including how they affected
529
     * the node’s total balance. Use skip to go back further in history and includeWatchOnly to consider watch-only
530
     * addresses as if they belong to this wallet. Use verbose to provide the details of transaction inputs and outputs.
531
     * Note that unlike Bitcoin Core’s listtransactions command, the response contains one element per transaction,
532
     * rather than one per transaction output.
533
     *
534
     * @param int $count
535
     * @param int $skip
536
     * @param bool $includeWatchOnly
537
     * @param bool $verbose
538
     * @return mixed
539
     */
540
    public function listWalletTransactions($count = 10, $skip = 0, $includeWatchOnly = false, $verbose = false)
541
    {
542
        return $this->jsonRPCClient->execute("listwallettransactions", array($count, $skip, $includeWatchOnly, $verbose));
543
    }
544
545
    /**
546
     * Prepares an unspent transaction output (useful for building atomic exchange transactions) containing qty units
547
     * of asset, where asset is an asset name, ref or issuance txid. Multiple items can be specified within the first
548
     * parameter to include several assets within the output. The output will be locked against automatic selection for
549
     * spending unless the optional lock parameter is set to false. Returns the txid and vout of the prepared output.
550
     *
551
     * @param $assetsToLock
552
     * @param bool $lock
553
     * @return mixed
554
     */
555
    public function prepareLockUnspent($assetsToLock, $lock = true)
556
    {
557
        return $this->jsonRPCClient->execute("preparelockunspent", array($assetsToLock, $lock));
558
    }
559
560
    /**
561
     * This works like preparelockunspent, but with control over the from-address whose funds are used to prepare the
562
     * unspent transaction output. Any change from the transaction is send back to from-address.
563
     *
564
     * @param $fromAddress
565
     * @param $assetsToLock
566
     * @param bool $lock
567
     * @return mixed
568
     */
569
    public function prepareLockUnspentFrom($fromAddress, $assetsToLock, $lock = true)
570
    {
571
        return $this->jsonRPCClient->execute("preparelockunspentfrom", array($fromAddress, $assetsToLock, $lock));
572
    }
573
574
    /**
575
     * Revokes permissions from addresses, where addresses is a comma-separated list of addresses and permissions is
576
     * one of connect, send, receive, issue, mine, admin, or a comma-separated list thereof. Equivalent to calling
577
     * grant with start-block=0 and end-block=0. Returns the txid of transaction revoking the permissions. For more
578
     * information, see permissions management.
579
     *
580
     * @param $addresses
581
     * @param $permissions
582
     * @param int $nativeAmount
583
     * @param string $comment
584
     * @param string $commentTo
585
     * @return mixed
586
     */
587
    public function revoke($addresses, $permissions, $nativeAmount = 0, $comment = '', $commentTo = '')
588
    {
589
        return $this->jsonRPCClient->execute("revoke", array($addresses, $permissions, $nativeAmount, $comment, $commentTo));
590
    }
591
592
    /**
593
     * This works like revoke, but with control over the from-address used to revoke the permissions. If there are
594
     * multiple addresses with administrator permissions on one node, this allows control over which address is used.
595
     *
596
     * @param $fromAddress
597
     * @param $toAddresses
598
     * @param $permissions
599
     * @param int $nativeAmount
600
     * @param string $comment
601
     * @param string $commentTo
602
     * @return mixed
603
     */
604
    public function revokeFrom($fromAddress, $toAddresses, $permissions, $nativeAmount = 0, $comment = '', $commentTo = '')
605
    {
606
        return $this->jsonRPCClient->execute("revokefrom", array($fromAddress, $toAddresses, $permissions, $nativeAmount, $comment, $commentTo));
607
    }
608
609
    /**
610
     * This works like sendassettoaddress, but with control over the from-address whose funds are used. Any change from
611
     * the transaction is sent back to from-address. See also sendfromaddress for sending multiple assets in one
612
     * transaction.
613
     *
614
     * @param $fromAddress
615
     * @param $toAddress
616
     * @param $asset
617
     * @param $qty
618
     * @param null $nativeAmount
619
     * @param string $comment
620
     * @param string $commentTo
621
     * @return mixed
622
     */
623
    public function sendAssetFrom($fromAddress, $toAddress, $asset, $qty, $nativeAmount = null, $comment = '', $commentTo = '')
624
    {
625
        $nativeAmount = $this->findDefaultMinimumPerOutput($nativeAmount);
626
        return $this->jsonRPCClient->execute("sendassetfrom", array($fromAddress, $toAddress, $asset, $qty, $nativeAmount, $comment, $commentTo));
627
    }
628
629
    /**
630
     * Returns a list of all the parameters of this blockchain, reflecting the content of its params.dat file.
631
     *
632
     * @return mixed
633
     */
634
    public function getBlockchainParams()
635
    {
636
        return $this->jsonRPCClient->execute("getblockchainparams");
637
    }
638
639
    /**
640
     * Sends qty of asset to address, returning the txid. The asset can be specified using its name, ref or issuance
641
     * txid – see native assets for more information. See also sendassetfrom to control the address whose funds are
642
     * used, sendtoaddress for sending multiple assets in one transaction, and sendfromaddress to combine both of these.
643
     *
644
     * @param $address
645
     * @param $asset
646
     * @param $qty
647
     * @param null $nativeAmount
648
     * @param string $comment
649
     * @param string $commentTo
650
     * @return mixed
651
     */
652
    public function sendAssetToAddress($address, $asset, $qty, $nativeAmount = null, $comment = '', $commentTo = '')
653
    {
654
        $nativeAmount = $this->findDefaultMinimumPerOutput($nativeAmount);
655
        return $this->jsonRPCClient->execute("sendassettoaddress", array($address, $asset, $qty, $nativeAmount, $comment, $commentTo));
656
    }
657
658
    /**
659
     * This works like sendtoaddress, but with control over the from-address whose funds are used. Any
660
     * change from the transaction is sent back to from-address.
661
     *
662
     * @param $fromAddress
663
     * @param $toAddress
664
     * @param $amount
665
     * @param string $comment
666
     * @param string $commentTo
667
     * @return mixed
668
     */
669
    public function sendFromAddress($fromAddress, $toAddress, $amount, $comment = '', $commentTo = '')
670
    {
671
        return $this->jsonRPCClient->execute("sendfromaddress", array($fromAddress, $toAddress, $amount, $comment, $commentTo));
672
    }
673
674
    /**
675
     * This works like sendtoaddress (listed above), but includes the data-hex hexadecimal metadata in an additional
676
     * OP_RETURN transaction output.
677
     *
678
     * @param $address
679
     * @param $amount
680
     * @param $dataHex
681
     * @return mixed
682
     */
683
    public function sendWithMetadata($address, $amount, $dataHex)
684
    {
685
        return $this->jsonRPCClient->execute("sendwithmetadata", array($address, $amount, $dataHex));
686
    }
687
688
    /**
689
     * This works like sendtoaddress (listed above), but with control over the from-address whose funds are used, and
690
     * with the data-hex hexadecimal metadata added in an additional OP_RETURN transaction output. Any change from the
691
     * transaction is sent back to from-address.
692
     *
693
     * @param $fromAddress
694
     * @param $toAddress
695
     * @param $amount
696
     * @param $dataHex
697
     * @return mixed
698
     */
699
    public function sendWithMetadataFrom($fromAddress, $toAddress, $amount, $dataHex)
700
    {
701
        return $this->jsonRPCClient->execute("sendwithmetadatafrom", array($fromAddress, $toAddress, $amount, $dataHex));
702
    }
703
704
    /**
705
     * Creates a transaction spending the specified inputs, sending to the given addresses. In Bitcoin Core, each
706
     * amount field is a quantity of the bitcoin currency. For MultiChain, an {"asset":qty, ...} object can be used for
707
     * amount, in which each asset is an asset name, ref or issuance txid, and each qty is the quantity of that asset
708
     * to send (see native assets). Use "" as the asset inside this object to specify a quantity of the native
709
     * blockchain currency.
710
     *
711
     * @param $inputs
712
     * @param $addresses
713
     * @return mixed
714
     */
715
    public function createRawTransaction($inputs, $addresses)
716
    {
717
        return $this->jsonRPCClient->execute("createrawtransaction", array($inputs, $addresses));
718
    }
719
720
    /**
721
     * Returns a JSON object describing the serialized transaction in hexstring. For a MultiChain blockchain, each
722
     * transaction output includes assets and permissions fields listing any assets or permission changes encoded
723
     * within that output. There will also be a data field listing the content of any OP_RETURN outputs in the
724
     * transaction.
725
     *
726
     * @param $hexString
727
     * @return mixed
728
     */
729
    public function decodeRawTransaction($hexString)
730
    {
731
        return $this->jsonRPCClient->execute("decoderawtransaction", array($hexString));
732
    }
733
734
    /**
735
     * Returns information about the block with hash. If this is a MultiChain blockchain and format is true or omitted,
736
     * then the output includes a field miner showing the address of the miner of the block.
737
     *
738
     * @param $hash
739
     * @param bool $format
740
     * @return mixed
741
     */
742
    public function getBlock($hash, $format = true)
743
    {
744
        return $this->jsonRPCClient->execute("getblock", array($hash, $format));
745
    }
746
747
    /**
748
     * If verbose is 1, returns a JSON object describing transaction txid. For a MultiChain blockchain, each transaction
749
     * output includes assets and permissions fields listing any assets or permission changes encoded within that
750
     * output. There will also be a data field listing the content of any OP_RETURN outputs in the transaction.
751
     *
752
     * @param $txId
753
     * @param int $verbose
754
     * @return mixed
755
     */
756
    public function getRawTransaction($txId, $verbose = 0)
757
    {
758
        return $this->jsonRPCClient->execute("getrawtransaction", array($txId, $verbose));
759
    }
760
761
    /**
762
     * Returns details about an unspent transaction output vout of txid. For a MultiChain blockchain, includes assets
763
     * and permissions fields listing any assets or permission changes encoded within the output. Set confirmed to true
764
     * to include unconfirmed transaction outputs.
765
     *
766
     * @param $txId
767
     * @param $vOut
768
     * @param bool $unconfirmed
769
     * @return mixed
770
     */
771
    public function getTxOut($txId, $vOut, $unconfirmed = false)
772
    {
773
        return $this->jsonRPCClient->execute("gettxout", array($txId, $vOut, $unconfirmed));
774
    }
775
776
    /**
777
     * Returns a list of unspent transaction outputs in the wallet, with between minconf and maxconf confirmations. For
778
     * a MultiChain blockchain, each transaction output includes assets and permissions fields listing any assets or
779
     * permission changes encoded within that output. If addresses is provided, only outputs which pay an address in
780
     * this array will be included.
781
     *
782
     * @param int $minConf
783
     * @param int $maxConf
784
     * @param null $addresses
785
     * @return mixed
786
     */
787
    public function listUnspent($minConf = 1, $maxConf = 999999, $addresses = null)
788
    {
789
        return $this->jsonRPCClient->execute("listunspent", array($minConf, $maxConf, $addresses));
790
    }
791
792
    /**
793
     * @param $nativeAmount
794
     * @return mixed
795
     */
796
    private function findDefaultMinimumPerOutput($nativeAmount)
797
    {
798
        if (is_null($nativeAmount)) {
799
            $blockchainParams = $this->getBlockchainParams();
800
            $nativeAmount = $blockchainParams["minimum-per-output"];
801
            return $nativeAmount;
802
        }
803
        return $nativeAmount;
804
    }
805
806
    /**
807
     * Submits raw transaction (serialized, hex-encoded) to local node and network.
808
     * Returns the transaction hash in hex
809
     *
810
     * @param $hex
811
     * @param bool $allowHighFees
812
     * @return mixed
813
     */
814
    public function sendRawTransaction($hex, $allowHighFees = false)
815
    {
816
        return $this->jsonRPCClient->execute("sendrawtransaction", array($hex, $allowHighFees));
817
    }
818
}
819