Class: Nanook::Node
- Inherits:
-
Object
- Object
- Nanook::Node
- Defined in:
- lib/nanook/node.rb
Instance Method Summary collapse
- #account_count ⇒ Object (also: #frontier_count)
- #block_count ⇒ Object
- #block_count_type ⇒ Object
- #bootstrap(address:, port:) ⇒ Object
- #bootstrap_any ⇒ Object
-
#initialize(rpc) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #peers ⇒ Object
- #representatives ⇒ Object
- #stop ⇒ Object
- #sync_progress ⇒ Object
- #synced? ⇒ Boolean
- #synchronizing_blocks(limit: 1000) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(rpc) ⇒ Node
Returns a new instance of Node.
4 5 6 |
# File 'lib/nanook/node.rb', line 4 def initialize(rpc) @rpc = rpc end |
Instance Method Details
#account_count ⇒ Object Also known as: frontier_count
8 9 10 |
# File 'lib/nanook/node.rb', line 8 def account_count rpc(:frontier_count)[:count] end |
#block_count ⇒ Object
13 14 15 |
# File 'lib/nanook/node.rb', line 13 def block_count rpc(:block_count) end |
#block_count_type ⇒ Object
17 18 19 |
# File 'lib/nanook/node.rb', line 17 def block_count_type rpc(:block_count_type) end |
#bootstrap(address:, port:) ⇒ Object
21 22 23 |
# File 'lib/nanook/node.rb', line 21 def bootstrap(address:, port:) rpc(:bootstrap, address: address, port: port).has_key?(:success) end |
#bootstrap_any ⇒ Object
25 26 27 |
# File 'lib/nanook/node.rb', line 25 def bootstrap_any rpc(:bootstrap_any).has_key?(:success) end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/nanook/node.rb', line 29 def inspect "#{self.class.name}(object_id: \"#{"0x00%x" % (object_id << 1)}\")" end |
#peers ⇒ Object
33 34 35 |
# File 'lib/nanook/node.rb', line 33 def peers rpc(:peers)[:peers] end |
#representatives ⇒ Object
37 38 39 |
# File 'lib/nanook/node.rb', line 37 def representatives rpc(:representatives)[:representatives] end |
#stop ⇒ Object
41 42 43 |
# File 'lib/nanook/node.rb', line 41 def stop rpc(:stop).has_key?(:success) end |
#sync_progress ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/nanook/node.rb', line 53 def sync_progress response = rpc(:block_count) count = response[:count] unchecked = response[:unchecked] total = count + unchecked count.to_f * 100 / total.to_f end |
#synced? ⇒ Boolean
63 64 65 |
# File 'lib/nanook/node.rb', line 63 def synced? rpc(:block_count)[:unchecked] == 0 end |
#synchronizing_blocks(limit: 1000) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/nanook/node.rb', line 45 def synchronizing_blocks(limit: 1000) response = rpc(:unchecked, count: limit)[:blocks] response = response.map do |block, info| [block, JSON.parse(info).to_symbolized_hash] end Hash[response.sort].to_symbolized_hash end |
#version ⇒ Object
67 68 69 |
# File 'lib/nanook/node.rb', line 67 def version rpc(:version) end |