Class: Sibit::FirstOf

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

Overview

API first of.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2019-2026 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(list, log: Loog::NULL, verbose: false) ⇒ FirstOf

Constructor.



17
18
19
20
21
# File 'lib/sibit/firstof.rb', line 17

def initialize(list, log: Loog::NULL, verbose: false)
  @list = list
  @log = log
  @verbose = verbose
end

Instance Method Details

#balance(address) ⇒ Object

Gets the balance of the address, in satoshi.



31
32
33
34
35
# File 'lib/sibit/firstof.rb', line 31

def balance(address)
  first_of('balance') do |api|
    api.balance(address)
  end
end

#block(hash) ⇒ Object

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



77
78
79
80
81
# File 'lib/sibit/firstof.rb', line 77

def block(hash)
  first_of('block') do |api|
    api.block(hash)
  end
end

#feesObject

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



53
54
55
# File 'lib/sibit/firstof.rb', line 53

def fees
  first_of('fees', &:fees)
end

#height(hash) ⇒ Object

Get the height of the block.



38
39
40
41
42
# File 'lib/sibit/firstof.rb', line 38

def height(hash)
  first_of('height') do |api|
    api.height(hash)
  end
end

#latestObject

Latest block hash.



65
66
67
# File 'lib/sibit/firstof.rb', line 65

def latest
  first_of('latest', &:latest)
end

#next_of(hash) ⇒ Object

Get the hash of the next block.



45
46
47
48
49
# File 'lib/sibit/firstof.rb', line 45

def next_of(hash)
  first_of('next_of') do |api|
    api.next_of(hash)
  end
end

#price(currency = 'USD') ⇒ Object

Current price of BTC in USD (float returned).



24
25
26
27
28
# File 'lib/sibit/firstof.rb', line 24

def price(currency = 'USD')
  first_of('price') do |api|
    api.price(currency)
  end
end

#push(hex) ⇒ Object

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



70
71
72
73
74
# File 'lib/sibit/firstof.rb', line 70

def push(hex)
  first_of('push') do |api|
    api.push(hex)
  end
end

#utxos(keys) ⇒ Object

Fetch all unspent outputs per address.



58
59
60
61
62
# File 'lib/sibit/firstof.rb', line 58

def utxos(keys)
  first_of('utxos') do |api|
    api.utxos(keys)
  end
end