Class: Bitcoin2Graphdb::Bitcoin::BlockchainProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ BlockchainProvider

Returns a new instance of BlockchainProvider.



17
18
19
20
# File 'lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb', line 17

def initialize(config)
  @api = OpenAssets::Api.new(config)
  @api
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



15
16
17
# File 'lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb', line 15

def api
  @api
end

Instance Method Details

#block(block_hash) ⇒ Object

Raises:

  • (OpenAssets::Provider::ApiError)


22
23
24
25
26
# File 'lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb', line 22

def block(block_hash)
  b = api.provider.getblock(block_hash)
  raise OpenAssets::Provider::ApiError.new('{"code"=>-8, "message"=>"Block height out of range"}') if b['confirmations'] < min_block_confirmation
  b
end

#block_hash(block_height) ⇒ Object



28
29
30
# File 'lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb', line 28

def block_hash(block_height)
  api.provider.getblockhash(block_height)
end

#oa_outputs(txid, cache = true) ⇒ Object



36
37
38
# File 'lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb', line 36

def oa_outputs(txid, cache = true)
  api.get_outputs_from_txid(txid, cache)
end

#tx(txid) ⇒ Object



32
33
34
# File 'lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb', line 32

def tx(txid)
  api.provider.getrawtransaction(txid, 1)
end