blockchain 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,32 +1,57 @@
1
- ##Exchange rates functionality
1
+ # Exchange Rates 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 `ExchangeRateExplorer` class:
4
4
 
5
- ####`get_ticker`
6
- Call the 'ticker' method and return a dictionary of `Currency` objects. Keys are currency symbols (str) and values are `Currency` objects.
5
+ ```ruby
6
+ # as with other classes, you can set optional params base_url and / or api_code
7
+
8
+ require 'Blockchain'
9
+ explorer = Blockchain::ExchangeRateExplorer.new
10
+ ```
7
11
 
12
+ ## Methods
8
13
 
9
- Usage:
10
- ```ruby
11
- require 'blockchain'
14
+ ### `get_ticker`
15
+ Call the 'ticker' method and return a dictionary of `Currency` objects. Keys are currency codes (str) and values are `Currency` objects.
12
16
 
13
- ticker = Blockchain::get_ticker()
17
+ ##### Usage:
18
+ ```ruby
19
+ ticker = explorer.get_ticker
14
20
  #print the 15 min price for every currency
15
21
  ticker.keys.each do |key|
16
22
  puts ticker[key].p15min
17
23
  end
18
24
  ```
19
25
 
20
- ####`to_btc`
21
- Call the 'tobtc' method and convert x value in the provided currency to BTC. Returns a `float`.
26
+ ### `to_btc`
27
+ Convert x value in the provided currency to BTC. Returns a `float`.
22
28
 
23
- Params:
24
- ```
25
- ccy : str - currency code
26
- value : float
29
+ ##### Params:
30
+ * `str ccy` - code of the currency to convert from
31
+ * `float value` - amount in selected currency
32
+
33
+ ##### Usage:
34
+ ```ruby
35
+ btc_amount = explorer.to_btc('USD', 4342.11)
27
36
  ```
28
37
 
29
- Usage:
38
+ ### `from_btc`
39
+ Convert x value in satoshi to the provided currency. Returns a `float`
40
+
41
+ ##### Params:
42
+ * `str ccy` (optional) - code of the currency to convert to (default USD)
43
+ * `float satoshi_value` - amount of satoshi to convert
44
+
45
+ ##### Usage:
30
46
  ```ruby
31
- btc_amount = Blockchain::to_btc('USD', 4342.11)
32
- ```
47
+ one_btc_usd_value = explorer.from_btc(100000000)
48
+ ```
49
+
50
+ ## Response Object Properties
51
+
52
+ ### Currency Object
53
+ * `last`
54
+ * `buy`
55
+ * `sell`
56
+ * `symbol`
57
+ * `p15min`
@@ -1,18 +1,24 @@
1
- ##Push transaction functionality
1
+ # Push transaction functionality
2
2
 
3
- ####`pushtx`
4
- Call the pushtx endpoint and broadcast a hex encoded transaction. The method does not return anything upon success, but will raise exceptions if the transaction is malformed.
3
+ Initialize an instance of the `PushTx` class:
5
4
 
6
- Params:
7
- ```
8
- tx : str (hex encoded)
9
- api_code : str (optional)
5
+ ```ruby
6
+ # as with other classes, you can set optional params base_url and / or api_code
7
+
8
+ require 'Blockchain'
9
+ push_tx = Blockchain::PushTx.new
10
10
  ```
11
11
 
