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.
- 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
data/docs/exchangerates.md
CHANGED
@@ -1,32 +1,57 @@
|
|
1
|
-
|
1
|
+
# Exchange Rates functionality
|
2
2
|
|
3
|
-
|
3
|
+
Initialize an instance of the `ExchangeRateExplorer` class:
|
4
4
|
|
5
|
-
|
6
|
-
|
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
|
-
|
10
|
-
|
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
|
-
|
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
|
-
|
21
|
-
|
26
|
+
### `to_btc`
|
27
|
+
Convert x value in the provided currency to BTC. Returns a `float`.
|
22
28
|
|
23
|
-
Params:
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
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
|
-
|
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`
|
data/docs/pushtx.md
CHANGED
@@ -1,18 +1,24 @@
|
|
1
|
-
|
1
|
+
# Push transaction functionality
|
2
2
|
|
3
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
13
|
-
```ruby
|
14
|
-
require 'blockchain'
|
12
|
+
## Methods
|
15
13
|
|
16
|
-
|
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
|
```
|
data/docs/receive.md
CHANGED
@@ -1,36 +1,63 @@
|
|
1
|
-
|
1
|
+
# Receive Payments V2 functionality
|
2
2
|
|
3
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
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
|
-
|
22
|
-
|
18
|
+
##### Params:
|
19
|
+
* `str xpub`
|
20
|
+
* `str callback`
|
21
|
+
* `str api_key`
|
23
22
|
|
24
|
-
|
23
|
+
##### Usage:
|
24
|
+
```ruby
|
25
|
+
resp = receive_payment.receive('xpub1hNapz1CuH4DhnV1DFHH7hafwDE8FJRheA', 'http://your.url.com', 'yourApiKey')
|
25
26
|
```
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
-
|
49
|
+
resp = receive_payment.callback_log('xpub1hNapz1CuH4DhnV1DFHH7hafwDE8FJRheA', 'yourApiKey')
|
50
|
+
```
|
51
|
+
|
52
|
+
## Response Object Properties
|
33
53
|
|
34
|
-
|
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`
|
data/docs/statistics.md
CHANGED
@@ -1,16 +1,79 @@
|
|
1
|
-
|
1
|
+
# Statistics functionality
|
2
2
|
|
3
|
-
|
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
|
-
|
17
|
+
##### Usage:
|
18
|
+
```ruby
|
19
|
+
stats = explorer.get_statistics()
|
7
20
|
```
|
8
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
16
|
-
|
77
|
+
### ChartValue Object
|
78
|
+
* `x`
|
79
|
+
* `y`
|
data/docs/wallet.md
CHANGED
@@ -1,54 +1,49 @@
|
|
1
|
-
|
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
|
-
|
8
|
-
|
9
|
-
url :
|
10
|
-
|
11
|
-
|
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 '
|
15
|
+
require 'Blockchain'
|
17
16
|
|
18
|
-
wallet = Blockchain::Wallet.new('ada4e4b6-3c9f-11e4-baad-164230d1df67', 'password123'
|
17
|
+
wallet = Blockchain::Wallet.new('ada4e4b6-3c9f-11e4-baad-164230d1df67', 'password123')
|
19
18
|
```
|
20
19
|
|
21
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
38
|
+
### `send_many`
|
41
39
|
Send bitcoin from your wallet to multiple addresses. Returns a `PaymentResponse` object.
|
42
40
|
|
43
|
-
Params:
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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
|
-
|
69
|
-
List all active addresses in the wallet. Returns an array of `
|
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
|
-
|
86
|
-
Retrieve an address from the wallet. Returns an `
|
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'
|
83
|
+
addr = wallet.get_address('1NAF7GbdyRg3miHNrw2bGxrd63tfMEmJob')
|
96
84
|
puts addr.balance
|
97
85
|
```
|
98
86
|
|
99
|
-
|
100
|
-
Generate a new address and add it to the wallet. Returns an `
|
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
|
-
|
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
|
-
|
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
|
-
|
139
|
-
Consolidate the wallet addresses. Returns a string array of consolidated addresses.
|
120
|
+
## Response Object Properties
|
140
121
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
122
|
+
### WalletAddress Object
|
123
|
+
* `balance`
|
124
|
+
* `address`
|
125
|
+
* `label`
|
126
|
+
* `total_received`
|
145
127
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
128
|
+
### PaymentResponse Object
|
129
|
+
* `message`
|
130
|
+
* `tx_hash`
|
131
|
+
* `notice`
|