Sha256: cfdb4a9d4a7b13d7b4a7a00e837369df5b13c1155a76cc43fbdfa217d6b031da

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true
module NanoRpc::AccountsHelper
  include NanoRpc::ApplicationHelper

  def balances
    accounts_balances
      .balances
      .each_with_object({}) do |(k, v), hash|
      hash[k] = v['balance']
    end
  end

  def pending_balances
    accounts_balances
      .balances
      .each_with_object({}) do |(k, v), hash|
      hash[k] = v['pending']
    end
  end
  alias balances_pending pending_balances

  def frontiers
    accounts_frontiers.frontiers
  end

  def move(from:, to:)
    account_move(source: from, wallet: to).moved == 1
  end

  def pending(count:, threshold: nil, source: nil, include_active: nil)
    accounts_pending(
      count: count,
      threshold: threshold,
      source: source,
      include_active: include_active
    ).blocks
  end
  alias pending_blocks pending

  # Array-like access for NanoRpc::Account
  def [](idx)
    return unless @addresses[idx]
    @account_objects ||= []
    @account_objects[idx] ||= NanoRpc::Account.new(@addresses[idx], node: node)
  end

  def <<(val)
    @addresses << val
  end

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

  def first
    self[0]
  end

  def second
    self[1]
  end

  def third
    self[2]
  end

  def last
    size > 1 ? self[-1] : first
  end

  def size
    addresses.size
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nano_rpc-0.21.0 lib/nano_rpc/helpers/accounts_helper.rb
nano_rpc-0.20.0 lib/nano_rpc/helpers/accounts_helper.rb