12
- Usage:
13
- ```ruby
14
- require 'blockchain'
12
+ ## Methods
15
13
 
16
- Blockchain::pushtx( '0100000001fd468e431cf5797b108e4d22724e1e055b3ecec59af4ef17b063afd36d3c5cf6010000008c4930460221009918eee8be186035be8ca573b7a4ef7bc672c59430785e5390cc375329a2099702210085b86387e3e15d68c847a1bdf786ed0fdbc87ab3b7c224f3c5490ac19ff4e756014104fe2cfcf0733e559cbf28d7b1489a673c0d7d6de8470d7ff3b272e7221afb051b777b5f879dd6a8908f459f950650319f0e83a5cf1d7c1dfadf6458f09a84ba80ffffffff01185d2033000000001976a9144be9a6a5f6fb75765145d9c54f1a4929e407d2ec88ac00000000')
14
+ ### `pushtx`
15
+ Call the pushtx endpoint and broadcast a hex encoded transaction. The method does not return anything upon success, but will raise exceptions if the transaction is malformed.
16
+
17
+ ##### Params:
18
+ * `str tx` (hex encoded)
19
+
20
+ ##### Usage:
21
+ ```ruby
22
+ push_tx.pushtx( '0100000001fd468e431cf5797b108e4d22724e1e055b3ecec59af4ef17b063afd36d3c5cf6010000008c4930460221009918eee8be186035be8ca573b7a4ef7bc672c59430785e5390cc375329a2099702210085b86387e3e15d68c847a1bdf786ed0fdbc87ab3b7c224f3c5490ac19ff4e756014104fe2cfcf0733e559cbf28d7b1489a673c0d7d6de8470d7ff3b272e7221afb051b777b5f879dd6a8908f459f950650319f0e83a5cf1d7c1dfadf6458f09a84ba80ffffffff01185d2033000000001976a9144be9a6a5f6fb75765145d9c54f1a4929e407d2ec88ac00000000')
17
23
 
18
24
  ```
@@ -1,36 +1,63 @@
1
- ##Receive V2 functionality
1
+ # Receive Payments V2 functionality
2
2
 
3
- ####`receive`
4
- Call the 'v2/receive' endpoint and create a new address. Returns a `V2::ReceiveResponse` object.
3
+ Initialize an instance of the `Receive` class:
5
4
 
6
- Params:
7
- ```
8
- xpub : str
9
- callback : str
10
- api_key : str
5
+ ```ruby
6
+ # you can set optional param base_url (https://api.blockchain.info/v2/ by default).
7
+
8
+ require 'Blockchain'
9
+ receive_payment = Blockchain::V2::Receive.new
11
10
  ```
12
11
 
13
- Usage:
14
- ```ruby
15
- require 'blockchain'
16
12
 
17
- resp = Blockchain::V2::receive('xpub1hNapz1CuH4DhnV1DFHH7hafwDE8FJRheA', 'http://your.url.com', 'yourApiKey')
13
+ ## Methods
18
14
 
19
- ```
15
+ ### `receive`
16
+ Call the 'v2/receive' endpoint and create a new address. Returns a `V2::ReceiveResponse` object.
20
17
 
21
- ####`callback_log`
22
- Call the 'v2/receive/callback_log' endpoint. Returns an array of `LogEntry` objects.
18
+ ##### Params:
19
+ * `str xpub`
20
+ * `str callback`
21
+ * `str api_key`
23
22
 
24
- Params:
23
+ ##### Usage:
24
+ ```ruby
25
+ resp = receive_payment.receive('xpub1hNapz1CuH4DhnV1DFHH7hafwDE8FJRheA', 'http://your.url.com', 'yourApiKey')
25
26
  ```
26
- callback : str
27
- api_key : str
27
+
28
+ ### `callback_log`
29
+ Call the 'v2/receive/callback_log' endpoint to see logs related to callback attempts. Returns an array of `LogEntry` objects.
30
+
31
+ ##### Params:
32
+ * `str callback`
33
+ * `str api_key`
34
+
35
+ ##### Usage:
36
+ ```ruby
37
+ resp = receive_payment.callback_log('http://your.url.com', 'yourApiKey')
28
38
  ```
29
39
 
