class Universa::Connection
The connection to a single Universa
node.
Public Class Methods
Do not create it direcly, use {Client#random_connection}, {Client#random_connections} or {Client#[]} instead
# File lib/universa/client.rb, line 143 def initialize umi_client @client = umi_client end
Public Instance Methods
Get contract or hashId state from this single node @param [Contract | HashId] x what to check @return [ContractState]
# 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
# File lib/universa/client.rb, line 209 def inspect "<Universa::Connection:#{url}" end
# File lib/universa/client.rb, line 151 def node_number @node_number ||= @client.getNodeNumber() end
Check the connected node is alive. It is adivesd to call {restart} on nodes that return false on pings to reestablish connection.
@return true if it is ok
# File lib/universa/client.rb, line 169 def ping @client.ping end
ping another node from this one
@param [Numeric] node_number
to ping @param [Numeric] timeout
@return [Hash] hashie with TCP and UDP fields holding ping time in millis, -1 if not available
# 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 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.
@param [Contract] contract must be sealed ({Contract#seal})
@return [ContractState] of the result. Could contain errors.
# File lib/universa/client.rb, line 190 def register_single(contract, timeout = 25) ContractState.new(@client.register(contract.packed, timeout * 1000)) end
Attempt to reestablish connection to the node
# File lib/universa/client.rb, line 174 def restart @client.restart end
# File lib/universa/client.rb, line 213 def to_s inspect end
# File lib/universa/client.rb, line 147 def umi_client @client end
node url (IP-based)
# File lib/universa/client.rb, line 179 def url @url ||= @client.get_url end