Module: NanoRpc::AccountsHelper

Includes:
ApplicationHelper
Included in:
Accounts
Defined in:
lib/nano_rpc/helpers/accounts_helper.rb

Instance Method Summary collapse

Instance Method Details

#<<(val) ⇒ Object



46
47
48
49
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 46

def <<(val)
  @to_a = nil
  @addresses << val
end

#[](idx) ⇒ Object

Array-like access for NanoRpc::Account



41
42
43
44
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 41

def [](idx)
  return unless addresses[idx]
  to_a[idx]
end

#balancesObject



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
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 51

def each(&_block)
  to_a.each { || yield  }
end

#frontiersObject



22
23
24
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 22

def frontiers
  accounts_frontiers.frontiers
end

#move(from:, to:) ⇒ Object



26
27
28
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 26

def move(from:, to:)
  (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_balancesObject 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

#to_aObject



55
56
57
58
59
60
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 55

def to_a
  @to_a ||=
    addresses.map do |address|
      NanoRpc::Account.new(address, node: node)
    end
end