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 directly, 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 directly, use Universa::Client#random_connection, Universa::Client#random_connections or Universa::Client#[] instead
152 153 154 |
# File 'lib/universa/client.rb', line 152 def initialize umi_client @client = umi_client end |
Instance Method Details
#get_state(x) ⇒ ContractState
Get contract or hashId state from this single node
206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/universa/client.rb', line 206 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
218 219 220 |
# File 'lib/universa/client.rb', line 218 def inspect "<Universa::Connection:#{url}" end |
#node_number ⇒ Object
160 161 162 |
# File 'lib/universa/client.rb', line 160 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.
178 179 180 |
# File 'lib/universa/client.rb', line 178 def ping @client.ping end |
#ping_node(node_number, timeout: 5000) ⇒ Hash
ping another node from this one
170 171 172 |
# File 'lib/universa/client.rb', line 170 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.
199 200 201 |
# File 'lib/universa/client.rb', line 199 def register_single(contract, timeout = 25) ContractState.new(@client.register(contract.packed, timeout * 1000)) end |
#restart ⇒ Object
Attempt to reestablish connection to the node
183 184 185 |
# File 'lib/universa/client.rb', line 183 def restart @client.restart end |
#to_s ⇒ Object
222 223 224 |
# File 'lib/universa/client.rb', line 222 def to_s inspect end |
#umi_client ⇒ Object
156 157 158 |
# File 'lib/universa/client.rb', line 156 def umi_client @client end |
#url ⇒ Object
node url (IP-based)
188 189 190 |
# File 'lib/universa/client.rb', line 188 def url @url ||= @client.get_url end |