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
7 8 9 |
# File 'lib/bitcoin/wallet/coinselector.rb', line 7 def initialize txouts @txouts = txouts end |
Instance Method Details
#select(value) ⇒ Object
select txouts needed to spend value
btc (base units)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bitcoin/wallet/coinselector.rb', line 12 def select(value) txouts = [] @txouts.each do |txout| begin next if txout.get_next_in 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 |