Skip to content

Commit c467503

Browse files
committed
Updated README.
1 parent b00f751 commit c467503

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

README.md

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Run ```php composer.phar require denpa/php-bitcoinrpc``` in your project directory or add following lines to composer.json
77
```javascript
88
"require": {
9-
"denpa/php-bitcoinrpc": "^1.0"
9+
"denpa/php-bitcoinrpc": "^2.0"
1010
}
1111
```
1212
and run ```php composer.phar update```.
@@ -36,37 +36,68 @@ $bitcoind = new BitcoinClient([
3636
```
3737
Then call methods defined in [Bitcoin Core API Documentation](https://bitcoin.org/en/developer-reference#bitcoin-core-apis) with magic:
3838
```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
4051
```
4152
To send asynchronous request, add Async to method name:
4253
```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+
//
4760
},
48-
function ($exception) {
49-
//
61+
function (\Exception $exception) {
62+
//
5063
}
5164
);
65+
66+
$promise->wait();
5267
```
5368

5469
You can also send requests using request method:
5570
```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+
5784
```
5885
or requestAsync method for asynchronous calls:
5986
```php
60-
$bitcoind->requestAsync(
61-
'getBlock',
87+
use Denpa\Bitcoin\BitcoindResponse;
88+
89+
$promise = $bitcoind->requestAsync(
90+
'getBlock',
6291
'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
63-
function ($success) {
64-
//
92+
function (BitcoindResponse $success) {
93+
//
6594
},
66-
function ($exception) {
67-
//
95+
function (\Exception $exception) {
96+
//
6897
}
6998
);
99+
100+
$promise->wait();
70101
```
71102

72103
## License

0 commit comments

Comments
 (0)