Class: LedgerLite::Ledger
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#send(from, to, amount) ⇒ Object
(also: #transfer)
apply/do single transaction - send payment - do transfer - find a different name - why? why not?.
-
#sufficient?(addr, amount) ⇒ Boolean
(also: #sufficient_funds?)
find a better name - why? why not? e.g.
- #unpack(tx) ⇒ Object
Methods inherited from Base
config, configure, #initialize, #unpack_transactions, #write
Constructor Details
This class inherits a constructor from LedgerLite::Base
Instance Method Details
#send(from, to, amount) ⇒ Object Also known as: transfer
apply/do single transaction - send payment - do transfer
- find a different name - why? why not?
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/ledger-lite/base.rb', line 169 def send( from, to, amount ) if sufficient?( from, amount ) if self.class.config.coinbase?( from ) # note: coinbase has unlimited funds!! ("virtual" built-in money printing address) else @addr[ from ] -= amount end @addr[ to ] ||= 0 @addr[ to ] += amount end end |
#sufficient?(addr, amount) ⇒ Boolean Also known as: sufficient_funds?
find a better name - why? why not?
e.g. use can? funds? sufficient? has_funds?
156 157 158 159 160 161 |
# File 'lib/ledger-lite/base.rb', line 156 def sufficient?( addr, amount ) return true if self.class.config.coinbase?( addr ) ## note: coinbase has unlimited funds!!! @addr.has_key?( addr ) && @addr[addr] - amount >= 0 end |
#unpack(tx) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ledger-lite/base.rb', line 134 def unpack( tx ) ## "unpack" from, to, amount values puts "unpack:" pp tx if tx.is_a?( Hash ) ## support hashes from = tx[:from] to = tx[:to] amount = tx[:amount] else ## assume it's a transaction (tx) struct/class from = tx.from to = tx.to amount = tx.amount end [from,to,amount] end |