blockchain 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -6
- data/Rakefile +6 -7
- data/blockchain.gemspec +1 -3
- data/docs/blockexplorer.md +235 -64
- data/docs/createwallet.md +32 -15
- data/docs/exchangerates.md +42 -17
- data/docs/pushtx.md +17 -11
- data/docs/receive.md +49 -22
- data/docs/statistics.md +71 -8
- data/docs/wallet.md +61 -79
- data/lib/blockchain.rb +1 -0
- data/lib/blockchain/blockexplorer.rb +195 -91
- data/lib/blockchain/client.rb +56 -0
- data/lib/blockchain/createwallet.rb +34 -19
- data/lib/blockchain/exchangerates.rb +55 -28
- data/lib/blockchain/pushtx.rb +21 -9
- data/lib/blockchain/receive.rb +52 -26
- data/lib/blockchain/statistics.rb +90 -29
- data/lib/blockchain/version.rb +1 -1
- data/lib/blockchain/wallet.rb +39 -42
- data/test/test_block.rb +97 -0
- data/test/test_exchangerates.rb +31 -0
- data/test/test_pushtx.rb +11 -0
- data/test/test_statistics.rb +35 -0
- data/test/test_wallet.rb +44 -0
- metadata +14 -18
- data/lib/blockchain/util.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad92df1e084cfe05666bfc1b54bcde999de70dec
|
4
|
+
data.tar.gz: 2ec38849a086345f5824a654428d38ac4dcbb6e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dc36e728ed3219a0a0c6b72d232932de48a3c6c499faa41e3ac2ef3c57786013c45cf3fa69a7930283c9e0dad976dc256a0b8f229cce0a82dcffa0050266f4f
|
7
|
+
data.tar.gz: 3aa3343bd6f4aeb6ea26e66ba4dc1f064d86e27f221a9334ce35b801d585c1d9cb70e82ade16845bd22f6b5c3d9a61e792e8382941f699f917b099d175cb1394
|
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
#Blockchain API library (Ruby, v1)
|
1
|
+
# Blockchain API library (Ruby, v1)
|
2
2
|
|
3
3
|
An official Ruby gem for interacting with the Blockchain.info API.
|
4
4
|
|
5
|
-
###
|
5
|
+
### Release notes
|
6
|
+
|
7
|
+
This gem was recently updated to support additional functionality of the Blockchain API. As part of this process, the archticture was changed. Rather than calling static methods under the Blockchain module, applications can now create instances of different classes supporting different Blockchain API endpoints. Calling the static methods will still work, but these have been deprecated.
|
8
|
+
|
9
|
+
### Getting started
|
6
10
|
|
7
11
|
Installation via RubyGems:
|
8
12
|
|
@@ -31,20 +35,33 @@ The gem consists of the following functionality:
|
|
31
35
|
|
32
36
|
The main module is called `Blockchain`
|
33
37
|
|
34
|
-
###
|
38
|
+
### The Client class
|
39
|
+
|
40
|
+
Every class instance creates an instance of the client class, which is used to make calls to the API. The client instance will be created with a default base url if none is provided. You can also provide an API code when creating an instance of any class. For example:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'Blockchain'
|
44
|
+
|
45
|
+
# creates a block explorer instance pointing to the default base url, https://blockchain.info/, with no api code
|
46
|
+
explorer = Blockchain::BlockExplorer.new
|
47
|
+
# creates a block explorer pointing to an alternative base url and using an api code
|
48
|
+
explorer = Blockchain::BlockExplorer.new('http://some-other-url.com/', 'api-code')
|
49
|
+
```
|
50
|
+
|
51
|
+
### Error handling
|
35
52
|
|
36
53
|
All functions may raise exceptions caused by incorrectly passed parameters or other problems. If a call is rejected server-side, the `APIException` exception will be raised.
|
37
54
|
|
38
|
-
###Connection timeouts
|
55
|
+
### Connection timeouts
|
39
56
|
|
40
57
|
It is possible to set arbitrary connection timeouts.
|
41
58
|
|
42
59
|
```ruby
|
43
|
-
require '
|
60
|
+
require 'Blockchain'
|
44
61
|
Blockchain::TIMEOUT_SECONDS = 5 #time out after 5 seconds
|
45
62
|
```
|
46
63
|
|
47
|
-
###Request limits and API keys
|
64
|
+
### Request limits and API keys
|
48
65
|
|
49
66
|
In order to prevent abuse some API methods require an API key approved with some basic contact information and a description of its intended use. Please request an API key [here](https://blockchain.info/api/api_create_code).
|
50
67
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
7
|
-
|
8
|
-
task :default => :spec
|
9
|
-
rescue LoadError
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << "test"
|
10
6
|
end
|
7
|
+
|
8
|
+
desc "Running Tests"
|
9
|
+
task :default => :test
|
data/blockchain.gemspec
CHANGED
data/docs/blockexplorer.md
CHANGED
@@ -1,117 +1,288 @@
|
|
1
|
-
|
1
|
+
# Block Explorer functionality
|
2
2
|
|
3
|
-
|
3
|
+
Initialize an instance of the `BlockExplorer` class:
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
```ruby
|
6
|
+
require 'Blockchain'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
# create an instance pointing to https://blockchain.info/ with no api code
|
9
|
+
explorer = Blockchain::BlockExplorer.new
|
10
|
+
|
11
|
+
# create an instance potining to https://blockchain.info/ with an api code
|
12
|
+
explorer = Blockchain::BlockExplorer.new(api_code = 'your-api-code')
|
13
|
+
|
14
|
+
# create an instance pointing to an alternative base url with no api code
|
15
|
+
explorer = Blockchain::BlockExplorer.new('http://some-alternative-url')
|
16
|
+
|
17
|
+
# create an instance pointing to an alternative base url with an api code
|
18
|
+
explorer = Blockchain::BlockExplorer.new('http://some-alternative-url', 'your-api-code')
|
11
19
|
```
|
12
20
|
|
13
|
-
|
14
|
-
|
15
|
-
|
21
|
+
## Methods
|
22
|
+
|
23
|
+
### `get_block_by_index`
|
24
|
+
|
25
|
+
Get a single block based on a block index. Returns a `Block` object. (Deprecated)
|
16
26
|
|
17
|
-
|
27
|
+
##### Params:
|
28
|
+
* `int block_index`
|
29
|
+
|
30
|
+
##### Usage:
|
31
|
+
```ruby
|
32
|
+
explorer.get_block_by_index(1486749)
|
18
33
|
```
|
19
34
|
|
20
|
-
|
21
|
-
|
35
|
+
### `get_block_by_hash`
|
36
|
+
|
37
|
+
Get a single block based on a block hash. Returns a `Block` object.
|
38
|
+
|
39
|
+
##### Params:
|
40
|
+
* `str block_hash`
|
22
41
|
|
23
|
-
|
42
|
+
##### Usage:
|
43
|
+
```ruby
|
44
|
+
explorer.get_block_by_hash('000000000000000016f9a2c3e0f4c1245ff24856a79c34806969f5084f410680')
|
24
45
|
```
|
25
|
-
|
46
|
+
|
47
|
+
### `get_tx_by_index`
|
48
|
+
|
49
|
+
Get a single transaction based on a transaction index. Returns a `Transaction` object. (Deprecated)
|
50
|
+
|
51
|
+
##### Params:
|
52
|
+
* `int tx_index`
|
53
|
+
|
54
|
+
##### Usage:
|
55
|
+
```ruby
|
56
|
+
explorer.get_tx_by_index(243169766)
|
26
57
|
```
|
27
58
|
|
28
|
-
|
59
|
+
### `get_tx_by_hash`
|
60
|
+
|
61
|
+
Get a single transaction based on a transaction hash. Returns a `Transaction` object.
|
62
|
+
|
63
|
+
##### Params:
|
64
|
+
* `str tx_hash`
|
65
|
+
|
66
|
+
##### Usage:
|
29
67
|
```ruby
|
30
|
-
|
68
|
+
explorer.get_tx_by_hash('d4af240386cdacab4ca666d178afc88280b620ae308ae8d2585e9ab8fc664a94')
|
31
69
|
```
|
32
70
|
|
33
|
-
|
71
|
+
### `get_block_height`
|
72
|
+
|
34
73
|
Get an array of blocks at the specified height. Returns an array of `Block` objects.
|
35
74
|
|
36
|
-
Params:
|
37
|
-
|
38
|
-
height : int - block height
|
39
|
-
```
|
75
|
+
##### Params:
|
76
|
+
* `int height`
|
40
77
|
|
41
|
-
Usage:
|
78
|
+
##### Usage:
|
42
79
|
```ruby
|
43
|
-
|
80
|
+
explorer.get_block_height(2570)
|
44
81
|
```
|
45
82
|
|
46
|
-
|
47
|
-
Get
|
83
|
+
---
|
84
|
+
### Get Address
|
48
85
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
86
|
+
The implementations of these methods are currently interchangeable, but this is liable to change in the future. All address methods accept the following optional parameters:
|
87
|
+
|
88
|
+
* `int limit` - the number of transactions to limit the response to (max. 50, default 50 for a single address, max. 100, default 100 for multiple addresses)
|
89
|
+
* `int offset` - skip the first n transactions (default 0). This can be used to get more than the maximum number of transactions
|
90
|
+
* `FilterType filter` - type of filter to use for the query (default FilterType::REMOVE_UNSPENDABLE)
|
91
|
+
|
92
|
+
### `get_address_by_hash160`
|
53
93
|
|
54
|
-
|
94
|
+
Get a single hash160 address and its transactions. Returns an `Address` object.
|
95
|
+
|
96
|
+
##### Params:
|
97
|
+
* `str address` - address in hash160 format
|
98
|
+
|
99
|
+
##### Usage:
|
55
100
|
```ruby
|
56
|
-
|
101
|
+
explorer.get_address_by_hash160('5ddda1c11ce7df6681cb064cf9aab5d6df44bb1b')
|
57
102
|
```
|
58
103
|
|
59
|
-
|
60
|
-
Get an array of unspent outputs for an address. Returns an array of `UnspentOutput` objects.
|
104
|
+
### `get_address_by_base58`
|
61
105
|
|
62
|
-
|
63
|
-
```
|
64
|
-
address : str - address in the base58 or hash160 format
|
65
|
-
```
|
106
|
+
Get a single base58check address and its transactions. Returns an `Address` object.
|
66
107
|
|
67
|
-
|
108
|
+
##### Params:
|
109
|
+
* `str address` - address in base58check format
|
110
|
+
|
111
|
+
##### Usage:
|
68
112
|
```ruby
|
69
|
-
|
113
|
+
explorer.get_address_by_base58('19ZKM6JFvCiBQbqqHPzRDLGHpN6wkQnXDs')
|
70
114
|
```
|
71
115
|
|
72
|
-
|
73
|
-
|
116
|
+
### `get_xpub`
|
117
|
+
|
118
|
+
Get the xPub summary with its overall balanace and transactions. Returns a `Xpub` object.
|
119
|
+
|
120
|
+
##### Params:
|
121
|
+
* `str xpub` - xPub address
|
74
122
|
|
75
|
-
Usage:
|
123
|
+
##### Usage:
|
76
124
|
```ruby
|
77
|
-
|
125
|
+
explorer.get_xpub('xpub6CmZamQcHw2TPtbGmJNEvRgfhLwitarvzFn3fBYEEkFTqztus7W7CNbf48Kxuj1bRRBmZPzQocB6qar9ay6buVkQk73ftKE1z4tt9cPHWRn')
|
78
126
|
```
|
79
127
|
|
80
|
-
|
81
|
-
Get a list of currently unconfirmed transactions. Returns an array of `Transaction` objects.
|
128
|
+
### `get_multi_address`
|
82
129
|
|
83
|
-
|
130
|
+
Get data for multiple base58check and / or xpub addresses. Returns a `MultiAddress` object.
|
131
|
+
|
132
|
+
##### Params:
|
133
|
+
* `str[] address_array`
|
134
|
+
|
135
|
+
##### Usage:
|
84
136
|
```ruby
|
85
|
-
|
137
|
+
address_array = ['1C48NriBmPVvgCk1V5eNCS82zbSrKoPLbK', '1MyAwSkfdnTsV2uAsHiHMNcxqYhtWwNWSQ', '1Dn5EfV8bvfNu7HQ9iKr467nPFRiogKv9G']
|
138
|
+
explorer.get_multi_address(address_array)
|
86
139
|
```
|
140
|
+
---
|
87
141
|
|
88
|
-
|
89
|
-
Get a list of blocks for a specific day or mining pool. Returns an array of `SimpleBlock` objects.
|
142
|
+
### `get_unspent_outputs`
|
90
143
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
144
|
+
Get an array of unspent outputs for one or more base58check or hash160 addresses. Returns an array of `UnspentOutput` objects.
|
145
|
+
|
146
|
+
##### Params:
|
147
|
+
* `str[] address_array`
|
148
|
+
* `int limit` (optional) - the number of transactions to limit the response to (max. 1000, default 250)
|
149
|
+
* `int confirmations` (optional) - minimum number of confirmations to show (default 0)
|
97
150
|
|
98
|
-
Usage:
|
151
|
+
##### Usage:
|
99
152
|
```ruby
|
100
|
-
|
153
|
+
explorer.get_unspent_outputs(['1HS9RLmKvJ7D1ZYgfPExJZQZA1DMU3DEVd'])
|
101
154
|
```
|
102
155
|
|
103
|
-
|
104
|
-
Get
|
156
|
+
### `get_latest_block`
|
157
|
+
Get the latest block on the main chain. Returns a `LatestBlock` object.
|
105
158
|
|
106
|
-
|
159
|
+
##### Usage:
|
160
|
+
```ruby
|
161
|
+
explorer.get_latest_block()
|
107
162
|
```
|
108
|
-
|
163
|
+
|
164
|
+
### `get_unconfirmed_tx`
|
165
|
+
Get the last 10 unconfirmed transactions. Returns an array of `Transaction` objects.
|
166
|
+
|
167
|
+
##### Usage:
|
168
|
+
```ruby
|
169
|
+
explorer.get_unconfirmed_tx()
|
109
170
|
```
|
110
171
|
|
111
|
-
|
172
|
+
### `get_blocks`
|
173
|
+
Get a list of blocks for a specific day or mining pool. Returns an array of `SimpleBlock` objects.
|
174
|
+
|
175
|
+
##### Params:
|
176
|
+
* `int time` (optional) - unix time in ms
|
177
|
+
* `str pool_name` (optional) - pool name
|
178
|
+
|
179
|
+
Providing neither parameter will return all blocks mined today.
|
180
|
+
|
181
|
+
##### Usage:
|
112
182
|
```ruby
|
113
|
-
|
183
|
+
blocks = explorer.get_blocks(pool_name = 'Discus Fish')
|
114
184
|
```
|
115
185
|
|
116
186
|
Note regarding `Input` objects: if coinbase transaction, only `script` and `script_siq` will be populated.
|
117
187
|
|
188
|
+
## Response Object Properties
|
189
|
+
|
190
|
+
A description of the objects returned by the methods in this class
|
191
|
+
|
192
|
+
### SimpleBlock Object
|
193
|
+
* `height`
|
194
|
+
* `hash`
|
195
|
+
* `time`
|
196
|
+
* `main_chain`
|
197
|
+
|
198
|
+
### LatestBlock Object
|
199
|
+
* `hash`
|
200
|
+
* `time`
|
201
|
+
* `block_index`
|
202
|
+
* `height`
|
203
|
+
* `tx_indexes`
|
204
|
+
|
205
|
+
### UnspentOutput Object
|
206
|
+
* `tx_hash`
|
207
|
+
* `tx_index`
|
208
|
+
* `tx_output_n`
|
209
|
+
* `script`
|
210
|
+
* `value`
|
211
|
+
* `value_hex`
|
212
|
+
* `confirmations`
|
213
|
+
|
214
|
+
### Address Object
|
215
|
+
* `hash160`
|
216
|
+
* `address`
|
217
|
+
* `n_tx`
|
218
|
+
* `total_received`
|
219
|
+
* `total_sent`
|
220
|
+
* `final_balance`
|
221
|
+
* `transactions`
|
222
|
+
|
223
|
+
### MultiAddress Object
|
224
|
+
* `addresses`
|
225
|
+
* `transactions`
|
226
|
+
|
227
|
+
### Xpub Object
|
228
|
+
* `address`
|
229
|
+
* `n_tx`
|
230
|
+
* `total_received`
|
231
|
+
* `total_sent`
|
232
|
+
* `final_balance`
|
233
|
+
* `change_index`
|
234
|
+
* `account_index`
|
235
|
+
* `gap_limit`
|
236
|
+
|
237
|
+
### Input Object
|
238
|
+
* `n`
|
239
|
+
* `value`
|
240
|
+
* `address`
|
241
|
+
* `tx_index`
|
242
|
+
* `type`
|
243
|
+
* `script`
|
244
|
+
* `script_sig`
|
245
|
+
* `sequence`
|
246
|
+
|
247
|
+
### Output Object
|
248
|
+
* `n`
|
249
|
+
* `value`
|
250
|
+
* `address`
|
251
|
+
* `tx_index`
|
252
|
+
* `script`
|
253
|
+
* `spent`
|
254
|
+
|
255
|
+
### Transaction Object
|
256
|
+
* `double_spend`
|
257
|
+
* `block_height`
|
258
|
+
* `time`
|
259
|
+
* `relayed_by`
|
260
|
+
* `hash`
|
261
|
+
* `tx_index`
|
262
|
+
* `version`
|
263
|
+
* `size`
|
264
|
+
* `inputs`
|
265
|
+
* `outputs`
|
266
|
+
|
267
|
+
### Block Object
|
268
|
+
* `hash`
|
269
|
+
* `version`
|
270
|
+
* `previous_block`
|
271
|
+
* `merkle_root`
|
272
|
+
* `time`
|
273
|
+
* `bits`
|
274
|
+
* `fee`
|
275
|
+
* `nonce`
|
276
|
+
* `n_tx`
|
277
|
+
* `size`
|
278
|
+
* `block_index`
|
279
|
+
* `main_chain`
|
280
|
+
* `height`
|
281
|
+
* `received_time`
|
282
|
+
* `relayed_by`
|
283
|
+
* `transactions`
|
284
|
+
|
285
|
+
### FilterType Enum
|
286
|
+
* `ALL`
|
287
|
+
* `CONFIRMED_ONLY`
|
288
|
+
* `REMOVE_UNSPENDABLE`
|
data/docs/createwallet.md
CHANGED
@@ -1,21 +1,38 @@
|
|
1
|
-
|
1
|
+
# Create Wallet functionality
|
2
2
|
|
3
|
-
|
4
|
-
Create a new Blockchain.info wallet. It can be created containing a pre-generated private key or will otherwise generate a new private key. Returns a `CreateWalletResponse` instance.
|
3
|
+
Initialize an instance of the `WalletCreator` class:
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
```ruby
|
6
|
+
require 'Blockchain'
|
7
|
+
|
8
|
+
# create an instance potining to http://127,0.0.1:3000/
|
9
|
+
wallet_creator = Blockchain::WalletCreator.new(api_code = 'your-api-code')
|
10
|
+
|
11
|
+
# create an instance pointing to an alternative base url
|
12
|
+
wallet_creator = Blockchain::BlockExplorer.new('http://some-alternative-url', 'your-api-code')
|
14
13
|
```
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
## Methods
|
16
|
+
|
17
|
+
### `create_wallet`
|
18
|
+
Create a new Blockchain.info wallet. It can be created containing a pre-generated private key or will otherwise generate a new private key. Returns a `CreateWalletResponse` instance.
|
19
|
+
|
20
|
+
##### Params:
|
21
|
+
|
22
|
+
* `str password` - password for the new wallet. Min. 10 characters.
|
23
|
+
* `str priv` (optional) - private key to add to the wallet.
|
24
|
+
* `str label` (optional) - label for the first address in the wallet.
|
25
|
+
* `str email` (optional) - email to associate with the new wallet.
|
26
|
+
|
19
27
|
|
20
|
-
|
28
|
+
##### Usage:
|
29
|
+
```ruby
|
30
|
+
new_wallet = wallet_creator.create_wallet('1234password', label = 'Test wallet')
|
21
31
|
```
|
32
|
+
|
33
|
+
## Response Object Properties
|
34
|
+
|
35
|
+
### CreateWalletResponse Object
|
36
|
+
* `identifier`
|
37
|
+
* `address`
|
38
|
+
* `label`
|