Skip to content

Commit 590c83b

Browse files
authored
Merge pull request #54 from assafY/upgrade-client
Upgrade client
2 parents f143b8f + 6a4175f commit 590c83b

19 files changed

+496
-169
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ An official PHP library for interacting with the blockchain.info API.
77
Getting Started
88
---------------
99

10-
Download the source or clone the repository. This php library works with the [Composer](https://getcomposer.org/) package manager. Navigate to the root of the repository and run
10+
Download the source or clone the repository. This php library works with the [Composer](https://getcomposer.org/) package manager. Navigate to the root of the repository and run
1111

1212
```
1313
$ composer install
1414
```
1515

16-
This will create the `/vendor` folder in the repository root.
16+
This will create the `/vendor` folder in the repository root.
1717

1818
In order to use Wallet and CreateWallet functionality, you must provide an URL to an instance of [service-my-wallet-v3](https://github.com/blockchain/service-my-wallet-v3).
1919
Before using these functionalities, call \Blockchain\Blockchain::setServiceUrl to set the URL to the instance of of [service-my-wallet-v3](https://github.com/blockchain/service-my-wallet-v3).
@@ -30,9 +30,9 @@ $Blockchain = new \Blockchain\Blockchain();
3030
$Blockchain->setServiceUrl('http://localhost:3000');
3131
```
3232

33-
All functionality is provided through the `Blockchain` object.
33+
All functionality is provided through the `Blockchain` object.
3434

35-
###Call Limits
35+
### Call Limits
3636

3737
The [official documentation](https://blockchain.info/api) lists API call limits, which may be bypassed with an API code. If you use a code, enter it when you create the `Blockchain` object:
3838

@@ -42,7 +42,7 @@ $Blockchain = new \Blockchain\Blockchain('http://localhost:3000', $my_api_code);
4242

4343
If you need an API code, you may request one [here](https://blockchain.info/api/api_create_code).
4444

45-
###Network Timeouts
45+
### Network Timeouts
4646

4747
Set the `cURL` timeout, in seconds, with the `setTimeout` member function:
4848

@@ -58,25 +58,25 @@ A Note about Bitcoin Values
5858

5959
All Bitcoin values returned by the API are in string float format, in order to preserve full value precision. It is recommended that all arithmetic operations performed on Bitcoin values within PHP utilize the `bcmath` functions as follows:
6060

61-
#####`bcadd` Add Two Numbers
61+
##### `bcadd` Add Two Numbers
6262

6363
```php
6464
$result = bcadd("101.234115", "34.92834753", 8); // "136.16246253"
6565
```
6666

67-
#####`bcsub` Subtract Two Numbers
67+
##### `bcsub` Subtract Two Numbers
6868

6969
```php
7070
$result = bcsub("101.234115", "34.92834753", 8); // "66.30576747"
7171
```
7272

73-
#####`bcmul` Multiply Two Numbers
73+
##### `bcmul` Multiply Two Numbers
7474

7575
```php
7676
$result = bcmul("101.234115", "34.92834753", 8); // "3535.940350613"
7777
```
7878

79-
#####`bcdiv` Divide Two Numbers
79+
##### `bcdiv` Divide Two Numbers
8080

8181
```php
8282
$result = bcdiv("101.234115", "34.92834753", 8); // "2.89833679"

docs/blockexplorer.md

Lines changed: 84 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,61 +9,103 @@ $val = $Blockchain->Explorer->someFunc($param);
99
```
1010

1111

12-
###Blocks
12+
### Blocks
1313

1414
Blocks may be queried in multiple ways: by the block hash, by the height in the blockchain, or by the block's index. Calls return `Block` objects. `getBlocksAtHeight` returns an array of `Block` objects.
1515

1616
```php
1717
$block = $Blockchain->Explorer->getBlock($hash);
1818
$blocks = $Blockchain->Explorer->getBlocksAtHeight($height_int);
19-
$block = $Blockchain->Explorer->getBlockByIndex($index_int);
19+
$block = $Blockchain->Explorer->getBlockByIndex($index_int) // deprecated;
2020
```
2121

2222

23-
###Transactions
23+
### Transactions
2424
Get a single transaction based on hash or index. Returns a `Transaction` object.
2525

2626
```php
2727
$tx = $Blockchain->Explorer->getTransaction($hash);
28-
$tx = $Blockchain->Explorer->getTransactionByIndex($index);
28+
$tx = $Blockchain->Explorer->getTransactionByIndex($index) // deprecated;
2929
```
3030

3131

32-
###Addresses
33-
Get the details of an address, including a paged list of transactions. Returns an `Address` object.
32+
### Addresses
33+
Get the details of a Base58Check or Hash160 address, including a paged list of transactions. Returns an `Address` object.
3434

3535
```php
36-
$limit = 50;
37-
$offset = 0;
38-
$address = $Blockchain->Explorer->getAddress($address, $limit, $offset);
36+
/*
37+
* Optional params:
38+
* $limit - max number of transactions to get (default 50, max 50)
39+
* $offset - used to get more than the max possible number of transactions (default 0)
40+
* $filter - filter option when getting transactions (default FilterType::RemoveUnspendable)
41+
*/
42+
43+
/*
44+
* Functions are currently interchangeable but this is liable to change in the future
45+
*/
46+
$address = $Blockchain->Explorer->getHash160Address($address);
47+
$address = $Blockchain->Explorer->getBase58Address($address);
3948
```
4049

4150

42-
###Unspent Outputs
43-
Get an array of `UnspentOutput` objects for a given address.
51+
### xPub
52+
Get summary of an xPub, with its overall balance and transactions. Returns an `Xpub` object.
4453

4554
```php
46-
$unspent = $Blockchain->Explorer->getUnspentOutputs($address);
55+
/*
56+
* Optional params:
57+
* $limit - max number of transactions to get (default 100, max 100)
58+
* $offset - used to get more than the max possible number of transactions (default 0)
59+
* $filter - filter option when getting transactions (default FilterType::RemoveUnspendable)
60+
*/
61+
$xpub_summary = $Blockchain->Explorer->getXpub($xpub);
4762
```
4863

4964

50-
###Latest Block
65+
### MultiAddress
66+
Get data for an array Base58Check and / or xPub addresses. Returns a `MultiAddress` object.
67+
68+
```php
69+
/*
70+
* Optional params:
71+
* $limit - max number of transactions to get (default 100, max 100)
72+
* $offset - used to get more than the max possible number of transactions (default 0)
73+
* $filter - filter option when getting transactions (default FilterType::RemoveUnspendable)
74+
*/
75+
$multi_addr = $Blockchain->Explorer.getMultiAddress(array($addr1, $addr2, $addr3))
76+
```
77+
78+
79+
### Unspent Outputs
80+
Get an array of `UnspentOutput` objects for an array of addresses.
81+
82+
```php
83+
/*
84+
* Optional params:
85+
* $confirmations - show transactions with minimum number of confirmations (default 0)
86+
* $limit - max number of transactions to get (default 100, max 100)
87+
*/
88+
$unspent = $Blockchain->Explorer->getUnspentOutputs(array($addr1, $addr2, $addr3));
89+
```
90+
91+
92+
### Latest Block
5193
Get the latest block on the main chain. Returns a simpler `LatestBlock` object;
5294

5395
```php
5496
$latest = $Blockchain->Explorer->getLatestBlock();
5597
```
5698

5799

58-
###Unconfirmed Transactions
100+
### Unconfirmed Transactions
59101
Get a list of unconfirmed transactions. Returns an array of `Transaction` objects.
60102

61103
```php
62104
$unconfirmed = $Blockchain->Explorer->getUnconfirmedTransactions();
63105
```
64106

65107

66-
###Simple Blocks
108+
### Simple Blocks
67109
Get blocks from a particular day or from a given mining pool. Return arrays of `SimpleBlock` objects.
68110

69111
```php
@@ -73,20 +115,12 @@ $simple_blocks = $Blockchain->Explorer->getBlocksByPool($pool_name);
73115
For a list of mining pool names, visit [this page](https://blockchain.info/pools).
74116

75117

76-
###Inventory Data
77-
Gets data for recent blockchain entities, up to one hour old. Returns an `InventoryData` object.
78-
79-
```php
80-
$data = $Blockchain->Explorer->getInventoryData($hash);
81-
```
82-
83-
84-
Return Objects
85-
--------------
118+
Response Object Properties
119+
--------------------------
86120

87121
Calls to the API return first-class objects.
88122

89-
###Block
123+
### Block
90124

91125
```php
92126
class Block {
@@ -109,7 +143,7 @@ class Block {
109143
}
110144
```
111145

112-
###Transaction
146+
### Transaction
113147
```php
114148
class Transaction {
115149
public $double_spend = false; // bool
@@ -132,7 +166,7 @@ class Input {
132166
public $sequence; // int
133167
public $script_sig; // string
134168
public $coinbase = true; // bool
135-
169+
136170
// If coinbase is false, then the following fields are created
137171
public $n; // int
138172
public $value; // string, e.g. "12.64952835"
@@ -145,6 +179,14 @@ class Input {
145179
}
146180
```
147181

182+
### MultiAddress
183+
```php
184+
class MultiAddress {
185+
public $addresses // Array of Address objects
186+
public $transactions // Array of Transaction objects
187+
}
188+
```
189+
148190
### Output
149191
```php
150192
class Output {
@@ -170,6 +212,15 @@ class Address {
170212
}
171213
```
172214

215+
### Xpub
216+
```php
217+
class Xpub extends Address {
218+
public $change_index // int
219+
public $account_index // int
220+
public $gap_limit // int
221+
}
222+
```
223+
173224
### UnspentOutput
174225
```php
175226
class UnspentOutput {
@@ -205,15 +256,11 @@ class SimpleBlock {
205256
}
206257
```
207258

208-
### InventoryData
259+
### FilterType
209260
```php
210-
class InventoryData {
211-
public $hash; // string
212-
public $type; // string
213-
public $initial_time; // int
214-
public $initial_ip; // string
215-
public $nconnected; // int
216-
public $relayed_count; // int
217-
public $relayed_percent; // int
261+
class FilterType {
262+
const All = 4;
263+
const ConfirmedOnly = 5;
264+
const RemoveUnspendable = 6;
218265
}
219266
```

docs/create.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,30 @@ There are two ways to create wallets: provide an existing private key or let Blo
1919

2020
Please read the [offical documentation](https://blockchain.info/api/create_wallet) for important details.
2121

22-
###Create with Key
22+
### Create with Key
2323
Create a new wallet with a known private key. Returns a `WalletResponse` object.
2424

2525
```php
2626
$wallet = $Blockchain->Create->createWithKey($password, $privKey, $email=null, $label=null);
2727
```
2828

29-
###Create without Key
29+
### Create without Key
3030
Create a new wallet, letting Blockchain generate a new private key. Returns a `WalletResponse` object.
3131

3232
```php
3333
$wallet = $Blockchain->Create->create($password, $email=null, $label=null);
3434
```
3535

36-
###WalletResponse
36+
Response Object Properties
37+
--------------------------
38+
39+
### WalletResponse
3740
The `WalletResponse` object contains fields for the wallet identifier (`guid`), the `address` for receiving Bitcoin, and a `label` for the first account of the wallet.
3841

3942
```php
4043
class WalletResponse {
4144
public $guid; // string
4245
public $address; // string
43-
public $label; // string
46+
public $label; // string
4447
}
4548
```

docs/rates.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ Get the amount of Bitcoin that could be purchased for a given fiat amount. Retur
1717
$btc_amount = $Blockchain->Rates->toBTC(500, 'USD');
1818
```
1919

20+
Convert Bitcoin to Fiat Currency
21+
--------------------------------
22+
Get the amount of a given fiat currency for a given bitcoin amount (in satoshi). Returns a `float`.
23+
24+
```php
25+
/*
26+
* Optional param:
27+
* $symbol - the fiat currency to convert to ('USD' by default)
28+
*/
29+
$one_btc_in_usd = $Blockchain->Rates->fromBTC(100000000);
30+
```
2031

2132
Get Rates
2233
---------
@@ -29,7 +40,10 @@ $rates = $Blockchain->Rates->get();
2940
foreach($rates as $cur=>$ticker) { ... }
3041
```
3142

32-
###Ticker
43+
Response Object Properties
44+
--------------------------
45+
46+
### Ticker
3347

3448
```php
3549
class Ticker {

0 commit comments

Comments
 (0)