Class: Nanook::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/nanook/node.rb

Instance Method Summary collapse

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_countObject



8
9
10
# File 'lib/nanook/node.rb', line 8

def block_count
  rpc(:block_count)
end

#block_count_typeObject



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_anyObject



20
21
22
# File 'lib/nanook/node.rb', line 20

def bootstrap_any
  rpc(:bootstrap_any).has_key?(:success)
end

#frontier_countObject



24
25
26
# File 'lib/nanook/node.rb', line 24

def frontier_count
  rpc(:frontier_count)[:count]
end

#inspectObject

: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

#peersObject



32
33
34
# File 'lib/nanook/node.rb', line 32

def peers
  rpc(:peers)[:peers]
end

#representativesObject



36
37
38
# File 'lib/nanook/node.rb', line 36

def representatives
  rpc(:representatives)[:representatives]
end

#stopObject



40
41
42
# File 'lib/nanook/node.rb', line 40

def stop
  rpc(:stop).has_key?(:success)
end

#sync_progressObject



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

Returns:

  • (Boolean)


54
55
56
# File 'lib/nanook/node.rb', line 54

def synced?
  rpc(:block_count)[:unchecked] == 0
end

#versionObject



58
59
60
# File 'lib/nanook/node.rb', line 58

def version
  rpc(:version)
end