30
- Usage:
40
+ ### `callback_log`
41
+ Call the 'v2/receive/checkgap' endpoint to check the index gap betweem the last address paid and the last address generated. Returns an `int`.
42
+
43
+ ##### Params:
44
+ * `str xpub`
45
+ * `str api_key`
46
+
47
+ ##### Usage:
31
48
  ```ruby
32
- require 'blockchain'
49
+ resp = receive_payment.callback_log('xpub1hNapz1CuH4DhnV1DFHH7hafwDE8FJRheA', 'yourApiKey')
50
+ ```
51
+
52
+ ## Response Object Properties
33
53
 
34
- resp = Blockchain::callback_log('1hNapz1CuH4DhnV1DFHH7hafwDE8FJRheA', 'http://your.url.com')
54
+ ### ReceiveResponse Object
55
+ * `address`
56
+ * `index`
57
+ * `callback_url`
35
58
 
36
- ```
59
+ ### LogEntry Object
60
+ * `callback_url`
61
+ * `called_at`
62
+ * `raw_response`
63
+ * `response_code`
@@ -1,16 +1,79 @@
1
- ## Statistics functionality
1
+ # Statistics functionality
2
2
 
3
- ####`get`
3
+ Initialize an instance of the `StatisticsExplorer` class:
4
+
5
+ ```ruby
6
+ # as with other classes, you can set optional params base_url and / or api_code
7
+
8
+ require 'Blockchain'
9
+ explorer = Blockchain::StatisticsExplorer.new
10
+ ```
11
+
12
+ ## Methods
13
+
14
+ ### `get_statistics`
4
15
  Get network statistics. Returns a `StatisticsResponse` object.
5
16
 
6
- Params:
17
+ ##### Usage:
18
+ ```ruby
19
+ stats = explorer.get_statistics()
7
20
  ```
8
- api_code : str (optional)
21
+
22
+ ### `get_chart`
23
+ Get data from a Blockchain.info chart. Returns a `ChartResponse` object.
24
+
25
+ ##### Params
26
+ * `str chart_type` - the name of the chart to get data for
27
+ * `str timespan` (optional) - the duration of the chart (1 year by default in most cases, 1 week for mempool charts)
28
+ * `str rolling_average` (optional) - the duration over which data should be averaged
29
+
30
+ ##### Usage
31
+ ```ruby
32
+ chart_stats = explorer.get_chart('transactions-per-second', '5weeks', '8hours')
9
33
  ```
10
34
 
11
- Usage:
35
+ ### `get_pools`
36
+ Get all mining pools and the total blocks they each mined in the last 4 days. Returns a `str` => `int` hash.
37
+
38
+ ##### Params
39
+ * `int timespan` (optional) - number of days to get data for (default 4, maximum 10)
40
+
41
+ ##### Usage
12
42
  ```ruby
13
- require 'blockchain'
43
+ pool_stats = explorer.get_pools(8)
44
+ ```
45
+
46
+ ## Response Object Properties
47
+
48
+ ### StatisticsResponse Object
49
+ * `trade_volume_btc`
50
+ * `miners_revenue_usd`
51
+ * `btc_mined`
52
+ * `trade_volume_usd`
53
+ * `difficulty`
54
+ * `minutes_between_blocks`
55
+ * `number_of_transactions`
56
+ * `hash_rate`
57
+ * `timestamp`
58
+ * `mined_blocks`
59
+ * `blocks_size`
60
+ * `total_fees_btc`
61
+ * `total_btc_sent`
62
+ * `estimated_btc_sent`
63
+ * `total_btc`
64
+ * `total_blocks`
65
+ * `next_retarget`
66
+ * `estimated_transaction_volume_usd`
67
+ * `miners_revenue_btc`
68
+ * `market_price_usd`
69
+
70
+ ### ChartResponse Object
71
+ * `chart_name`
72
+ * `unit`
73
+ * `timespan`
74
+ * `description`
75
+ * `values`
14
76
 
15
- stats = Blockchain::get_statistics()
16
- ```
77
+ ### ChartValue Object
78
+ * `x`
79
+ * `y`
@@ -1,54 +1,49 @@
1
- ##`wallet` module
1
+ # Wallet functionality
2
2
 
