Class: Universa::Connection
- Inherits:
-
Object
- Object
- Universa::Connection
- Defined in:
- lib/universa/client.rb
Overview
The connection to a single Universa node.
Instance Method Summary collapse
-
#get_state(x) ⇒ ContractState
Get contract or hashId state from this single node.
-
#initialize(umi_client) ⇒ Connection
constructor
Do not create it direcly, use Universa::Client#random_connection, Universa::Client#random_connections or Universa::Client#[] instead.
- #inspect ⇒ Object
- #node_number ⇒ Object
-
#ping ⇒ Object
Check the connected node is alive.
-
#ping_node(node_number, timeout: 5000) ⇒ Hash
ping another node from this one.
-
#register_single(contract, timeout = 25) ⇒ ContractState
Register a single contract (on private network or if you have white key allowing free operations) with the current node.
-
#restart ⇒ Object
Attempt to reestablish connection to the node.
- #to_s ⇒ Object
- #umi_client ⇒ Object
-
#url ⇒ Object
node url (IP-based).
Constructor Details
#initialize(umi_client) ⇒ Connection
Do not create it direcly, use Universa::Client#random_connection, Universa::Client#random_connections or Universa::Client#[] instead
143 144 145 |
# File 'lib/universa/client.rb', line 143 def initialize umi_client @client = umi_client end |
Instance Method Details
#get_state(x) ⇒ ContractState
Get contract or hashId state from this single node
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/universa/client.rb', line 197 def get_state x id = case x when HashId x when Contract x.hash_id else raise ArgumentError, "bad argument, want Contract or HashId" end ContractState.new(@client.getState(id)) end |
#inspect ⇒ Object
209 210 211 |
# File 'lib/universa/client.rb', line 209 def inspect "<Universa::Connection:#{url}" end |
#node_number ⇒ Object
151 152 153 |
# File 'lib/universa/client.rb', line 151 def node_number @node_number ||= @client.getNodeNumber() end |
#ping ⇒ Object
Check the connected node is alive. It is adivesd to call #restart on nodes that return false on pings to reestablish connection.
169 170 171 |
# File 'lib/universa/client.rb', line 169 def ping @client.ping end |
#ping_node(node_number, timeout: 5000) ⇒ Hash
ping another node from this one
161 162 163 |
# File 'lib/universa/client.rb', line 161 def ping_node(node_number, timeout: 5000) Hashie::Mash.new(@client.pingNode(node_number, timeout).to_h) end |
#register_single(contract, timeout = 25) ⇒ ContractState
Register a single contract (on private network or if you have white key allowing free operations) with the current node. Client must check returned contract state. It requires “open” network or special key that has a right to register contracts without payment.
190 191 192 |
# File 'lib/universa/client.rb', line 190 def register_single(contract, timeout = 25) ContractState.new(@client.register(contract.packed, timeout * 1000)) end |
#restart ⇒ Object
Attempt to reestablish connection to the node
174 175 176 |
# File 'lib/universa/client.rb', line 174 def restart @client.restart end |
#to_s ⇒ Object
213 214 215 |
# File 'lib/universa/client.rb', line 213 def to_s inspect end |
#umi_client ⇒ Object
147 148 149 |
# File 'lib/universa/client.rb', line 147 def umi_client @client end |
#url ⇒ Object
node url (IP-based)
179 180 181 |
# File 'lib/universa/client.rb', line 179 def url @url ||= @client.get_url end |