Class: BlockrIo
- Inherits:
-
Object
- Object
- BlockrIo
- Defined in:
- lib/blockr_io.rb
Overview
This is a ‘driver’ meant to emulate bitcoin-client calls, by way of the blockr.io API
Defined Under Namespace
Classes: ResponseError
Instance Method Summary collapse
- #api_url ⇒ Object
- #getrawtransaction(tx_id) ⇒ Object
-
#initialize(is_testing = false) ⇒ BlockrIo
constructor
A new instance of BlockrIo.
- #is_testing? ⇒ Boolean
-
#listunconfirmed(addr) ⇒ Object
Shows all the transactions that are unconfirmed for the provided address:.
- #listunspent(addr, include_unconfirmed = false) ⇒ Object
- #sendrawtransaction(raw_tx) ⇒ Object
Constructor Details
#initialize(is_testing = false) ⇒ BlockrIo
Returns a new instance of BlockrIo.
6 7 8 |
# File 'lib/blockr_io.rb', line 6 def initialize(is_testing = false) @is_testing = is_testing end |
Instance Method Details
#api_url ⇒ Object
10 11 12 |
# File 'lib/blockr_io.rb', line 10 def api_url 'http://%s.blockr.io/api/v1' % (is_testing? ? 'tbtc' : 'btc') end |
#getrawtransaction(tx_id) ⇒ Object
14 15 16 |
# File 'lib/blockr_io.rb', line 14 def getrawtransaction(tx_id) json_get('tx', 'raw', tx_id.to_s)['data']['tx']['hex'] end |
#is_testing? ⇒ Boolean
23 24 25 |
# File 'lib/blockr_io.rb', line 23 def is_testing? @is_testing end |
#listunconfirmed(addr) ⇒ Object
Shows all the transactions that are unconfirmed for the provided address:
33 34 35 |
# File 'lib/blockr_io.rb', line 33 def listunconfirmed(addr) json_get('address','unconfirmed',addr)['data']['unconfirmed'] end |
#listunspent(addr, include_unconfirmed = false) ⇒ Object
27 28 29 30 |
# File 'lib/blockr_io.rb', line 27 def listunspent(addr, include_unconfirmed = false) query = [addr,(include_unconfirmed) ? '?unconfirmed=1' : nil ].join json_get('address', 'unspent', query)['data']['unspent'] end |
#sendrawtransaction(raw_tx) ⇒ Object
18 19 20 21 |
# File 'lib/blockr_io.rb', line 18 def sendrawtransaction(raw_tx) request('tx', 'push'){|req| req.post( {hex: raw_tx}.to_json, accept: 'json', content_type: 'json' ) }['data'] end |