Module: NanoRpc::AccountsHelper
- Includes:
- ApplicationHelper
- Included in:
- Accounts
- Defined in:
- lib/nano_rpc/helpers/accounts_helper.rb
Instance Method Summary collapse
- #<<(val) ⇒ Object
-
#[](idx) ⇒ Object
Array-like access for NanoRpc::Account.
- #balances ⇒ Object
- #each(&_block) ⇒ Object
- #first ⇒ Object
- #frontiers ⇒ Object
- #last ⇒ Object
- #move(from:, to:) ⇒ Object
- #pending(count:, threshold: nil, source: nil, include_active: nil) ⇒ Object (also: #pending_blocks)
- #pending_balances ⇒ Object (also: #balances_pending)
- #second ⇒ Object
- #size ⇒ Object
- #third ⇒ Object
Instance Method Details
#<<(val) ⇒ Object
47 48 49 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 47 def <<(val) @addresses << val end |
#[](idx) ⇒ Object
Array-like access for NanoRpc::Account
41 42 43 44 45 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 41 def [](idx) return unless @addresses[idx] @account_objects ||= [] @account_objects[idx] ||= NanoRpc::Account.new(@addresses[idx], node: node) end |
#balances ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 5 def balances accounts_balances .balances .each_with_object({}) do |(k, v), hash| hash[k] = v['balance'] end end |
#each(&_block) ⇒ Object
51 52 53 54 55 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 51 def each(&_block) @addresses.each do |address| yield NanoRpc::Account.new(address, node: node) end end |
#first ⇒ Object
57 58 59 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 57 def first self[0] end |
#frontiers ⇒ Object
22 23 24 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 22 def frontiers accounts_frontiers.frontiers end |
#last ⇒ Object
69 70 71 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 69 def last size > 1 ? self[-1] : first end |
#move(from:, to:) ⇒ Object
26 27 28 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 26 def move(from:, to:) account_move(source: from, wallet: to).moved == 1 end |
#pending(count:, threshold: nil, source: nil, include_active: nil) ⇒ Object Also known as: pending_blocks
30 31 32 33 34 35 36 37 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 30 def pending(count:, threshold: nil, source: nil, include_active: nil) accounts_pending( count: count, threshold: threshold, source: source, include_active: include_active ).blocks end |
#pending_balances ⇒ Object Also known as: balances_pending
13 14 15 16 17 18 19 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 13 def pending_balances accounts_balances .balances .each_with_object({}) do |(k, v), hash| hash[k] = v['pending'] end end |
#second ⇒ Object
61 62 63 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 61 def second self[1] end |
#size ⇒ Object
73 74 75 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 73 def size addresses.size end |
#third ⇒ Object
65 66 67 |
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 65 def third self[2] end |