Class: Sibit::Blockchair
- Inherits:
-
Object
- Object
- Sibit::Blockchair
- Defined in:
- lib/sibit/blockchair.rb
Overview
Btc.com API.
Instance Method Summary collapse
-
#balance(address) ⇒ Object
Gets the balance of the address, in satoshi.
-
#block(_hash) ⇒ Object
This method should fetch a Blockchain block and return as a hash.
-
#fees ⇒ Object
Get recommended fees, in satoshi per byte.
-
#height(_hash) ⇒ Object
The height of the block.
-
#initialize(key: nil, log: Sibit::Log.new, http: Sibit::Http.new, dry: false) ⇒ Blockchair
constructor
Constructor.
-
#latest ⇒ Object
Gets the hash of the latest block.
-
#next_of(_hash) ⇒ Object
Get hash of the block after this one.
-
#price(_currency = 'USD') ⇒ Object
Current price of BTC in USD (float returned).
-
#push(hex) ⇒ Object
Push this transaction (in hex format) to the network.
-
#utxos(_sources) ⇒ Object
Fetch all unspent outputs per address.
Constructor Details
Instance Method Details
#balance(address) ⇒ Object
Gets the balance of the address, in satoshi.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sibit/blockchair.rb', line 66 def balance(address) json = Sibit::Json.new(http: @http, log: @log).get( Iri.new('https://api.blockchair.com/bitcoin/dashboards/address').append(address).fragment(the_key) )['data'][address] if json.nil? @log.info("Address #{address} not found") return 0 end a = json['address'] b = a['balance'] @log.info("The balance of #{address} is #{b} satoshi") b end |
#block(_hash) ⇒ Object
This method should fetch a Blockchain block and return as a hash.
105 106 107 |
# File 'lib/sibit/blockchair.rb', line 105 def block(_hash) raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement block()' end |
#fees ⇒ Object
Get recommended fees, in satoshi per byte.
81 82 83 |
# File 'lib/sibit/blockchair.rb', line 81 def fees raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement fees()' end |
#height(_hash) ⇒ Object
The height of the block.
55 56 57 |
# File 'lib/sibit/blockchair.rb', line 55 def height(_hash) raise Sibit::NotSupportedError, 'Blockchair API doesn\'t provide height()' end |
#latest ⇒ Object
Gets the hash of the latest block.
86 87 88 |
# File 'lib/sibit/blockchair.rb', line 86 def latest raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement latest()' end |
#next_of(_hash) ⇒ Object
Get hash of the block after this one.
60 61 62 63 |
# File 'lib/sibit/blockchair.rb', line 60 def next_of(_hash) # They don't provide next block hash raise Sibit::NotSupportedError, 'Blockchair API doesn\'t provide next_of()' end |
#price(_currency = 'USD') ⇒ Object
Current price of BTC in USD (float returned).
50 51 52 |
# File 'lib/sibit/blockchair.rb', line 50 def price(_currency = 'USD') raise Sibit::NotSupportedError, 'Blockchair doesn\'t provide BTC price' end |
#push(hex) ⇒ Object
Push this transaction (in hex format) to the network.
96 97 98 99 100 101 102 |
# File 'lib/sibit/blockchair.rb', line 96 def push(hex) Sibit::Json.new(http: @http, log: @log).post( Iri.new('https://api.blockchair.com/bitcoin/push/transaction').fragment(the_key), "data=#{hex}" ) @log.info("Transaction (#{hex.length} in hex) has been pushed to Blockchair") end |
#utxos(_sources) ⇒ Object
Fetch all unspent outputs per address.
91 92 93 |
# File 'lib/sibit/blockchair.rb', line 91 def utxos(_sources) raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement utxos()' end |