Class: Kryolite::Daemon
- Inherits:
-
Object
- Object
- Kryolite::Daemon
- Defined in:
- lib/kryolite/daemon.rb
Instance Method Summary collapse
- #balance(wallet, opts = {}) ⇒ Object
- #block_pos(wallet, height, opts = {}) ⇒ Object
- #block_pow(wallet, height, opts = {}) ⇒ Object
- #blocktemplate(wallet, opts = {}) ⇒ Object
- #get(path, status_or_statuses, opts = {}) ⇒ Object
-
#initialize(url = nil, opts = {}) ⇒ Daemon
constructor
A new instance of Daemon.
- #peers(opts = {}) ⇒ Object
Constructor Details
#initialize(url = nil, opts = {}) ⇒ Daemon
Returns a new instance of Daemon.
5 6 7 8 9 10 11 12 |
# File 'lib/kryolite/daemon.rb', line 5 def initialize url = nil, opts = {} @client = Excon.new url, { persistent: opts[:persistent] || true, connect_timeout: opts[:connect_timeout] || opts[:timeout] || 5, read_timeout: opts[:read_timeout] || opts[:timeout] || 5, write_timeout: opts[:write_timeout] || opts[:timeout] || 5 } end |
Instance Method Details
#balance(wallet, opts = {}) ⇒ Object
46 47 48 |
# File 'lib/kryolite/daemon.rb', line 46 def balance wallet, opts = {} get "/balance?wallet=#{wallet}", 200, opts end |
#block_pos(wallet, height, opts = {}) ⇒ Object
58 59 60 |
# File 'lib/kryolite/daemon.rb', line 58 def block_pos wallet, height, opts = {} get "/block/pos?wallet=#{wallet}&height=#{height}", [200, 204], opts end |
#block_pow(wallet, height, opts = {}) ⇒ Object
54 55 56 |
# File 'lib/kryolite/daemon.rb', line 54 def block_pow wallet, height, opts = {} get "/block/pow?wallet=#{wallet}&height=#{height}", [200, 204], opts end |
#blocktemplate(wallet, opts = {}) ⇒ Object
50 51 52 |
# File 'lib/kryolite/daemon.rb', line 50 def blocktemplate wallet, opts = {} get "/blocktemplate?wallet=#{wallet}", 200, opts end |
#get(path, status_or_statuses, opts = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kryolite/daemon.rb', line 14 def get path, status_or_statuses, opts = {} statuses = if status_or_statuses.is_a? Array status_or_statuses else [status_or_statuses] end response = @client.get({ path: path, idempotent: opts[:idempotent] || true, retry_limit: opts[:retry_limit] || 0, retry_interval: opts[:retry_interval] || 1, retry_errors: opts[:retry_errors] || Excon::DEFAULT_RETRY_ERRORS }) unless statuses.include? response.status raise Kryolite::UnknownStatusError.new "#{path} status was #{response.status}, not #{status}" end if response.status == 200 return JSON.parse(response.body) end nil rescue Excon::Error::Timeout => ex raise Kryolite::TimeoutError.new ex. end |
#peers(opts = {}) ⇒ Object
42 43 44 |
# File 'lib/kryolite/daemon.rb', line 42 def peers opts = {} get "/peers", 200, opts end |