Class: Pool

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/shilling/pool.rb

Overview

pending (unconfirmed) transactions (mem) pool

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transactions = []) ⇒ Pool

Returns a new instance of Pool.



9
10
11
# File 'lib/shilling/pool.rb', line 9

def initialize( transactions=[] )
  @transactions = transactions
end

Class Method Details

.from_json(data) ⇒ Object



36
37
38
39
40
# File 'lib/shilling/pool.rb', line 36

def self.from_json( data )
  ## note: assumes data is an array of block records/objects in json
  transactions = data.map { |h| Tx.from_h( h ) }
  self.new( transactions )
end

Instance Method Details

#<<(tx) ⇒ Object



15
16
17
# File 'lib/shilling/pool.rb', line 15

def <<( tx )
  @transactions << tx
end

#as_jsonObject



32
33
34
# File 'lib/shilling/pool.rb', line 32

def as_json
  @transactions.map { |tx| tx.to_h }
end

#transactionsObject



13
# File 'lib/shilling/pool.rb', line 13

def transactions() @transactions; end

#update!(txns_confirmed) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/shilling/pool.rb', line 20

def update!( txns_confirmed )
  ## find a better name?
  ##  remove confirmed transactions from pool

  ##   document - keep only pending transaction not yet (confirmed) in blockchain ????
  @transactions = @transactions.select do |tx_unconfirmed|
    txns_confirmed.none? { |tx_confirmed| tx_confirmed.id == tx_unconfirmed.id }
  end
end