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.4.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 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)
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
#rpc ⇒ Nanook::Rpc (readonly)
27 28 29 |
# File 'lib/nanook.rb', line 27 def rpc @rpc end |
Class Method Details
.default_unit ⇒ Symbol
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
Returns a new instance of Account.
Example:
account = Nanook.new.account("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpi00000000")
65 66 67 |
# File 'lib/nanook.rb', line 65 def account(account) Nanook::Account.new(@rpc, account) end |
#block(block) ⇒ Nanook::Block
Returns a new instance of Block.
Example:
block = Nanook.new.block("FBF8B0E6623A31AB528EBD839EEAA91CAFD25C12294C46754E45FD017F7939EB")
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
Returns a new instance of Key.
Example:
key = Nanook.new.key("3068BB1CA04525BB0E416C485FE6A67FD52540227D267CC8B6E8DA958A7FA039")
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
Returns a new instance of Wallet.
Example:
wallet = Nanook.new.wallet("000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A277D81789F3F")
113 114 115 |
# File 'lib/nanook.rb', line 113 def wallet(wallet=nil) Nanook::Wallet.new(@rpc, wallet) end |
#work_peers ⇒ Nanook::WorkPeer
123 124 125 |
# File 'lib/nanook.rb', line 123 def work_peers Nanook::WorkPeer.new(@rpc) end |