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

#account_countObject Also known as: frontier_count



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

def 
  rpc(:frontier_count)[:count]
end

#block_countObject



13
14
15
# File 'lib/nanook/node.rb', line 13

def block_count
  rpc(:block_count)
end

#block_count_typeObject



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_anyObject



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

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

#inspectObject



29
30
31
# File 'lib/nanook/node.rb', line 29

def inspect
  "#{self.class.name}(object_id: \"#{"0x00%x" % (object_id << 1)}\")"
end

#peersObject



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

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

#representativesObject



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

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

#stopObject



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

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

#sync_progressObject



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

Returns:

  • (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

#versionObject



67
68
69
# File 'lib/nanook/node.rb', line 67

def version
  rpc(:version)
end