3
3
  An instance of the `Wallet` class needs to be initialized before it can be used.
4
4
 
5
- Constructor params:
6
- ```
7
- identifier : str
8
- password : str
9
- url : str
10
- second_password : str (optional)
11
- api_code : str (optional)
12
- ```
5
+ ##### Constructor params:
6
+
7
+ * `str identifier`
8
+ * `str password`
9
+ * `str url` (optional, defaults to http://localhost:3000)
10
+ * `str second_password` (optional)
11
+ * `str api_code` (optional)
13
12
 
14
- Usage:
13
+ ##### Usage:
15
14
  ```ruby
16
- require 'blockchain'
15
+ require 'Blockchain'
17
16
 
18
- wallet = Blockchain::Wallet.new('ada4e4b6-3c9f-11e4-baad-164230d1df67', 'password123', 'http://localhost:3000/')
17
+ wallet = Blockchain::Wallet.new('ada4e4b6-3c9f-11e4-baad-164230d1df67', 'password123')
19
18
  ```
20
19
 
21
- ####`send`
20
+ ## Methods
21
+
22
+ ### `send`
22
23
  Send bitcoin from your wallet to a single address. Returns a `PaymentResponse` object.
23
24
 
24
- Params:
25
- ```
26
- to : str - receiving address
27
- amount : int - amount to send (in satoshi)
28
- from_address : str - specific address to send from (optional, keyword)
29
- fee : int - transaction fee in satoshi. Must be greater than default (optional, keyword)
30
- note : str - public note to include with the transaction if amount >= 0.005 BTC (optional, keyword)
31
- ```
25
+ ##### Params:
26
+ * `str to` - receiving address
27
+ * `int amount` - amount to send (in satoshi)
28
+ * `str from_address` (optional, keyword) - specific address to send from
29
+ * `int fee` (optional, keyword) - transaction fee in satoshi. Must be greater than default
32
30
 
33
- Usage:
31
+ ##### Usage:
34
32
  ```ruby
35
33
  payment = wallet.send('1NAF7GbdyRg3miHNrw2bGxrd63tfMEmJob', 1000000, from_address: '1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq')
36
34
 
37
35
  puts payment.tx_hash
38
36
  ```
39
37
 
40
- ####`send_many`
38
+ ### `send_many`
41
39
  Send bitcoin from your wallet to multiple addresses. Returns a `PaymentResponse` object.
42
40
 
43
- Params:
44
- ```
45
- recipients : dictionary - dictionary with the structure of 'address':amount
46
- from_address : str - specific address to send from (optional, keyword)
47
- fee : int - transaction fee in satoshi. Must be greater than default (optional, keyword)
48
- note : str - public note to include with the transaction if amount >= 0.005 BTC (optional, keyword)
49
- ```
41
+ ##### Params:
42
+ * `dictionary recipients` - hash with the structure of `str address` => `int amount` in satoshi
43
+ * `str from_address` (optional, keyword) - specific address to send from
44
+ * `int fee` (optional, keyword) - transaction fee in satoshi. Must be greater than default
50
45
 
51
- Usage:
46
+ ##### Usage:
52
47
  ```ruby
53
48
  recipients = { '1NAF7GbdyRg3miHNrw2bGxrd63tfMEmJob' => 1428300,
54
49
  '1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq' => 234522117 }
@@ -57,23 +52,18 @@ payment = wallet.send_many(recipients)
57
52
  puts payment.tx_hash
58
53
  ```
59
54
 
60
- ####`get_balance`
55
+ ### `get_balance`
61
56
  Fetch the wallet balance. Includes unconfirmed transactions and possibly double spends. Returns the wallet balance in satoshi.
62
57
 
63
- Usage:
58
+ ##### Usage:
64
59
  ```ruby
65
- puts wallet.get_balance()
60
+ puts wallet.get_balance()
66
61
  ```
67
62
 
68
- ####`list_addresses`
69
- List all active addresses in the wallet. Returns an array of `Address` objects.
70
-
71
- Params:
72
- ```
73
- confirmations : int - minimum number of confirmations transactions must have before being included in balance of addresses (optional)
74
- ```
63
+ ### `list_addresses`
64
+ List all active addresses in the wallet. Returns an array of `WalletAddress` objects.
75
65
 
76
- Usage:
66
+ ##### Usage:
77
67
  ```ruby
78
68
  addresses = wallet.list_addresses()
79
69
  addresses.each do |a|
@@ -82,68 +72,60 @@ end
82
72
 
83
73
  ```
84
74
 
85
- ####`get_address`
86
- Retrieve an address from the wallet. Returns an `Address` object.
75
+ ### `get_address`
76
+ Retrieve an address from the wallet. Returns an `WalletAddress` object.
87
77
 
88
- Params:
89
- ```
90
- confirmations : int - minimum number of confirmations transactions must have before being included in the balance (optional)
91
- ```
78
+ ##### Params:
79
+ * `str address` - the address to retrieve
92
80
 
93
- Usage:
81
+ ##### Usage:
94
82
  ```ruby
95
- addr = wallet.get_address('1NAF7GbdyRg3miHNrw2bGxrd63tfMEmJob', confirmations = 2)
83
+ addr = wallet.get_address('1NAF7GbdyRg3miHNrw2bGxrd63tfMEmJob')
96
84
  puts addr.balance
97
85
  ```
98
86
 
99
- ####`new_address`
100
- Generate a new address and add it to the wallet. Returns an `Address` object.
87
+ ### `new_address`
88
+ Generate a new address and add it to the wallet. Returns an `WalletAddress` object.
101
89
 
102
- Params:
103
- ```
104
- label : str - label to attach to the address (optional, keyword)
105
- ```
90
+ ##### Params:
91
+ * `str label` (optional, keyword) - label to attach to the address
106
92
 
107
- Usage:
93
+ ##### Usage:
108
94
  ```ruby
109
95
  newaddr = wallet.new_address('test_label')
110
96
  ```
111
97
 
112
- ####`archive_address`
98
+ ### `archive_address`
113
99
  Archive an address. Returns a string representation of the archived address.
114
100
 
115
- Params:
116
- ```
117
- address : str - address to archive
118
- ```
101
+ ##### Params:
102
+ * `str address` - address to archive
119
103
 
120
- Usage:
104
+ ##### Usage:
121
105
  ```ruby
122
106
  wallet.archive_address('1NAF7GbdyRg3miHNrw2bGxrd63tfMEmJob')
123
107
  ```
124
108
 
125
- ####`unarchive_address`
109
+ ### `unarchive_address`
126
110
  Unarchive an address. Returns a string representation of the unarchived address.
127
111
 
128
- Params:
129
- ```
130
- address : str - address to unarchive
131
- ```
112
+ ##### Params:
113
+ * `str address` - address to unarchive
132
114
 
133
- Usage:
115
+ ##### Usage:
134
116
  ```ruby
135
117
  wallet.unarchive_address('1NAF7GbdyRg3miHNrw2bGxrd63tfMEmJob')
136
118
  ```
137
119
 
138
- ####`consolidate`
139
- Consolidate the wallet addresses. Returns a string array of consolidated addresses.
120
+ ## Response Object Properties
140
121
 
141
- Params:
142
- ```
143
- days : int - addresses which have not received any transactions in at least this many days will be consolidated.
144
- ```
122
+ ### WalletAddress Object
123
+ * `balance`
124
+ * `address`
125
+ * `label`
126
+ * `total_received`
145
127
 
146
- Usage:
147
- ```ruby
148
- wallet.consolidate(50)
149
- ```
128
+ ### PaymentResponse Object
129
+ * `message`
130
+ * `tx_hash`
131
+ * `notice`