Class: Bitcoin::Wallet::SimpleCoinSelector
- Inherits:
-
Object
- Object
- Bitcoin::Wallet::SimpleCoinSelector
- Defined in:
- lib/bitcoin/wallet/coinselector.rb
Overview
select unspent txouts to be used by the Wallet when creating a new transaction
Instance Method Summary collapse
-
#initialize(txouts) ⇒ SimpleCoinSelector
constructor
create coinselector with given
txouts
. -
#select(value) ⇒ Object
select txouts needed to spend
value
btc (base units).
Constructor Details
#initialize(txouts) ⇒ SimpleCoinSelector
create coinselector with given txouts
9 10 11 |
# File 'lib/bitcoin/wallet/coinselector.rb', line 9 def initialize txouts @txouts = txouts end |
Instance Method Details
#select(value) ⇒ Object
select txouts needed to spend value
btc (base units)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bitcoin/wallet/coinselector.rb', line 14 def select(value) txouts = [] @txouts.each do |txout| begin next if txout.get_next_in next if Bitcoin.namecoin? && txout.type.to_s =~ /^name_/ next unless txout.get_address next unless txout.get_tx.get_block txouts << txout return txouts if txouts.map(&:value).inject(:+) >= value rescue p $! end end nil end |