Sha256: b8f71d349edefe307b4070c6502567876acbbd7e80d62e7ae8c54dfb6e2974d3

Contents?: true

Size: 684 Bytes

Versions: 1

Compression:

Stored size: 684 Bytes

Contents

module Bitcoin::Wallet

  # select unspent txouts to be used by the Wallet when creating a new transaction
  class SimpleCoinSelector

    # create coinselector with given +txouts+
    def initialize txouts
      @txouts = txouts
    end

    # select txouts needed to spend +value+ btc (base units)
    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

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bitcoin-ruby-0.0.1 lib/bitcoin/wallet/coinselector.rb