Class: Sibit::Earn

Inherits:
Object
  • Object
show all
Defined in:
lib/sibit/earn.rb

Overview

Blockchain.info API.

Instance Method Summary collapse

Constructor Details

#initialize(log: Sibit::Log.new, http: Sibit::Http.new, dry: false) ⇒ Earn

Constructor.



40
41
42
43
44
# File 'lib/sibit/earn.rb', line 40

def initialize(log: Sibit::Log.new, http: Sibit::Http.new, dry: false)
  @http = http
  @log = log
  @dry = dry
end

Instance Method Details

#balance(_address) ⇒ Object

Gets the balance of the address, in satoshi.



52
53
54
# File 'lib/sibit/earn.rb', line 52

def balance(_address)
  raise Sibit::NotSupportedError, 'balance() doesn\'t work here'
end

#block(_hash) ⇒ Object

This method should fetch a Blockchain block and return as a hash.



98
99
100
# File 'lib/sibit/earn.rb', line 98

def block(_hash)
  raise Sibit::NotSupportedError, 'block() doesn\'t work here'
end

#feesObject

Get recommended fees, in satoshi per byte. The method returns a hash: { S: 12, M: 45, L: 100, XL: 200 }



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sibit/earn.rb', line 68

def fees
  json = Sibit::Json.new(http: @http, log: @log).get(
    Iri.new('https://bitcoinfees.earn.com/api/v1/fees/recommended')
  )
  @log.info("Current recommended Bitcoin fees: \
#{json['hourFee']}/#{json['halfHourFee']}/#{json['fastestFee']} sat/byte")
  {
    S: json['hourFee'] / 3,
    M: json['hourFee'],
    L: json['halfHourFee'],
    XL: json['fastestFee']
  }
end

#height(_hash) ⇒ Object

The height of the block.



62
63
64
# File 'lib/sibit/earn.rb', line 62

def height(_hash)
  raise Sibit::NotSupportedError, 'Earn API doesn\'t provide height()'
end

#latestObject

Gets the hash of the latest block.



93
94
95
# File 'lib/sibit/earn.rb', line 93

def latest
  raise Sibit::NotSupportedError, 'latest() doesn\'t work here'
end

#next_of(_hash) ⇒ Object

Get hash of the block after this one.



57
58
59
# File 'lib/sibit/earn.rb', line 57

def next_of(_hash)
  raise Sibit::NotSupportedError, 'Earn.com API doesn\'t provide next_of()'
end

#price(_currency) ⇒ Object

Current price of BTC in USD (float returned).



47
48
49
# File 'lib/sibit/earn.rb', line 47

def price(_currency)
  raise Sibit::NotSupportedError, 'price() doesn\'t work here'
end

#push(_hex) ⇒ Object

Push this transaction (in hex format) to the network.



88
89
90
# File 'lib/sibit/earn.rb', line 88

def push(_hex)
  raise Sibit::NotSupportedError, 'Not implemented yet'
end

#utxos(_sources) ⇒ Object

Fetch all unspent outputs per address.



83
84
85
# File 'lib/sibit/earn.rb', line 83

def utxos(_sources)
  raise Sibit::NotSupportedError, 'Not implemented yet'
end