Class: Nanook

Inherits:
Object
  • Object
show all
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

UNITS =
[:raw, :nano]
DEFAULT_UNIT =
:nano
VERSION =
"2.4.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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)

Parameters:



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

#rpcNanook::Rpc (readonly)

Returns:



27
28
29
# File 'lib/nanook.rb', line 27

def rpc
  @rpc
end

Class Method Details

.default_unitSymbol

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)

Returns:

  • (Symbol)

    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

Returns a new instance of Account.

Example:

 = Nanook.new.("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpi00000000")

Parameters:

  • account (String)

    the id of the account you want to work with

Returns:



65
66
67
# File 'lib/nanook.rb', line 65

def ()
  Nanook::Account.new(@rpc, )
end

#block(block) ⇒ Nanook::Block

Returns a new instance of Block.

Example:

block = Nanook.new.block("FBF8B0E6623A31AB528EBD839EEAA91CAFD25C12294C46754E45FD017F7939EB")

Parameters:

  • block (String)

    the id/hash of the block you want to work with

Returns:



76
77
78
# File 'lib/nanook.rb', line 76

def block(block)
  Nanook::Block.new(@rpc, block)
end

#inspectString

Returns:

  • (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")

Parameters:

  • key (String) (defaults to: nil)

    a private key

Returns:



92
93
94
# File 'lib/nanook.rb', line 92

def key(key=nil)
  Nanook::Key.new(@rpc, key)
end

#nodeNanook::Node

Returns a new instance of Node.

Example:

node = Nanook.new.node

Returns:



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")

Parameters:

  • wallet (String) (defaults to: nil)

    the id of the wallet you want to work with

Returns:



113
114
115
# File 'lib/nanook.rb', line 113

def wallet(wallet=nil)
  Nanook::Wallet.new(@rpc, wallet)
end

#work_peersNanook::WorkPeer

Returns a new instance of WorkPeer.

Example:

work_peers = Nanook.new.work_peers

Returns:



123
124
125
# File 'lib/nanook.rb', line 123

def work_peers
  Nanook::WorkPeer.new(@rpc)
end