class XRBP::NodeStore::SQLDB::Ledgers

Public Class Methods

new(sql_db) click to toggle source
# File lib/xrbp/nodestore/sqldb.rb, line 34
def initialize(sql_db)
  @sql_db = sql_db
end

Public Instance Methods

all() click to toggle source

TODO: remove memoization, define first(n), last(n) methods

# File lib/xrbp/nodestore/sqldb.rb, line 70
def all
  @all ||= @sql_db.ledger_db.execute("select * from Ledgers order by LedgerSeq asc")
                            .collect { |row| from_db(row) }
end
between(before, after) click to toggle source
# File lib/xrbp/nodestore/sqldb.rb, line 38
def between(before, after)
  @sql_db.ledger_db.execute("select * from Ledgers where ClosingTime >= ? and ClosingTime <= ?",
                                                                             before.to_xrp_time,
                                                                              after.to_xrp_time)
                   .collect { |row| from_db(row) }
end
count()
Alias for: size
each() { |row| ... } click to toggle source
# File lib/xrbp/nodestore/sqldb.rb, line 63
def each
  all.each do |row|
    yield row
  end
end
first() click to toggle source
# File lib/xrbp/nodestore/sqldb.rb, line 53
def first
  @sql_db.ledger_db.execute("select LedgerSeq from Ledgers order by LedgerSeq asc limit 1").first.first
end
hash_for_seq(seq) click to toggle source
# File lib/xrbp/nodestore/sqldb.rb, line 45
def hash_for_seq(seq)
  @sql_db.ledger_db.execute("select LedgerHash from Ledgers where LedgerSeq = ?", seq).first.first
end
last() click to toggle source
# File lib/xrbp/nodestore/sqldb.rb, line 57
def last
  @sql_db.ledger_db.execute("select LedgerSeq from Ledgers order by LedgerSeq desc limit 1").first.first
end
size() click to toggle source
# File lib/xrbp/nodestore/sqldb.rb, line 49
def size
  @sql_db.ledger_db.execute("select count(ROWID) from Ledgers").first.first
end
Also aliased as: count

Private Instance Methods

from_db(row) click to toggle source
# File lib/xrbp/nodestore/sqldb.rb, line 77
def from_db(row)
  {:hash              => row[0],
   :seq               => row[1],
   :prev_hash         => row[2],
   :total_coins       => row[3],
   :closing_time      => row[4].from_xrp_time,
   :prev_closing_time => row[5].from_xrp_time,
   :close_time_res    => row[6],
   :close_flags       => row[7],
   :account_set_hash  => row[8],
   :trans_set_hash    => row[9]}
end