1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AdrianMejias\FactomApi; |
4
|
|
|
|
5
|
|
|
class FactomApi extends FactomConnector |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Every directory block has a KeyMR (Key Merkle Root), which can be used to retrieve it. |
9
|
|
|
* |
10
|
|
|
* @url https://docs.factom.com/api#directory-block |
11
|
|
|
* |
12
|
|
|
* @return json { object header, object entryblocklist } |
13
|
|
|
*/ |
14
|
|
|
public function directoryBlock(string $keymr) |
15
|
|
|
{ |
16
|
|
|
$result = $this->callEndpoint('directory-block', 'POST', [ |
|
|
|
|
17
|
|
|
'KeyMR' => $keymr, |
18
|
|
|
]); |
19
|
|
|
|
20
|
|
|
// return Result |
21
|
|
|
return $result; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The directory block head is the last known directory block by factom, or in other words, the |
26
|
|
|
* most recently recorded block. |
27
|
|
|
* |
28
|
|
|
* @url https://docs.factom.com/api#directory-block-head |
29
|
|
|
* |
30
|
|
|
* @return json { string keymr } |
31
|
|
|
*/ |
32
|
|
|
public function directoryBlockHead() |
33
|
|
|
{ |
34
|
|
|
$result = $this->callEndpoint('directory-block-head', 'POST'); |
|
|
|
|
35
|
|
|
|
36
|
|
|
// return Result |
37
|
|
|
return $result; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns various heights that allows you to view the state of the blockchain. |
42
|
|
|
* |
43
|
|
|
* @url https://docs.factom.com/api#heights |
44
|
|
|
* |
45
|
|
|
* @return json { ... } |
46
|
|
|
*/ |
47
|
|
|
public function heights() |
48
|
|
|
{ |
49
|
|
|
$result = $this->callEndpoint('heights', 'POST'); |
|
|
|
|
50
|
|
|
|
51
|
|
|
// return Result |
52
|
|
|
return $result; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Retrieve an entry or transaction in raw format, the data is a hex encoded string. |
57
|
|
|
* |
58
|
|
|
* @url https://docs.factom.com/api#raw-data |
59
|
|
|
* |
60
|
|
|
* @return json { string data } |
61
|
|
|
*/ |
62
|
|
|
public function rawData(string $hash) |
63
|
|
|
{ |
64
|
|
|
$result = $this->callEndpoint('raw-data', 'POST', [ |
|
|
|
|
65
|
|
|
'hash' => $hash, |
66
|
|
|
]); |
67
|
|
|
|
68
|
|
|
// return Result |
69
|
|
|
return $result; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Retrieve a directory block given only its height. |
74
|
|
|
* |
75
|
|
|
* @url https://docs.factom.com/api#dblock-by-height |
76
|
|
|
* |
77
|
|
|
* @return json { object dblock, string rawdata } |
78
|
|
|
*/ |
79
|
|
|
public function dblockByHeight(int $height) |
80
|
|
|
{ |
81
|
|
|
$result = $this->callEndpoint('dblock-by-height', 'POST', [ |
|
|
|
|
82
|
|
|
'height' => $height, |
83
|
|
|
]); |
84
|
|
|
|
85
|
|
|
// return Result |
86
|
|
|
return $result; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Retrieve administrative blocks for any given height. |
91
|
|
|
* |
92
|
|
|
* @url https://docs.factom.com/api#ablock-by-height |
93
|
|
|
* |
94
|
|
|
* @return json { object ablock, string rawdata } |
95
|
|
|
*/ |
96
|
|
|
public function ablockByHeight(int $height) |
97
|
|
|
{ |
98
|
|
|
$result = $this->callEndpoint('ablock-by-height', 'POST', [ |
|
|
|
|
99
|
|
|
'height' => $height, |
100
|
|
|
]); |
101
|
|
|
|
102
|
|
|
// return Result |
103
|
|
|
return $result; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Retrieve the entry credit block for any given height. |
108
|
|
|
* |
109
|
|
|
* @url https://docs.factom.com/api#ecblock-by-height |
110
|
|
|
* |
111
|
|
|
* @return json { object ecblock, string rawdata } |
112
|
|
|
*/ |
113
|
|
|
public function ecblockByHeight(int $height) |
114
|
|
|
{ |
115
|
|
|
$result = $this->callEndpoint('ecblock-by-height', 'POST', [ |
|
|
|
|
116
|
|
|
'height' => $height, |
117
|
|
|
]); |
118
|
|
|
|
119
|
|
|
// return Result |
120
|
|
|
return $result; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Retrieve the factoid block for any given height. |
125
|
|
|
* |
126
|
|
|
* @url https://docs.factom.com/api#fblock-by-height |
127
|
|
|
* |
128
|
|
|
* @return json { object fblock, string rawdata } |
129
|
|
|
*/ |
130
|
|
|
public function fblockByHeight(int $height) |
131
|
|
|
{ |
132
|
|
|
$result = $this->callEndpoint('fblock-by-height', 'POST', [ |
|
|
|
|
133
|
|
|
'height' => $height, |
134
|
|
|
]); |
135
|
|
|
|
136
|
|
|
// return Result |
137
|
|
|
return $result; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Retrieve a specified factoid block given its merkle root key. |
142
|
|
|
* |
143
|
|
|
* @url https://docs.factom.com/api#factoid-block |
144
|
|
|
* |
145
|
|
|
* @return json { object fblock, string rawdata } |
146
|
|
|
*/ |
147
|
|
|
public function factoidBlock(string $keymr) |
148
|
|
|
{ |
149
|
|
|
$result = $this->callEndpoint('factoid-block', 'POST', [ |
|
|
|
|
150
|
|
|
'KeyMR' => $keymr, |
151
|
|
|
]); |
152
|
|
|
|
153
|
|
|
// return Result |
154
|
|
|
return $result; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Retrieve a specified entrycredit block given its merkle root key. |
159
|
|
|
* |
160
|
|
|
* @url https://docs.factom.com/api#entrycredit-block |
161
|
|
|
* |
162
|
|
|
* @return json { object ecblock, string rawdata } |
163
|
|
|
*/ |
164
|
|
|
public function entrycreditBlock(string $keymr) |
165
|
|
|
{ |
166
|
|
|
$result = $this->callEndpoint('entrycredit-block', 'POST', [ |
|
|
|
|
167
|
|
|
'KeyMR' => $keymr, |
168
|
|
|
]); |
169
|
|
|
|
170
|
|
|
// return Result |
171
|
|
|
return $result; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Retrieve a specified admin block given its merkle root key. |
176
|
|
|
* |
177
|
|
|
* @url https://docs.factom.com/api#admin-block |
178
|
|
|
* |
179
|
|
|
* @return json { object ablock, string rawdata } |
180
|
|
|
*/ |
181
|
|
|
public function adminBlock(string $keymr) |
182
|
|
|
{ |
183
|
|
|
$result = $this->callEndpoint('admin-block', 'POST', [ |
|
|
|
|
184
|
|
|
'KeyMR' => $keymr, |
185
|
|
|
]); |
186
|
|
|
|
187
|
|
|
// return Result |
188
|
|
|
return $result; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Retrieve a specified entry block given its merkle root key. |
193
|
|
|
* |
194
|
|
|
* @url https://docs.factom.com/api#entry-block |
195
|
|
|
* |
196
|
|
|
* @return json { object header, object entrylist } |
197
|
|
|
*/ |
198
|
|
|
public function entryBlock(string $keymr) |
199
|
|
|
{ |
200
|
|
|
$result = $this->callEndpoint('entry-block', 'POST', [ |
|
|
|
|
201
|
|
|
'KeyMR' => $keymr, |
202
|
|
|
]); |
203
|
|
|
|
204
|
|
|
// return Result |
205
|
|
|
return $result; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Get an Entry from factomd specified by the Entry Hash. |
210
|
|
|
* |
211
|
|
|
* @url https://docs.factom.com/api#entry |
212
|
|
|
* |
213
|
|
|
* @return json { string chainid, string content, array extids } |
214
|
|
|
*/ |
215
|
|
|
public function entry(string $hash) |
216
|
|
|
{ |
217
|
|
|
$result = $this->callEndpoint('entry', 'POST', [ |
|
|
|
|
218
|
|
|
'Hash' => $hash, |
219
|
|
|
]); |
220
|
|
|
|
221
|
|
|
// return Result |
222
|
|
|
return $result; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Returns an array of the entries that have been submitted but have not been recoreded into the blockchain. |
227
|
|
|
* |
228
|
|
|
* @url https://docs.factom.com/api#pending-entries |
229
|
|
|
* |
230
|
|
|
* @return json { array ... } |
231
|
|
|
*/ |
232
|
|
|
public function pendingEntries() |
233
|
|
|
{ |
234
|
|
|
$result = $this->callEndpoint('pending-entries', 'POST'); |
|
|
|
|
235
|
|
|
|
236
|
|
|
// return Result |
237
|
|
|
return $result; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Retrieve details of a factoid transaction using a transactions hash. |
242
|
|
|
* |
243
|
|
|
* @url https://docs.factom.com/api#transaction |
244
|
|
|
* |
245
|
|
|
* @return json { object ... } |
246
|
|
|
*/ |
247
|
|
|
public function transaction(string $hash) |
248
|
|
|
{ |
249
|
|
|
$result = $this->callEndpoint('transaction', 'POST', [ |
|
|
|
|
250
|
|
|
'hash' => $hash, |
251
|
|
|
]); |
252
|
|
|
|
253
|
|
|
// return Result |
254
|
|
|
return $result; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* This api call is used to find the status of a transaction, whether it be a factoid, reveal entry, or commit entry. |
259
|
|
|
* |
260
|
|
|
* @url https://docs.factom.com/api#ack |
261
|
|
|
* |
262
|
|
|
* @return json { object ... } |
263
|
|
|
*/ |
264
|
|
|
public function ack(string $hash, string $chainid, string $fulltransaction = null) |
265
|
|
|
{ |
266
|
|
|
$result = $this->callEndpoint('ack', 'POST', [ |
|
|
|
|
267
|
|
|
'hash' => $hash, |
268
|
|
|
'chainid' => $chainid, |
269
|
|
|
'fulltransaction' => $fulltransaction, |
270
|
|
|
]); |
271
|
|
|
|
272
|
|
|
// return Result |
273
|
|
|
return $result; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Factoid Acknowledgements will give the current status of a transaction. |
278
|
|
|
* |
279
|
|
|
* @status Depricated - please refer to ack. |
280
|
|
|
* |
281
|
|
|
* @url https://docs.factom.com/api#factoid-ack |
282
|
|
|
* |
283
|
|
|
* @return json { object ... } |
284
|
|
|
*/ |
285
|
|
|
public function factoidAck(string $txid) |
286
|
|
|
{ |
287
|
|
|
$result = $this->callEndpoint('factoid-ack', 'POST', [ |
|
|
|
|
288
|
|
|
'TxID' => $txid, |
289
|
|
|
]); |
290
|
|
|
|
291
|
|
|
// return Result |
292
|
|
|
return $result; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* Entry Acknowledgements will give the current status of a transaction. |
297
|
|
|
* |
298
|
|
|
* @status Depricated - please refer to ack. |
299
|
|
|
* |
300
|
|
|
* @url https://docs.factom.com/api#factoid-ack |
301
|
|
|
* |
302
|
|
|
* @return json { object ... } |
303
|
|
|
*/ |
304
|
|
|
public function entryAck(string $txid) |
305
|
|
|
{ |
306
|
|
|
$result = $this->callEndpoint('entry-ack', 'POST', [ |
|
|
|
|
307
|
|
|
'TxID' => $txid, |
308
|
|
|
]); |
309
|
|
|
|
310
|
|
|
// return Result |
311
|
|
|
return $result; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Retrieve a reciept providing cryptographially verfiable proof that information was |
316
|
|
|
* recorded in the factom blockchain and that this was subsequently anchored in the |
317
|
|
|
* bitcoin blockchain. |
318
|
|
|
* |
319
|
|
|
* @url https://docs.factom.com/api#receipt |
320
|
|
|
* |
321
|
|
|
* @return json { object ... } |
322
|
|
|
*/ |
323
|
|
|
public function receipt(string $hash) |
324
|
|
|
{ |
325
|
|
|
$result = $this->callEndpoint('receipt', 'POST', [ |
|
|
|
|
326
|
|
|
'hash' => $hash, |
327
|
|
|
]); |
328
|
|
|
|
329
|
|
|
// return Result |
330
|
|
|
return $result; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Returns an array of factoid transactions that have not yet been recorded in the blockchain, |
335
|
|
|
* but are known to the system. |
336
|
|
|
* |
337
|
|
|
* @url https://docs.factom.com/api#pending-transactions |
338
|
|
|
* |
339
|
|
|
* @return json { string TransactionID, string Status } |
340
|
|
|
*/ |
341
|
|
|
public function pendingTransactions(string $address) |
342
|
|
|
{ |
343
|
|
|
$result = $this->callEndpoint('pending-transactions', 'POST', [ |
|
|
|
|
344
|
|
|
'Address' => $address, |
345
|
|
|
]); |
346
|
|
|
|
347
|
|
|
// return Result |
348
|
|
|
return $result; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* Return the keymr of the head of the chain for a chain ID |
353
|
|
|
* (the unique hash created when the chain was created). |
354
|
|
|
* |
355
|
|
|
* @url https://docs.factom.com/api#chain-head |
356
|
|
|
* |
357
|
|
|
* @return json { string ChainHead } |
358
|
|
|
*/ |
359
|
|
|
public function chainHead(string $chainid) |
360
|
|
|
{ |
361
|
|
|
$result = $this->callEndpoint('chain-head', 'POST', [ |
|
|
|
|
362
|
|
|
'ChainID' => $chainid, |
363
|
|
|
]); |
364
|
|
|
|
365
|
|
|
// return Result |
366
|
|
|
return $result; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Return its current balance for a specific entry credit address. |
371
|
|
|
* |
372
|
|
|
* @url https://docs.factom.com/api#entry-credit-balance |
373
|
|
|
* |
374
|
|
|
* @return json { int balance } |
375
|
|
|
*/ |
376
|
|
|
public function entryCreditBalance(string $address) |
377
|
|
|
{ |
378
|
|
|
$result = $this->callEndpoint('entry-credit-balance', 'POST', [ |
|
|
|
|
379
|
|
|
'address' => $address, |
380
|
|
|
]); |
381
|
|
|
|
382
|
|
|
// return Result |
383
|
|
|
return $result; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* This call returns the number of Factoshis (Factoids *10^-8) that are currently |
388
|
|
|
* available at the address specified. |
389
|
|
|
* |
390
|
|
|
* @url https://docs.factom.com/api#factoid-balance |
391
|
|
|
* |
392
|
|
|
* @return json { int balance } |
393
|
|
|
*/ |
394
|
|
|
public function factoidBalance(string $address) |
395
|
|
|
{ |
396
|
|
|
$result = $this->callEndpoint('factoid-balance', 'POST', [ |
|
|
|
|
397
|
|
|
'address' => $address, |
398
|
|
|
]); |
399
|
|
|
|
400
|
|
|
// return Result |
401
|
|
|
return $result; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* Returns the number of Factoshis (Factoids *10^-8) that purchase a single Entry Credit. |
406
|
|
|
* |
407
|
|
|
* @url https://docs.factom.com/api#entry-credit-rate |
408
|
|
|
* |
409
|
|
|
* @return json { int rate } |
410
|
|
|
*/ |
411
|
|
|
public function entryCreditRate() |
412
|
|
|
{ |
413
|
|
|
$result = $this->callEndpoint('entry-credit-rate', 'POST'); |
|
|
|
|
414
|
|
|
|
415
|
|
|
// return Result |
416
|
|
|
return $result; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* Retrieve current properties of the Factom system, including the software and the API versions. |
421
|
|
|
* |
422
|
|
|
* @url https://docs.factom.com/api#properties |
423
|
|
|
* |
424
|
|
|
* @return json { string factomdversion, string factomdapiversion } |
425
|
|
|
*/ |
426
|
|
|
public function properties() |
427
|
|
|
{ |
428
|
|
|
$result = $this->callEndpoint('properties', 'POST'); |
|
|
|
|
429
|
|
|
|
430
|
|
|
// return Result |
431
|
|
|
return $result; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Submit a factoid transaction. |
436
|
|
|
* |
437
|
|
|
* @url https://docs.factom.com/api#factoid-submit |
438
|
|
|
* |
439
|
|
|
* @return json { string message, string txid } |
440
|
|
|
*/ |
441
|
|
|
public function factoidSubmit(string $transaction) |
442
|
|
|
{ |
443
|
|
|
$result = $this->callEndpoint('factoid-submit', 'POST', [ |
|
|
|
|
444
|
|
|
'transaction' => $transaction, |
445
|
|
|
]); |
446
|
|
|
|
447
|
|
|
// return Result |
448
|
|
|
return $result; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* Send a Chain Commit Message to factomd to create a new Chain. |
453
|
|
|
* |
454
|
|
|
* @url https://docs.factom.com/api#commit-chain |
455
|
|
|
* |
456
|
|
|
* @return json { string message, string txid, string entryhash, string chainid } |
457
|
|
|
*/ |
458
|
|
|
public function commitChain(string $message) |
459
|
|
|
{ |
460
|
|
|
$result = $this->callEndpoint('commit-chain', 'POST', [ |
|
|
|
|
461
|
|
|
'message' => $message, |
462
|
|
|
]); |
463
|
|
|
|
464
|
|
|
// return Result |
465
|
|
|
return $result; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* Reveal the First Entry in a Chain to factomd after the Commit to compleate the Chain creation. |
470
|
|
|
* |
471
|
|
|
* @url https://docs.factom.com/api#reveal-chain |
472
|
|
|
* |
473
|
|
|
* @return json { string message, string txid, string entryhash, string chainid } |
474
|
|
|
*/ |
475
|
|
|
public function revealChain(string $entry) |
476
|
|
|
{ |
477
|
|
|
$result = $this->callEndpoint('reveal-chain', 'POST', [ |
|
|
|
|
478
|
|
|
'entry' => $entry, |
479
|
|
|
]); |
480
|
|
|
|
481
|
|
|
// return Result |
482
|
|
|
return $result; |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
/** |
486
|
|
|
* Send an Entry Commit Message to factom to create a new Entry. |
487
|
|
|
* |
488
|
|
|
* @url https://docs.factom.com/api#commit-entry |
489
|
|
|
* |
490
|
|
|
* @return json { string message, string txid, string entryhash } |
491
|
|
|
*/ |
492
|
|
|
public function commitEntry(string $message) |
493
|
|
|
{ |
494
|
|
|
$result = $this->callEndpoint('commit-entry', 'POST', [ |
|
|
|
|
495
|
|
|
'message' => $message, |
496
|
|
|
]); |
497
|
|
|
|
498
|
|
|
// return Result |
499
|
|
|
return $result; |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
/** |
503
|
|
|
* Reveal an Entry to factomd after the Commit to compleate the Entry creation. |
504
|
|
|
* |
505
|
|
|
* @url https://docs.factom.com/api#reveal-entry |
506
|
|
|
* |
507
|
|
|
* @return json { string message, string txid, string entryhash, string chainid } |
508
|
|
|
*/ |
509
|
|
|
public function revealEntry(string $entry) |
510
|
|
|
{ |
511
|
|
|
$result = $this->callEndpoint('reveal-entry', 'POST', [ |
|
|
|
|
512
|
|
|
'entry' => $entry, |
513
|
|
|
]); |
514
|
|
|
|
515
|
|
|
// return Result |
516
|
|
|
return $result; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Send a raw hex encoded binary message to the Factom network. |
521
|
|
|
* |
522
|
|
|
* @url https://docs.factom.com/api#send-raw-message |
523
|
|
|
* |
524
|
|
|
* @return json { string message } |
525
|
|
|
*/ |
526
|
|
|
public function sendRawMessage(string $message) |
527
|
|
|
{ |
528
|
|
|
$result = $this->callEndpoint('send-raw-message', 'POST', [ |
|
|
|
|
529
|
|
|
'message' => $message, |
530
|
|
|
]); |
531
|
|
|
|
532
|
|
|
// return Result |
533
|
|
|
return $result; |
534
|
|
|
} |
535
|
|
|
} |
536
|
|
|
|