Class: Nanook
- Inherits:
-
Object
- Object
- Nanook
- Defined in:
- lib/nanook.rb,
lib/nanook/key.rb,
lib/nanook/rpc.rb,
lib/nanook/node.rb,
lib/nanook/util.rb,
lib/nanook/block.rb,
lib/nanook/error.rb,
lib/nanook/wallet.rb,
lib/nanook/account.rb,
lib/nanook/version.rb,
lib/nanook/work_peer.rb,
lib/nanook/wallet_account.rb
Overview
Initializing
Connect to the default RPC host at localhost:7076 and with a timeout of 500 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
Classes: Account, Block, Error, Key, Node, Rpc, Util, Wallet, WalletAccount, WorkPeer
Constant Summary collapse
- UNITS =
%i[raw nano].freeze
- DEFAULT_UNIT =
:nano
- VERSION =
'2.5.1'
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.
- #inspect ⇒ String
-
#key(key = nil) ⇒ Nanook::Key
Returns a new instance of Key.
-
#node ⇒ Nanook::Node
Returns a new instance of Node.
-
#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 localhost:7076 with the default timeout of 10s:
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.com:7076", timeout: 10)
53 54 55 |
# File 'lib/nanook.rb', line 53 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).
33 34 35 36 37 38 39 |
# File 'lib/nanook.rb', line 33 def self.default_unit return DEFAULT_UNIT unless defined?(UNIT) raise Nanook::Error, "UNIT #{UNIT} must be one of #{UNITS}" unless UNITS.include?(UNIT.to_sym) UNIT.to_sym end |
Instance Method Details
#account(account) ⇒ Nanook::Account
64 65 66 |
# File 'lib/nanook.rb', line 64 def account(account) Nanook::Account.new(@rpc, account) end |
#block(block) ⇒ Nanook::Block
75 76 77 |
# File 'lib/nanook.rb', line 75 def block(block) Nanook::Block.new(@rpc, block) end |
#inspect ⇒ String
80 81 82 |
# File 'lib/nanook.rb', line 80 def inspect "#{self.class.name}(rpc: #{@rpc.inspect}, object_id: \"#{format('0x00%x', (object_id << 1))}\")" end |
#key(key = nil) ⇒ Nanook::Key
91 92 93 |
# File 'lib/nanook.rb', line 91 def key(key = nil) Nanook::Key.new(@rpc, key) end |
#node ⇒ Nanook::Node
101 102 103 |
# File 'lib/nanook.rb', line 101 def node Nanook::Node.new(@rpc) end |
#wallet(wallet = nil) ⇒ Nanook::Wallet
112 113 114 |
# File 'lib/nanook.rb', line 112 def wallet(wallet = nil) Nanook::Wallet.new(@rpc, wallet) end |