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



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::.new(@addresses[idx], node: node)
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
54
55
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 51

def each(&_block)
  @addresses.each do |address|
    yield NanoRpc::.new(address, node: node)
  end
end

#firstObject



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

def first
  self[0]
end

#frontiersObject



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

def frontiers
  accounts_frontiers.frontiers
end

#lastObject



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:)
  (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

#secondObject



61
62
63
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 61

def second
  self[1]
end

#sizeObject



73
74
75
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 73

def size
  addresses.size
end

#thirdObject



65
66
67
# File 'lib/nano_rpc/helpers/accounts_helper.rb', line 65

def third
  self[2]
end