|
6 | 6 | Run ```php composer.phar require denpa/php-bitcoinrpc``` in your project directory or add following lines to composer.json |
7 | 7 | ```javascript |
8 | 8 | "require": { |
9 | | - "denpa/php-bitcoinrpc": "^1.0" |
| 9 | + "denpa/php-bitcoinrpc": "^2.0" |
10 | 10 | } |
11 | 11 | ``` |
12 | 12 | and run ```php composer.phar update```. |
@@ -36,37 +36,68 @@ $bitcoind = new BitcoinClient([ |
36 | 36 | ``` |
37 | 37 | Then call methods defined in [Bitcoin Core API Documentation](https://bitcoin.org/en/developer-reference#bitcoin-core-apis) with magic: |
38 | 38 | ```php |
39 | | -$bitcoind->getBlock('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'); |
| 39 | +$block = $bitcoind->getBlock('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'); |
| 40 | + |
| 41 | +$block('hash'); // 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f |
| 42 | +$block['height']; // 0 (array access) |
| 43 | +$block->get('tx.0'); // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b |
| 44 | +$block->count('tx'); // 1 |
| 45 | +$block->has('version'); // key must exist and CAN NOT be null |
| 46 | +$block->exists('version'); // key must exist and CAN be null |
| 47 | +$block->contains(0); // check if response contains value |
| 48 | +$block->values(); // array of values |
| 49 | +$block->keys(); // array of keys |
| 50 | +$block->random(1, 'tx'); // random block txid |
40 | 51 | ``` |
41 | 52 | To send asynchronous request, add Async to method name: |
42 | 53 | ```php |
43 | | -$bitcoind->getBlockAsync( |
44 | | - '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f', |
45 | | - function ($success) { |
46 | | - // |
| 54 | +use Denpa\Bitcoin\BitcoindResponse; |
| 55 | + |
| 56 | +$promise = $bitcoind->getBlockAsync( |
| 57 | + '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f', |
| 58 | + function (BitcoindResponse $success) { |
| 59 | + // |
47 | 60 | }, |
48 | | - function ($exception) { |
49 | | - // |
| 61 | + function (\Exception $exception) { |
| 62 | + // |
50 | 63 | } |
51 | 64 | ); |
| 65 | + |
| 66 | +$promise->wait(); |
52 | 67 | ``` |
53 | 68 |
|
54 | 69 | You can also send requests using request method: |
55 | 70 | ```php |
56 | | -$bitcoind->request('getBlock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'); |
| 71 | +$block = $bitcoind->request('getBlock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'); |
| 72 | + |
| 73 | +$block('hash'); // 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f |
| 74 | +$block['height']; // 0 (array access) |
| 75 | +$block->get('tx.0'); // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b |
| 76 | +$block->count('tx'); // 1 |
| 77 | +$block->has('version'); // key must exist and CAN NOT be null |
| 78 | +$block->exists('version'); // key must exist and CAN be null |
| 79 | +$block->contains(0); // check if response contains value |
| 80 | +$block->values(); // get response values |
| 81 | +$block->keys(); // get response keys |
| 82 | +$block->random(1, 'tx'); // get random txid |
| 83 | + |
57 | 84 | ``` |
58 | 85 | or requestAsync method for asynchronous calls: |
59 | 86 | ```php |
60 | | -$bitcoind->requestAsync( |
61 | | - 'getBlock', |
| 87 | +use Denpa\Bitcoin\BitcoindResponse; |
| 88 | + |
| 89 | +$promise = $bitcoind->requestAsync( |
| 90 | + 'getBlock', |
62 | 91 | '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f', |
63 | | - function ($success) { |
64 | | - // |
| 92 | + function (BitcoindResponse $success) { |
| 93 | + // |
65 | 94 | }, |
66 | | - function ($exception) { |
67 | | - // |
| 95 | + function (\Exception $exception) { |
| 96 | + // |
68 | 97 | } |
69 | 98 | ); |
| 99 | + |
| 100 | +$promise->wait(); |
70 | 101 | ``` |
71 | 102 |
|
72 | 103 | ## License |
|
0 commit comments