Class: Nanook
- Inherits:
-
Object
- Object
- Nanook
- Includes:
- Util
- Defined in:
- lib/nanook.rb,
lib/nanook/rpc.rb,
lib/nanook/node.rb,
lib/nanook/util.rb,
lib/nanook/block.rb,
lib/nanook/errors.rb,
lib/nanook/wallet.rb,
lib/nanook/account.rb,
lib/nanook/version.rb,
lib/nanook/work_peer.rb,
lib/nanook/public_key.rb,
lib/nanook/private_key.rb,
lib/nanook/wallet_account.rb
Overview
Initializing
Connect to the default RPC host at [::1]:7076 and with a timeout of 60 seconds:
nanook = Nanook.new
To connect to another host instead:
nanook = Nanook.new("http://ip6-localhost.com:7076")
To give a specific timeout value:
Nanook.new(timeout: 600)
Nanook.new("http://ip6-localhost.com:7076", timeout: 600)
Defined Under Namespace
Modules: Util Classes: Account, Block, Node, PrivateKey, PublicKey, Rpc, Wallet, WalletAccount, WorkPeer
Constant Summary collapse
- UNITS =
%i[raw nano].freeze
- DEFAULT_UNIT =
:nano
- Error =
Class.new(StandardError)
- ConnectionError =
Class.new(Error)
- NanoUnitError =
Class.new(Error)
- NodeRpcError =
Class.new(Error)
- NodeRpcConfigurationError =
Class.new(NodeRpcError)
- VERSION =
'3.0.0'
Constants included from Util
Instance Attribute Summary collapse
- #rpc ⇒ Nanook::Rpc readonly
Class Method Summary collapse
-
.default_unit ⇒ Symbol
The default unit for amounts to be in.
Instance Method Summary collapse
-
#account(account) ⇒ Nanook::Account
Returns a new instance of Account.
-
#block(block) ⇒ Nanook::Block
Returns a new instance of Block.
-
#initialize(uri = Nanook::Rpc::DEFAULT_URI, timeout: Nanook::Rpc::DEFAULT_TIMEOUT) ⇒ Nanook
constructor
Returns a new instance of Nanook.
-
#network_telemetry ⇒ Nanook::WorkPeer
Return summarized metrics received from other nodes of the whole network.
-
#node ⇒ Nanook::Node
Returns a new instance of Node.
-
#private_key(key = nil) ⇒ Nanook::PrivateKey
Returns a new instance of PrivateKey.
-
#public_key(key) ⇒ Nanook::PublicKey
Returns a new instance of PublicKey.
- #to_s ⇒ String (also: #inspect)
-
#wallet(wallet = nil) ⇒ Nanook::Wallet
Returns a new instance of Wallet.
-
#work_peers ⇒ Nanook::WorkPeer
Returns a new instance of WorkPeer.
Constructor Details
#initialize(uri = Nanook::Rpc::DEFAULT_URI, timeout: Nanook::Rpc::DEFAULT_TIMEOUT) ⇒ Nanook
Returns a new instance of Nanook.
Examples:
Connecting to [::1]:7076 with the default timeout of 60s:
Nanook.new
Setting a custom timeout:
Nanook.new(timeout: 10)
Connecting to a custom RPC host and setting a timeout:
Nanook.new("http://ip6-localhost:7076", timeout: 10)
60 61 62 |
# File 'lib/nanook.rb', line 60 def initialize(uri = Nanook::Rpc::DEFAULT_URI, timeout: Nanook::Rpc::DEFAULT_TIMEOUT) @rpc = Nanook::Rpc.new(uri, timeout: timeout) end |
Instance Attribute Details
Class Method Details
.default_unit ⇒ Symbol
Returns the default unit for amounts to be in. will return DEFAULT_UNIT unless you define a new constant Nanook::UNIT (which must be one of UNITS).
37 38 39 40 41 |
# File 'lib/nanook.rb', line 37 def self.default_unit return DEFAULT_UNIT unless defined?(UNIT) UNIT.to_sym end |
Instance Method Details
#account(account) ⇒ Nanook::Account
71 72 73 |
# File 'lib/nanook.rb', line 71 def account(account) as_account(account) end |
#block(block) ⇒ Nanook::Block
82 83 84 |
# File 'lib/nanook.rb', line 82 def block(block) as_block(block) end |
#network_telemetry ⇒ Nanook::WorkPeer
Return summarized metrics received from other nodes of the whole network.
Example:
Nanook.new.network_telemetry
Example response:
{
block_count: 5777903,
cemented_count: 688819,
unchecked_count: 443468,
account_count: 620750,
bandwidth_cap: 1572864,
peer_count: 32,
protocol_version: 18,
uptime: 556896,
genesis_block: Nanook::Block,
major_version: 21,
minor_version: 0,
patch_version: 0,
pre_release_version: 0,
maker: 0,
timestamp: Time,
active_difficulty: "ffffffcdbf40aa45"
}
171 172 173 174 175 176 |
# File 'lib/nanook.rb', line 171 def network_telemetry response = call_rpc(:telemetry, _coerce: Hash) response[:genesis_block] = as_block(response[:genesis_block]) if response[:genesis_block] response[:timestamp] = as_time(response[:timestamp]) if response[:timestamp] response end |
#node ⇒ Nanook::Node
120 121 122 |
# File 'lib/nanook.rb', line 120 def node Nanook::Node.new(@rpc) end |
#private_key(key = nil) ⇒ Nanook::PrivateKey
Returns a new instance of PrivateKey.
Example:
key = Nanook.new.private_key("3068BB1CA04525BB0E416C485FE6A67FD52540227D267CC8B6E8DA958A7FA039")
99 100 101 |
# File 'lib/nanook.rb', line 99 def private_key(key = nil) as_private_key(key) end |
#public_key(key) ⇒ Nanook::PublicKey
110 111 112 |
# File 'lib/nanook.rb', line 110 def public_key(key) as_public_key(key) end |
#to_s ⇒ String Also known as: inspect
87 88 89 |
# File 'lib/nanook.rb', line 87 def to_s "#{self.class.name}(rpc: #{@rpc})" end |
#wallet(wallet = nil) ⇒ Nanook::Wallet
131 132 133 |
# File 'lib/nanook.rb', line 131 def wallet(wallet = nil) Nanook::Wallet.new(@rpc, wallet) end |