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.
Completed
Push — master ( 1029b6...5d87db )
by Roderik
02:30
created

MultichainClient::dumpPrivateKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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