Class: Ledger

Inherits:
Object
  • Object
show all
Defined in:
lib/tulipmania/ledger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chain = []) ⇒ Ledger



5
6
7
8
9
10
# File 'lib/tulipmania/ledger.rb', line 5

def initialize( chain=[] )
  @wallets = {}
  chain.each do |block|
    apply_transactions( block.transactions )
  end
end

Instance Attribute Details

#walletsObject (readonly)

use addresses - why? why not? for now single address wallet (wallet==address)



3
4
5
# File 'lib/tulipmania/ledger.rb', line 3

def wallets
  @wallets
end

Instance Method Details

#sufficient_tulips?(wallet, qty, what) ⇒ Boolean



12
13
14
15
16
17
18
# File 'lib/tulipmania/ledger.rb', line 12

def sufficient_tulips?( wallet, qty, what )
  return true   if Tulipmania.config.coinbase?( wallet )

  @wallets.has_key?( wallet ) &&
  @wallets[wallet].has_key?( what ) &&
  @wallets[wallet][what] - qty >= 0
end