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