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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a92813c9ae48afa6b214434774c53a23b75be82
4
- data.tar.gz: 2cc22009b6e5573682c72e666be18dcb2635897b
3
+ metadata.gz: ad92df1e084cfe05666bfc1b54bcde999de70dec
4
+ data.tar.gz: 2ec38849a086345f5824a654428d38ac4dcbb6e5
5
5
  SHA512:
6
- metadata.gz: 0e89dcad42091a11a0700423540d9bad795a7deea3cd996cb020780fc1cdab0e2d8d9f49592317473778714be30c091200dea7019057287a0d3b7bf02e19efa2
7
- data.tar.gz: 8211b24abb62df05bbf0accbb6451f10e426d8b41b99f602785c055476d52b60b64bf506c24b79bf94a5568e0ce7f56e4097644226559787213a9e548f952e56
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
- ###Getting started
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
- ###Error handling
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 'blockchain'
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
- begin
4
- require 'rspec/core/rake_task'
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
@@ -20,6 +20,4 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency 'rspec', '~> 3.4'
24
-
25
- end
23
+ end
@@ -1,117 +1,288 @@
1
- ##Block explorer functionality
1
+ # Block Explorer functionality
2
2
 
3
- All functions support an optional parameter called `api_code`. It won't be listed with every function description.
3
+ Initialize an instance of the `BlockExplorer` class:
4
4
 
5
- ####`get_block`
6
- Get a single block based on a block index or hash. Returns a `Block` object.
5
+ ```ruby
6
+ require 'Blockchain'
7
7
 
8
- Params:
9
- ```
10
- block_id : str - block index or hash
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
- Usage:
14
- ```ruby
15
- require 'blockchain'
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
- block = Blockchain::get_block('000000000000000016f9a2c3e0f4c1245ff24856a79c34806969f5084f410680')
27
+ ##### Params:
28
+ * `int block_index`
29
+
30
+ ##### Usage:
31
+ ```ruby
32
+ explorer.get_block_by_index(1486749)
18
33
  ```
19
34
 
20
- ####`get_tx`
21
- Get a single transaction based on a transaction index or hash. Returns a `Transaction` object.
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
- Params:
42
+ ##### Usage:
43
+ ```ruby
44
+ explorer.get_block_by_hash('000000000000000016f9a2c3e0f4c1245ff24856a79c34806969f5084f410680')
24
45
  ```
25
- tx_id : str - transaction index or hash
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
- Usage:
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
- tx = Blockchain::get_tx('d4af240386cdacab4ca666d178afc88280b620ae308ae8d2585e9ab8fc664a94')
68
+ explorer.get_tx_by_hash('d4af240386cdacab4ca666d178afc88280b620ae308ae8d2585e9ab8fc664a94')
31
69
  ```
32
70
 
33
- ####`get_block_height`
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
- blocks = Blockchain::get_block_height(2570)
80
+ explorer.get_block_height(2570)
44
81
  ```
45
82
 
46
- ####`get_address`
47
- Get a single address and its transactions. Returns an `Address` object.
83
+ ---
84
+ ### Get Address
48
85
 
49
- Params:
50
- ```
51
- address : str - address in the base58 or hash160 format
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
- Usage:
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
- address = Blockchain::get_address('1HS9RLmKvJ7D1ZYgfPExJZQZA1DMU3DEVd')
101
+ explorer.get_address_by_hash160('5ddda1c11ce7df6681cb064cf9aab5d6df44bb1b')
57
102
  ```
58
103
 
59
- ####`get_unspent_outputs`
60
- Get an array of unspent outputs for an address. Returns an array of `UnspentOutput` objects.
104
+ ### `get_address_by_base58`
61
105
 
62
- Params:
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
- Usage:
108
+ ##### Params:
109
+ * `str address` - address in base58check format
110
+
111
+ ##### Usage:
68
112
  ```ruby
69
- outs = Blockchain::get_unspent_outputs('1HS9RLmKvJ7D1ZYgfPExJZQZA1DMU3DEVd')
113
+ explorer.get_address_by_base58('19ZKM6JFvCiBQbqqHPzRDLGHpN6wkQnXDs')
70
114
  ```
71
115
 
72
- ####`get_latest_block`
73
- Get the latest block on the main chain. Returns a `LatestBlock` object.
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
- latest_block = Blockchain::get_latest_block()
125
+ explorer.get_xpub('xpub6CmZamQcHw2TPtbGmJNEvRgfhLwitarvzFn3fBYEEkFTqztus7W7CNbf48Kxuj1bRRBmZPzQocB6qar9ay6buVkQk73ftKE1z4tt9cPHWRn')
78
126
  ```
79
127
 
80
- ####`get_unconfirmed_tx`
81
- Get a list of currently unconfirmed transactions. Returns an array of `Transaction` objects.
128
+ ### `get_multi_address`
82
129
 
83
- Usage:
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
- txs = Blockchain::get_unconfirmed_tx()
137
+ address_array = ['1C48NriBmPVvgCk1V5eNCS82zbSrKoPLbK', '1MyAwSkfdnTsV2uAsHiHMNcxqYhtWwNWSQ', '1Dn5EfV8bvfNu7HQ9iKr467nPFRiogKv9G']
138
+ explorer.get_multi_address(address_array)
86
139
  ```
140
+ ---
87
141
 
88
- ####`get_blocks`
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
- Params:
92
- ```
93
- time : int - unix time in ms (optional)
94
- pool_name : str - pool name (optional)
95
- ```
96
- At least one parameter is required.
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
- blocks = Blockchain::get_blocks(pool_name = 'Discus Fish')
153
+ explorer.get_unspent_outputs(['1HS9RLmKvJ7D1ZYgfPExJZQZA1DMU3DEVd'])
101
154
  ```
102
155
 
103
- ####`get_inventory_data`
104
- Get inventory data for recent blocks and addresses (up to 1 hour old). Returns an `InventoryData` object.
156
+ ### `get_latest_block`
157
+ Get the latest block on the main chain. Returns a `LatestBlock` object.
105
158
 
106
- Params:
159
+ ##### Usage:
160
+ ```ruby
161
+ explorer.get_latest_block()
107
162
  ```
108
- hash : str - tx or block hash
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
- Usage:
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
- inv = Blockchain::get_inventory_data('d4af240386cdacab4ca666d178afc88280b620ae308ae8d2585e9ab8fc664a94')
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`
@@ -1,21 +1,38 @@
1
- ##Create Wallet functionality
1
+ # Create Wallet functionality
2
2
 
3
- ####`create_wallet`
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
- Params:
7
- ```
8
- password : str - password for the new wallet. At least 10 characters.
9
- api_code : str - API code with the create wallets permission
10
- url : str - URL for an instance of service-my-wallet
11
- priv : str - private key to add to the wallet (optional, keyword)
12
- label : str - label for the first address in the wallet (optional, keyword)
13
- email : str - email to associate with the new wallet (optional, keyword)
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
- Usage:
17
- ```ruby
18
- require 'blockchain'
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
- wallet = Blockchain::create_wallet('1234password', '58ck39ajuiw', 'http://localhost:3000/', label: 'Test wallet')
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`