Class: BlockrIo

Inherits:
Object
  • Object
show all
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

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_urlObject



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

Returns:

  • (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