Sha256: 06b99cb20fc3efc84a352b92378efd771765d0113e8389f5cc365255160a4755

Contents?: true

Size: 1017 Bytes

Versions: 8

Compression:

Stored size: 1017 Bytes

Contents

module Bitcoin2Graphdb
  module Bitcoin

    class << self
      attr_accessor :provider

      def open(config)
        self.provider = BlockchainProvider.new(config)
      end

    end

    class BlockchainProvider

      attr_reader :api

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

      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

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

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

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

      private
      def min_block_confirmation
        api.config[:min_block_confirmation] ? api.config[:min_block_confirmation] : 2
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bitcoin2graphdb-0.4.1 lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb
bitcoin2graphdb-0.4.0 lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb
bitcoin2graphdb-0.3.9 lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb
bitcoin2graphdb-0.3.8 lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb
bitcoin2graphdb-0.3.7 lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb
bitcoin2graphdb-0.3.6 lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb
bitcoin2graphdb-0.3.5 lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb
bitcoin2graphdb-0.3.4 lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb