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 =
[:raw, :nano]
- DEFAULT_UNIT =
:nano
- VERSION =
"2.1.0"
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 600s:
Nanook.new
Setting a custom timeout:
Nanook.new(timeout: 600)
Connecting to a custom RPC host and setting a timeout:
Nanook.new("http://ip6-localhost.com:7076", timeout: 600)
54 55 56 |
# File 'lib/nanook.rb', line 54 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).
32 33 34 35 36 37 38 39 40 |
# File 'lib/nanook.rb', line 32 def self.default_unit return DEFAULT_UNIT unless defined?(UNIT) unless UNITS.include?(UNIT.to_sym) raise Nanook::Error.new("UNIT #{UNIT} must be one of #{UNITS}") end UNIT.to_sym end |
Instance Method Details
#account(account) ⇒ Nanook::Account
65 66 67 |
# File 'lib/nanook.rb', line 65 def account(account) Nanook::Account.new(@rpc, account) end |
#block(block) ⇒ Nanook::Block
76 77 78 |
# File 'lib/nanook.rb', line 76 def block(block) Nanook::Block.new(@rpc, block) end |
#inspect ⇒ String
81 82 83 |
# File 'lib/nanook.rb', line 81 def inspect "#{self.class.name}(rpc: #{@rpc.inspect}, object_id: \"#{"0x00%x" % (object_id << 1)}\")" end |
#key(key = nil) ⇒ Nanook::Key
92 93 94 |
# File 'lib/nanook.rb', line 92 def key(key=nil) Nanook::Key.new(@rpc, key) end |
#node ⇒ Nanook::Node
102 103 104 |
# File 'lib/nanook.rb', line 102 def node Nanook::Node.new(@rpc) end |
#wallet(wallet = nil) ⇒ Nanook::Wallet
113 114 115 |
# File 'lib/nanook.rb', line 113 def wallet(wallet=nil) Nanook::Wallet.new(@rpc, wallet) end |