Class: Banano::Node
- Inherits:
-
Object
- Object
- Banano::Node
- Defined in:
- lib/banano/node.rb
Instance Attribute Summary collapse
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#account_count ⇒ Integer
(also: #frontier_count)
The number of accounts in the nano ledger–essentially all accounts with open blocks.
-
#block_count ⇒ Hash{Symbol=>Integer}
The count of all blocks downloaded to the node, and blocks still to be synchronized by the node.
-
#block_count_by_type ⇒ Hash{Symbol=>Integer}
(also: #block_count_type)
The count of all known blocks by their type.
-
#initialize(uri: Client::LOCAL_ENDPOINT, timeout: Client::DEFAULT_TIMEOUT) ⇒ Node
constructor
A new instance of Node.
-
#peers ⇒ Hash{Symbol=>String}
Information about the node peers.
-
#representatives(raw = true) ⇒ Hash{Symbol=>Integer}
All representatives and their voting weight.
-
#representatives_online ⇒ Array<String>
(also: #reps_online)
All online representatives that have voted recently.
- #rpc(action:, params: {}) ⇒ Object
-
#sync_progress ⇒ Float
The percentage completeness of the synchronization process for your node as it downloads the nano ledger.
-
#synchronizing_blocks(limit: 1000) ⇒ Hash{Symbol=>String}
(also: #unchecked)
Information about the synchronizing blocks for this node.
-
#version ⇒ Hash{Symbol=>Integer|String}
(also: #info)
Version information for this node.
Constructor Details
#initialize(uri: Client::LOCAL_ENDPOINT, timeout: Client::DEFAULT_TIMEOUT) ⇒ Node
Returns a new instance of Node.
7 8 9 |
# File 'lib/banano/node.rb', line 7 def initialize(uri: Client::LOCAL_ENDPOINT, timeout: Client::DEFAULT_TIMEOUT) @client = Client.new(uri: uri, timeout: timeout) end |
Instance Attribute Details
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
5 6 7 |
# File 'lib/banano/node.rb', line 5 def timeout @timeout end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
5 6 7 |
# File 'lib/banano/node.rb', line 5 def uri @uri end |
Instance Method Details
#account_count ⇒ Integer Also known as: frontier_count
The number of accounts in the nano ledger–essentially all accounts with open blocks. An open block is the type of block written to the nano ledger when an account receives its first payment (see Nanook::WalletAccount#receive). All accounts that respond true
to Nanook::Account#exists? have open blocks in the ledger.
22 23 24 |
# File 'lib/banano/node.rb', line 22 def account_count rpc(action: :frontier_count)[:count] end |
#block_count ⇒ Hash{Symbol=>Integer}
The count of all blocks downloaded to the node, and blocks still to be synchronized by the node.
32 33 34 |
# File 'lib/banano/node.rb', line 32 def block_count rpc(action: :block_count) end |
#block_count_by_type ⇒ Hash{Symbol=>Integer} Also known as: block_count_type
The count of all known blocks by their type.
39 40 41 |
# File 'lib/banano/node.rb', line 39 def block_count_by_type rpc(action: :block_count_type) end |
#peers ⇒ Hash{Symbol=>String}
Returns information about the node peers.
47 48 49 50 |
# File 'lib/banano/node.rb', line 47 def peers h = -> (h) { Hash[h.map{ |k,v| [k.to_s, v] }] } h.call(rpc(action: :peers)[:peers]) end |
#representatives(raw = true) ⇒ Hash{Symbol=>Integer}
All representatives and their voting weight.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/banano/node.rb', line 56 def representatives(raw = true) response = rpc(action: :representatives)[:representatives] response = response.delete_if {|_, balance| balance.to_s == '0' } # remove 0 balance reps return response if raw == true r = response.map do |address, balance| [address.to_s, Banano::Unit.raw_to_ban(balance).to_f] end Hash[r] end |
#representatives_online ⇒ Array<String> Also known as: reps_online
All online representatives that have voted recently. Note, due to the design of the nano RPC, this method cannot return the voting weight of the representatives.
Example:
node.representatives_online # => ["ban_111...", "ban_311..."]
76 77 78 |
# File 'lib/banano/node.rb', line 76 def representatives_online rpc(action: :representatives_online)[:representatives] end |
#rpc(action:, params: {}) ⇒ Object
11 12 13 |
# File 'lib/banano/node.rb', line 11 def rpc(action:, params: {}) @client.rpc_call(action: action, params: params) end |
#sync_progress ⇒ Float
The percentage completeness of the synchronization process for your node as it downloads the nano ledger. Note, it’s normal for your progress to not ever reach 100. The closer to 100, the more complete your node’s data is, and so the query methods in this class become more reliable.
101 102 103 104 105 106 107 108 109 |
# File 'lib/banano/node.rb', line 101 def sync_progress response = block_count count = response[:count].to_i unchecked = response[:unchecked].to_i total = count + unchecked count.to_f * 100 / total.to_f end |
#synchronizing_blocks(limit: 1000) ⇒ Hash{Symbol=>String} Also known as: unchecked
Returns information about the synchronizing blocks for this node.
83 84 85 86 87 88 89 90 |
# File 'lib/banano/node.rb', line 83 def synchronizing_blocks(limit: 1000) response = rpc(action: :unchecked, params: {count: limit})[:blocks] # response = response.map do |block, info| # [block, JSON.parse(info).to_symbolized_hash] # end # Hash[response.sort].to_symbolized_hash response end |
#version ⇒ Hash{Symbol=>Integer|String} Also known as: info
Returns version information for this node.
112 113 114 |
# File 'lib/banano/node.rb', line 112 def version rpc(action: :version) end |