Class: Nanook::Node
- Inherits:
-
Object
- Object
- Nanook::Node
- Defined in:
- lib/nanook/node.rb
Instance Method Summary collapse
- #block_count ⇒ Object
- #block_count_type ⇒ Object
- #bootstrap(address:, port:) ⇒ Object
- #bootstrap_any ⇒ Object
- #frontier_count ⇒ Object
-
#initialize(rpc) ⇒ Node
constructor
A new instance of Node.
-
#inspect ⇒ Object
:nodoc:.
- #peers ⇒ Object
- #representatives ⇒ Object
- #stop ⇒ Object
- #sync_progress ⇒ Object
- #synced? ⇒ Boolean
- #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
#block_count ⇒ Object
8 9 10 |
# File 'lib/nanook/node.rb', line 8 def block_count rpc(:block_count) end |
#block_count_type ⇒ Object
12 13 14 |
# File 'lib/nanook/node.rb', line 12 def block_count_type rpc(:block_count_type) end |
#bootstrap(address:, port:) ⇒ Object
16 17 18 |
# File 'lib/nanook/node.rb', line 16 def bootstrap(address:, port:) rpc(:bootstrap, address: address, port: port).has_key?(:success) end |
#bootstrap_any ⇒ Object
20 21 22 |
# File 'lib/nanook/node.rb', line 20 def bootstrap_any rpc(:bootstrap_any).has_key?(:success) end |
#frontier_count ⇒ Object
24 25 26 |
# File 'lib/nanook/node.rb', line 24 def frontier_count rpc(:frontier_count)[:count] end |
#inspect ⇒ Object
:nodoc:
28 29 30 |
# File 'lib/nanook/node.rb', line 28 def inspect # :nodoc: "#{self.class.name}(object_id: \"#{"0x00%x" % (object_id << 1)}\")" end |
#peers ⇒ Object
32 33 34 |
# File 'lib/nanook/node.rb', line 32 def peers rpc(:peers)[:peers] end |
#representatives ⇒ Object
36 37 38 |
# File 'lib/nanook/node.rb', line 36 def representatives rpc(:representatives)[:representatives] end |
#stop ⇒ Object
40 41 42 |
# File 'lib/nanook/node.rb', line 40 def stop rpc(:stop).has_key?(:success) end |
#sync_progress ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/nanook/node.rb', line 44 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
54 55 56 |
# File 'lib/nanook/node.rb', line 54 def synced? rpc(:block_count)[:unchecked] == 0 end |
#version ⇒ Object
58 59 60 |
# File 'lib/nanook/node.rb', line 58 def version rpc(:version) end |