1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AdrianMejias\FactomApi; |
4
|
|
|
|
5
|
|
|
class FactomWalletApi extends FactomConnector |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Example of an invalid method. |
9
|
|
|
* |
10
|
|
|
* @url https://docs.factom.com/api#errors45 |
11
|
|
|
* |
12
|
|
|
* @return json { int code, string message } |
13
|
|
|
*/ |
14
|
|
|
public function errors() |
15
|
|
|
{ |
16
|
|
|
$result = $this->callEndpoint('bad', 'GET'); |
|
|
|
|
17
|
|
|
|
18
|
|
|
// return Result |
19
|
|
|
return $result; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Retrieve the public and private parts of a Factoid or Entry Credit address stored in the wallet. |
24
|
|
|
* |
25
|
|
|
* @url https://docs.factom.com/api#address |
26
|
|
|
* |
27
|
|
|
* @return json { string public, string secret } |
28
|
|
|
*/ |
29
|
|
|
public function address(string $address) |
30
|
|
|
{ |
31
|
|
|
$result = $this->callEndpoint('address', 'GET', [ |
|
|
|
|
32
|
|
|
'address' => $address, |
33
|
|
|
]); |
34
|
|
|
|
35
|
|
|
// return Result |
36
|
|
|
return $result; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Retrieve all of the Factoid and Entry Credit addresses stored in the wallet. |
41
|
|
|
* |
42
|
|
|
* @url https://docs.factom.com/api#all-address |
43
|
|
|
* |
44
|
|
|
* @return json { array addresses } |
45
|
|
|
*/ |
46
|
|
|
public function allAddress(string $address) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$result = $this->callEndpoint('all-address', 'GET'); |
|
|
|
|
49
|
|
|
|
50
|
|
|
// return Result |
51
|
|
|
return $result; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Create a new Entry Credit Address and store it in the wallet. |
56
|
|
|
* |
57
|
|
|
* @url https://docs.factom.com/api#generate-ec-address |
58
|
|
|
* |
59
|
|
|
* @return json { string public, string secret } |
60
|
|
|
*/ |
61
|
|
|
public function generateEcAddress() |
62
|
|
|
{ |
63
|
|
|
$result = $this->callEndpoint('generate-ec-address', 'GET'); |
|
|
|
|
64
|
|
|
|
65
|
|
|
// return Result |
66
|
|
|
return $result; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Create a new Entry Credit Address and store it in the wallet. |
71
|
|
|
* |
72
|
|
|
* @url https://docs.factom.com/api#generate-factoid-address |
73
|
|
|
* |
74
|
|
|
* @return json { string public, string secret } |
75
|
|
|
*/ |
76
|
|
|
public function generateFactoidAddress() |
77
|
|
|
{ |
78
|
|
|
$result = $this->callEndpoint('generate-factoid-address', 'GET'); |
|
|
|
|
79
|
|
|
|
80
|
|
|
// return Result |
81
|
|
|
return $result; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the current hight of blocks that have been cached by the wallet while syncing. |
86
|
|
|
* |
87
|
|
|
* @url https://docs.factom.com/api#get-height |
88
|
|
|
* |
89
|
|
|
* @return json { int height } |
90
|
|
|
*/ |
91
|
|
|
public function getHeight() |
92
|
|
|
{ |
93
|
|
|
$result = $this->callEndpoint('get-height', 'GET'); |
|
|
|
|
94
|
|
|
|
95
|
|
|
// return Result |
96
|
|
|
return $result; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Import Factoid and/or Entry Credit address secret keys into the wallet. |
101
|
|
|
* |
102
|
|
|
* @url https://docs.factom.com/api#import-addresses |
103
|
|
|
* |
104
|
|
|
* @return json { array addresses } |
105
|
|
|
*/ |
106
|
|
|
public function importAddresses(string $addresses) |
107
|
|
|
{ |
108
|
|
|
$result = $this->callEndpoint('addresses', 'GET', [ |
|
|
|
|
109
|
|
|
'addresses' => $addresses, |
110
|
|
|
]); |
111
|
|
|
|
112
|
|
|
// return Result |
113
|
|
|
return $result; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Import a Koinify crowd sale address into the wallet. |
118
|
|
|
* |
119
|
|
|
* @url https://docs.factom.com/api#import-koinify |
120
|
|
|
* |
121
|
|
|
* @return json { string public, string secret } |
122
|
|
|
*/ |
123
|
|
|
public function importKoinify(string $words) |
124
|
|
|
{ |
125
|
|
|
$result = $this->callEndpoint('import-koinify', 'GET', [ |
|
|
|
|
126
|
|
|
'words' => $words, |
127
|
|
|
]); |
128
|
|
|
|
129
|
|
|
// return Result |
130
|
|
|
return $result; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Return the wallet seed and all addresses in the wallet for backup and offline storage. |
135
|
|
|
* |
136
|
|
|
* @url https://docs.factom.com/api#wallet-backup |
137
|
|
|
* |
138
|
|
|
* @return json { string wallet-seed, array addresses } |
139
|
|
|
*/ |
140
|
|
|
public function walletBackup() |
141
|
|
|
{ |
142
|
|
|
$result = $this->callEndpoint('wallet-backup', 'GET'); |
|
|
|
|
143
|
|
|
|
144
|
|
|
// return Result |
145
|
|
|
return $result; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* This will retrieve all transactions within a given block height range. |
150
|
|
|
* |
151
|
|
|
* @url https://docs.factom.com/api#transactions-retrieving |
152
|
|
|
* |
153
|
|
|
* @return json { array transactions } |
154
|
|
|
*/ |
155
|
|
|
public function transactionsByRange(int $start, int $end) |
|
|
|
|
156
|
|
|
{ |
157
|
|
|
$result = $this->callEndpoint('transactions', 'POST'); |
|
|
|
|
158
|
|
|
|
159
|
|
|
// return Result |
160
|
|
|
return $result; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* This will retrieve a transaction by the given TxID. |
165
|
|
|
* |
166
|
|
|
* @url https://docs.factom.com/api#by-txid |
167
|
|
|
* |
168
|
|
|
* @return json { array transactions } |
169
|
|
|
*/ |
170
|
|
|
public function transactionsByTxID(string $txid) |
|
|
|
|
171
|
|
|
{ |
172
|
|
|
$result = $this->callEndpoint('transactions', 'POST'); |
|
|
|
|
173
|
|
|
|
174
|
|
|
// return Result |
175
|
|
|
return $result; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Retrieves all transactions that an address is apart of. |
180
|
|
|
* |
181
|
|
|
* @url https://docs.factom.com/api#by-address |
182
|
|
|
* |
183
|
|
|
* @return json { array transactions } |
184
|
|
|
*/ |
185
|
|
|
public function transactionsByAddress(string $address) |
186
|
|
|
{ |
187
|
|
|
$result = $this->callEndpoint('transactions', 'POST', [ |
|
|
|
|
188
|
|
|
'address' => $address, |
189
|
|
|
]); |
190
|
|
|
|
191
|
|
|
// return Result |
192
|
|
|
return $result; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* The developers were so preoccupied with whether or not they could, |
197
|
|
|
* they didn’t stop to think if they should. |
198
|
|
|
* |
199
|
|
|
* @url https://docs.factom.com/api#all-transactions |
200
|
|
|
* |
201
|
|
|
* @warning The amount of data returned by this is so large. |
202
|
|
|
* |
203
|
|
|
* @return json { array transactions } |
204
|
|
|
*/ |
205
|
|
|
public function transactions(string $address) |
|
|
|
|
206
|
|
|
{ |
207
|
|
|
$result = $this->callEndpoint('transactions', 'POST'); |
|
|
|
|
208
|
|
|
|
209
|
|
|
// return Result |
210
|
|
|
return $result; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Lists all the current working transactions in the wallet. |
215
|
|
|
* |
216
|
|
|
* @url https://docs.factom.com/api#tmp-transactions |
217
|
|
|
* |
218
|
|
|
* @return json { array transactions } |
219
|
|
|
*/ |
220
|
|
|
public function tmpTransactions(string $address) |
|
|
|
|
221
|
|
|
{ |
222
|
|
|
$result = $this->callEndpoint('tmp-transactions', 'POST'); |
|
|
|
|
223
|
|
|
|
224
|
|
|
// return Result |
225
|
|
|
return $result; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Deletes a working transaction in the wallet. |
230
|
|
|
* |
231
|
|
|
* @url https://docs.factom.com/api#delete-transaction |
232
|
|
|
* |
233
|
|
|
* @return json { object ... } |
234
|
|
|
*/ |
235
|
|
|
public function deleteTransaction(string $txname) |
236
|
|
|
{ |
237
|
|
|
$result = $this->callEndpoint('delete-transaction', 'GET', [ |
|
|
|
|
238
|
|
|
'tx-name' => $txname, |
239
|
|
|
]); |
240
|
|
|
|
241
|
|
|
// return Result |
242
|
|
|
return $result; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* This will create a new transaction. |
247
|
|
|
* |
248
|
|
|
* @url https://docs.factom.com/api#new-transaction |
249
|
|
|
* |
250
|
|
|
* @return json { object ... } |
251
|
|
|
*/ |
252
|
|
|
public function newTransaction(string $txname) |
253
|
|
|
{ |
254
|
|
|
$result = $this->callEndpoint('new-transaction', 'GET', [ |
|
|
|
|
255
|
|
|
'tx-name' => $txname, |
256
|
|
|
]); |
257
|
|
|
|
258
|
|
|
// return Result |
259
|
|
|
return $result; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Adds an input to the transaction from the given address. |
264
|
|
|
* |
265
|
|
|
* @url https://docs.factom.com/api#add-input |
266
|
|
|
* |
267
|
|
|
* @return json { object ... } |
268
|
|
|
*/ |
269
|
|
View Code Duplication |
public function addInput(string $txname, string $address, int $amount) |
|
|
|
|
270
|
|
|
{ |
271
|
|
|
$result = $this->callEndpoint('add-input', 'POST', [ |
|
|
|
|
272
|
|
|
'tx-name' => $txname, |
273
|
|
|
'address' => $address, |
274
|
|
|
'amount' => $amount, |
275
|
|
|
]); |
276
|
|
|
|
277
|
|
|
// return Result |
278
|
|
|
return $result; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Adds a factoid address output to the transaction. |
283
|
|
|
* |
284
|
|
|
* @url https://docs.factom.com/api#add-output |
285
|
|
|
* |
286
|
|
|
* @return json { object ... } |
287
|
|
|
*/ |
288
|
|
View Code Duplication |
public function addOutput(string $txname, string $address, int $amount) |
|
|
|
|
289
|
|
|
{ |
290
|
|
|
$result = $this->callEndpoint('add-output', 'POST', [ |
|
|
|
|
291
|
|
|
'tx-name' => $txname, |
292
|
|
|
'address' => $address, |
293
|
|
|
'amount' => $amount, |
294
|
|
|
]); |
295
|
|
|
|
296
|
|
|
// return Result |
297
|
|
|
return $result; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* When adding entry credit outputs, the amount given is in factoshis, not entry credtis. |
302
|
|
|
* |
303
|
|
|
* @url https://docs.factom.com/api#add-ec-output |
304
|
|
|
* |
305
|
|
|
* @return json { object ... } |
306
|
|
|
*/ |
307
|
|
View Code Duplication |
public function addEcOutput(string $txname, string $address, int $amount) |
|
|
|
|
308
|
|
|
{ |
309
|
|
|
$result = $this->callEndpoint('add-ec-output', 'POST', [ |
|
|
|
|
310
|
|
|
'tx-name' => $txname, |
311
|
|
|
'address' => $address, |
312
|
|
|
'amount' => $amount, |
313
|
|
|
]); |
314
|
|
|
|
315
|
|
|
// return Result |
316
|
|
|
return $result; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Addfee is a shortcut and safeguard for adding the required additonal factoshis to covert the fee. |
321
|
|
|
* |
322
|
|
|
* @url https://docs.factom.com/api#add-fee |
323
|
|
|
* |
324
|
|
|
* @return json { object ... } |
325
|
|
|
*/ |
326
|
|
|
public function addFee(string $txname, string $address) |
327
|
|
|
{ |
328
|
|
|
$result = $this->callEndpoint('add-fee', 'POST', [ |
|
|
|
|
329
|
|
|
'tx-name' => $txname, |
330
|
|
|
'address' => $address, |
331
|
|
|
]); |
332
|
|
|
|
333
|
|
|
// return Result |
334
|
|
|
return $result; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* When paying from a transaction, you can also make the recieving transaction pay for it. |
339
|
|
|
* |
340
|
|
|
* @url https://docs.factom.com/api#sub-fee |
341
|
|
|
* |
342
|
|
|
* @return json { object ... } |
343
|
|
|
*/ |
344
|
|
|
public function subFee(string $txname, string $address) |
345
|
|
|
{ |
346
|
|
|
$result = $this->callEndpoint('sub-fee', 'POST', [ |
|
|
|
|
347
|
|
|
'tx-name' => $txname, |
348
|
|
|
'address' => $address, |
349
|
|
|
]); |
350
|
|
|
|
351
|
|
|
// return Result |
352
|
|
|
return $result; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Signs the transaction. It is now ready to be signed. |
357
|
|
|
* |
358
|
|
|
* @url https://docs.factom.com/api#sign-transaction |
359
|
|
|
* |
360
|
|
|
* @return json { object ... } |
361
|
|
|
*/ |
362
|
|
|
public function signTransaction(string $txname) |
363
|
|
|
{ |
364
|
|
|
$result = $this->callEndpoint('sign-transaction', 'POST', [ |
|
|
|
|
365
|
|
|
'tx-name' => $txname, |
366
|
|
|
]); |
367
|
|
|
|
368
|
|
|
// return Result |
369
|
|
|
return $result; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Signs the transaction. It is now ready to be signed. |
374
|
|
|
* |
375
|
|
|
* @url https://docs.factom.com/api#compose-transaction |
376
|
|
|
* |
377
|
|
|
* @return json { object ... } |
378
|
|
|
*/ |
379
|
|
|
public function composeTransaction(string $txname) |
380
|
|
|
{ |
381
|
|
|
$result = $this->callEndpoint('compose-transaction', 'POST', [ |
|
|
|
|
382
|
|
|
'tx-name' => $txname, |
383
|
|
|
]); |
384
|
|
|
|
385
|
|
|
// return Result |
386
|
|
|
return $result; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* This method, compose-chain, will return the appropriate api calls to create a chain in factom. |
391
|
|
|
* |
392
|
|
|
* @url https://docs.factom.com/api#compose-chain |
393
|
|
|
* |
394
|
|
|
* @return json { object ... } |
395
|
|
|
*/ |
396
|
|
|
public function composeChain(array $extids, string $content, string $ecpub) |
397
|
|
|
{ |
398
|
|
|
$result = $this->callEndpoint('compose-chain', 'POST', [ |
|
|
|
|
399
|
|
|
'chain' => [ |
400
|
|
|
'firstentry' => [ |
401
|
|
|
'extids' => $extids, |
402
|
|
|
'content' => $content, |
403
|
|
|
], |
404
|
|
|
], |
405
|
|
|
'ecpub' => $ecpub, |
406
|
|
|
]); |
407
|
|
|
|
408
|
|
|
// return Result |
409
|
|
|
return $result; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* This method, compose-entry, will return the appropriate api calls to create a entry in factom. |
414
|
|
|
* |
415
|
|
|
* @url https://docs.factom.com/api#compose-entry |
416
|
|
|
* |
417
|
|
|
* @return json { object ... } |
418
|
|
|
*/ |
419
|
|
|
public function composeEntry(string $chainid, array $extids, string $content, string $ecpub) |
420
|
|
|
{ |
421
|
|
|
$result = $this->callEndpoint('compose-entry', 'POST', [ |
|
|
|
|
422
|
|
|
'entry' => [ |
423
|
|
|
'chainid' => $chainid, |
424
|
|
|
'extids' => $extids, |
425
|
|
|
'content' => $content, |
426
|
|
|
], |
427
|
|
|
'ecpub' => $ecpub, |
428
|
|
|
]); |
429
|
|
|
|
430
|
|
|
// return Result |
431
|
|
|
return $result; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Retrieve current properties of factom-walletd, including the wallet and wallet API versions. |
436
|
|
|
* |
437
|
|
|
* @url https://docs.factom.com/api#properties |
438
|
|
|
* |
439
|
|
|
* @return json { string walletversion, string walletapiversion } |
440
|
|
|
*/ |
441
|
|
|
public function properties() |
442
|
|
|
{ |
443
|
|
|
$result = $this->callEndpoint('properties', 'POST'); |
|
|
|
|
444
|
|
|
|
445
|
|
|
// return Result |
446
|
|
|
return $result; |
447
|
|
|
} |
448
|
|
|
} |
449
|
|
|
|