Class: Ledger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chain = []) ⇒ Ledger

Returns a new instance of Ledger.



5
6
7
8
9
10
# File 'lib/centralbank/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/centralbank/ledger.rb', line 3

def wallets
  @wallets
end

Instance Method Details

#sufficient_funds?(wallet, amount) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/centralbank/ledger.rb', line 12

def sufficient_funds?( wallet, amount )
  return true   if Centralbank.config.coinbase?( wallet )
  @wallets.has_key?( wallet ) && @wallets[wallet] - amount >= 0
end