Class: Nanook::Node
Overview
The Nanook::Node
class contains methods to manage your nano node and query its data of the nano network.
Your node is constantly syncing data with other nodes on the network. When your node first starts up after being built, its database will be empty and it will begin synchronizing and downloading data of the nano ledger to its local database. The ledger is the central record of all accounts and transactions. Some of the methods in this class query your node's database formed from the nano ledger, and so the responses are determined by the completeness of your node's database.
You can determine how synchronized your node is with the nano ledger with the #sync_progress method.
Initializing
Initialize this class through the convenient #node method:
node = Nanook.new.node
Or compose the longhand way like this:
rpc_conn = Nanook::Rpc.new
node = Nanook::Node.new(rpc_conn)
Constant Summary
Constants included from Util
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.
-
#bootstrap(address:, port:) ⇒ Boolean
Initialize bootstrap to a specific IP address and port.
-
#bootstrap_any ⇒ Boolean
Initialize multi-connection bootstrap to random peers.
-
#bootstrap_lazy(hash, force: false) ⇒ Boolean
Initialize lazy bootstrap with given block hash.
-
#change_receive_minimum(minimum, unit: Nanook.default_unit) ⇒ Boolean
Sets the receive minimum for wallets on the node.
-
#confirmation_quorum(unit: Nanook.default_unit) ⇒ Hash{Symbol=>String|Integer}
Returns information about node elections settings and observed network state:.
-
#difficulty(include_trend: false) ⇒ Hash{Symbol=>String|Float|Array}
Returns the difficulty values (16 hexadecimal digits string, 64 bit) for the minimum required on the network (network_minimum) as well as the current active difficulty seen on the network (network_current, 5 minute trended average of adjusted difficulty seen on confirmed transactions) which can be used to perform rework for better prioritization of transaction processing.
-
#initialize(rpc) ⇒ Node
constructor
A new instance of Node.
-
#keepalive(address:, port:) ⇒ Boolean
Tells the node to send a keepalive packet to a specific IP address and port.
-
#peers ⇒ Hash{Symbol=>Hash{Symbol=>Integer|String}}
Returns peers information.
-
#receive_minimum(unit: Nanook.default_unit) ⇒ Integer|Float
Returns receive minimum for wallets on the node.
-
#representatives(unit: Nanook.default_unit) ⇒ Hash{Nanook::Account=>Float|Integer}
All representatives and their voting weight.
-
#representatives_online ⇒ Nanook::Account
All online representatives that have voted recently and their weight.
-
#search_pending ⇒ Boolean
Tells the node to look for any account in all available wallets.
-
#stop ⇒ Boolean
Safely shuts down the node.
-
#sync_progress ⇒ Float
The percentage completeness of the synchronization process for your node as it downloads the nano ledger.
-
#synchronizing_blocks(limit: 1000, unit: Nanook.default_unit) ⇒ Hash{Symbol=>String}
(also: #unchecked)
Information about the synchronizing blocks for this node.
- #to_s ⇒ String (also: #inspect)
-
#uptime ⇒ Integer
Returns node uptime in seconds.
-
#version ⇒ Hash{Symbol=>Integer|String}
(also: #info)
Version information for this node.
Constructor Details
#initialize(rpc) ⇒ Node
Returns a new instance of Node.
33 34 35 |
# File 'lib/nanook/node.rb', line 33 def initialize(rpc) @rpc = rpc 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 WalletAccount#receive). All accounts that respond true
to Account#exists? have open blocks in the ledger.
44 45 46 |
# File 'lib/nanook/node.rb', line 44 def account_count rpc(:frontier_count, _access: :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.
Example:
{
count: 100,
unchecked: 10,
cemented: 25
}
62 63 64 |
# File 'lib/nanook/node.rb', line 62 def block_count rpc(:block_count, _coerce: Hash) end |
#bootstrap(address:, port:) ⇒ Boolean
Initialize bootstrap to a specific IP address and port.
76 77 78 |
# File 'lib/nanook/node.rb', line 76 def bootstrap(address:, port:) rpc(:bootstrap, address: address, port: port).key?(:success) end |
#bootstrap_any ⇒ Boolean
Initialize multi-connection bootstrap to random peers
83 84 85 |
# File 'lib/nanook/node.rb', line 83 def bootstrap_any rpc(:bootstrap_any).key?(:success) end |
#bootstrap_lazy(hash, force: false) ⇒ Boolean
Initialize lazy bootstrap with given block hash
93 94 95 |
# File 'lib/nanook/node.rb', line 93 def bootstrap_lazy(hash, force: false) rpc(:bootstrap_lazy, hash: hash, force: force, _access: :started) == 1 end |
#change_receive_minimum(minimum, unit: Nanook.default_unit) ⇒ Boolean
Sets the receive minimum for wallets on the node. The value is in Nano
by default. To specify an amount in raw
, pass the argument unit: :raw.
Example:
account.change_receive_minimum(0.01) # true
329 330 331 332 333 334 335 |
# File 'lib/nanook/node.rb', line 329 def change_receive_minimum(minimum, unit: Nanook.default_unit) validate_unit!(unit) minimum = NANO_to_raw(minimum) if unit == :nano rpc(:receive_minimum_set, amount: minimum).key?(:success) end |
#confirmation_quorum(unit: Nanook.default_unit) ⇒ Hash{Symbol=>String|Integer}
Returns information about node elections settings and observed network state:
-
`quorum_delta`: delta tally required to rollback block
-
`online_weight_quorum_percent`: percentage of online weight for delta
-
`online_weight_minimum`: minimum online weight to confirm block
-
`online_stake_total`: currently observed online total weight
-
`peers_stake_total`: known peers total weight
-
`peers_stake_required`: effective stake needed from directly connected peers for quorum
Example:
node.confirmation_quorum
Example response:
{
"quorum_delta": 43216377.43025059,
"online_weight_quorum_percent": 50,
"online_weight_minimum": 60000000.0",
"online_stake_total": 86432754.86050119,
"peers_stake_total": 84672338.52479072,
"peers_stake_required": 60000000.0"
}
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/nanook/node.rb', line 123 def confirmation_quorum(unit: Nanook.default_unit) validate_unit!(unit) response = rpc(:confirmation_quorum, _coerce: Hash) return response unless unit == :nano response[:quorum_delta] = raw_to_NANO(response[:quorum_delta]) response[:online_weight_minimum] = raw_to_NANO(response[:online_weight_minimum]) response[:online_stake_total] = raw_to_NANO(response[:online_stake_total]) response[:peers_stake_total] = raw_to_NANO(response[:peers_stake_total]) response[:peers_stake_required] = raw_to_NANO(response[:peers_stake_required]) response.compact end |
#difficulty(include_trend: false) ⇒ Hash{Symbol=>String|Float|Array}
Returns the difficulty values (16 hexadecimal digits string, 64 bit) for the minimum required on the network (network_minimum) as well as the current active difficulty seen on the network (network_current, 5 minute trended average of adjusted difficulty seen on confirmed transactions) which can be used to perform rework for better prioritization of transaction processing. A multiplier of the network_current from the base difficulty of network_minimum is also provided for comparison.
Example:
node.difficulty(include_trend: true)
Example response:
{
network_minimum: "ffffffc000000000",
network_current: "ffffffc1816766f2",
multiplier: 1.024089858417128,
difficulty_trend: [
1.156096135149775,
1.190133894573061,
1.135567138563921,
1.000000000000000,
]
}
171 172 173 174 175 176 177 |
# File 'lib/nanook/node.rb', line 171 def difficulty(include_trend: false) rpc(:active_difficulty, include_trend: include_trend, _coerce: Hash).tap do |response| response[:multiplier] = response[:multiplier].to_f response[:difficulty_trend].map!(&:to_f) if response.key?(:difficulty_trend) end end |
#keepalive(address:, port:) ⇒ Boolean
Tells the node to send a keepalive packet to a specific IP address and port.
69 70 71 |
# File 'lib/nanook/node.rb', line 69 def keepalive(address:, port:) rpc(:keepalive, address: address, port: port).key?(:started) end |
#peers ⇒ Hash{Symbol=>Hash{Symbol=>Integer|String}}
Returns peers information.
Example response:
{
:"[::ffff:104.131.102.132]:7075" => {
protocol_version: 20,
node_id: "node_1y7j5rdqhg99uyab1145gu3yur1ax35a3b6qr417yt8cd6n86uiw3d4whty3",
type: "udp"
},
:"[::ffff:104.131.114.102]:7075" => { ... }
}
199 200 201 |
# File 'lib/nanook/node.rb', line 199 def peers rpc(:peers, peer_details: true, _access: :peers, _coerce: Hash) end |
#receive_minimum(unit: Nanook.default_unit) ⇒ Integer|Float
Returns receive minimum for wallets on the node.
Example:
account.receive_minimum # => 0.01
346 347 348 349 350 351 352 353 354 |
# File 'lib/nanook/node.rb', line 346 def receive_minimum(unit: Nanook.default_unit) validate_unit!(unit) amount = rpc(:receive_minimum, _access: :amount) return amount unless unit == :nano raw_to_NANO(amount) end |
#representatives(unit: Nanook.default_unit) ⇒ Hash{Nanook::Account=>Float|Integer}
All representatives and their voting weight.
Example:
node.representatives
Example response:
{
Nanook::Account: 3822372327060170000000000000000000000,
Nanook::Account: 30999999999999999999999999000000,
Nanook::Account: 0
}
219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/nanook/node.rb', line 219 def representatives(unit: Nanook.default_unit) validate_unit!(unit) response = rpc(:representatives, _access: :representatives, _coerce: Hash) r = response.map do |account_id, weight| weight = raw_to_NANO(weight) if unit == :nano [as_account(account_id), weight] end Hash[r] end |
#representatives_online ⇒ Nanook::Account
All online representatives that have voted recently and their weight.
Example:
node.representatives_online # => [Nanook::Account, ...]
240 241 242 243 244 |
# File 'lib/nanook/node.rb', line 240 def representatives_online rpc(:representatives_online, _access: :representatives, _coerce: Array).map do |representative| as_account(representative) end end |
#search_pending ⇒ Boolean
Tells the node to look for any account in all available wallets.
Example:
node.search_pending #=> true
252 253 254 |
# File 'lib/nanook/node.rb', line 252 def search_pending rpc(:search_pending_all).key?(:success) end |
#stop ⇒ Boolean
Safely shuts down the node.
259 260 261 |
# File 'lib/nanook/node.rb', line 259 def stop rpc(:stop).key?(:success) 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.
301 302 303 304 305 306 307 308 309 |
# File 'lib/nanook/node.rb', line 301 def sync_progress response = rpc(:block_count, _coerce: Hash) count = response[:count] unchecked = response[:unchecked] total = count + unchecked count.to_f * 100 / total.to_f end |
#synchronizing_blocks(limit: 1000, unit: Nanook.default_unit) ⇒ Hash{Symbol=>String} Also known as: unchecked
Returns information about the synchronizing blocks for this node.
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/nanook/node.rb', line 268 def synchronizing_blocks(limit: 1000, unit: Nanook.default_unit) validate_unit!(unit) params = { count: limit, json_block: true, _access: :blocks, _coerce: Hash } response = rpc(:unchecked, params).map do |block, info| info[:account] = as_account(info[:account]) if info[:account] info[:link_as_account] = as_account(info[:link_as_account]) if info[:link_as_account] info[:representative] = as_account(info[:representative]) if info[:representative] info[:previous] = as_block(info[:previous]) if info[:previous] info[:link] = as_block(info[:link]) if info[:link] info[:balance] = raw_to_NANO(info[:balance]) if unit == :nano && info[:balance] [as_block(block), info] end Hash[response] end |
#to_s ⇒ String Also known as: inspect
180 181 182 |
# File 'lib/nanook/node.rb', line 180 def to_s self.class.name end |
#uptime ⇒ Integer
Returns node uptime in seconds
314 315 316 |
# File 'lib/nanook/node.rb', line 314 def uptime rpc(:uptime, _access: :seconds, _coerce: Hash) end |
#version ⇒ Hash{Symbol=>Integer|String} Also known as: info
Returns version information for this node.
357 358 359 |
# File 'lib/nanook/node.rb', line 357 def version rpc(:version, _coerce: Hash) end |