class Banano::Node

Attributes

timeout[R]
uri[R]

Public Class Methods

new(uri: Client::LOCAL_ENDPOINT, timeout: Client::DEFAULT_TIMEOUT) click to toggle source
# 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

Public Instance Methods

account_count() click to toggle source

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.

@return [Integer] number of accounts with open blocks.

# File lib/banano/node.rb, line 22
def account_count
  rpc(action: :frontier_count)[:count]
end
Also aliased as: frontier_count
block_count() click to toggle source

The count of all blocks downloaded to the node, and blocks still to be synchronized by the node.

@return [Hash{Symbol=>Integer}] number of blocks and unchecked

synchronizing blocks
# File lib/banano/node.rb, line 32
def block_count
  rpc(action: :block_count)
end
block_count_by_type() click to toggle source

The count of all known blocks by their type.

@return [Hash{Symbol=>Integer}] number of blocks by type

# File lib/banano/node.rb, line 39
def block_count_by_type
  rpc(action: :block_count_type)
end
Also aliased as: block_count_type
block_count_type()
Alias for: block_count_by_type
frontier_count()
Alias for: account_count
info()
Alias for: version
peers() click to toggle source

@return [Hash{Symbol=>String}] information about the node peers

# 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) click to toggle source

All representatives and their voting weight.

@param raw [Boolean] if true return raw balances, else banano units @return [Hash{Symbol=>Integer}] known representatives and their voting weight

# 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() click to toggle source

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..."]

@return [Array<String>] array of representative account ids

# File lib/banano/node.rb, line 76
def representatives_online
  rpc(action: :representatives_online)[:representatives]
end
Also aliased as: reps_online
reps_online()
rpc(action:, params: {}) click to toggle source
# File lib/banano/node.rb, line 11
def rpc(action:, params: {})
  @client.rpc_call(action: action, params: params)
end
sync_progress() click to toggle source

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.

@return [Float] the percentage completeness of the synchronization

process for your node
# 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) click to toggle source

@param limit [Integer] number of synchronizing blocks to return @return [Hash{Symbol=>String}] information about the synchronizing blocks for this node

# 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
Also aliased as: unchecked
unchecked(limit: 1000)
version() click to toggle source

@return [Hash{Symbol=>Integer|String}] version information for this node

# File lib/banano/node.rb, line 112
def version
  rpc(action: :version)
end
Also aliased as: info