Module: BTC::TransactionBuilder::Provider
- Included in:
- BlockProvider
- Defined in:
- lib/btcruby/transaction_builder/provider.rb
Overview
Interface for providing unspent outputs to transaction builder.
You can use it instead of Enumerable attribute unspent_outputs to customize which unspents to be used.
Defined Under Namespace
Classes: BlockProvider
Class Method Summary collapse
-
.new(&block) ⇒ Object
Creates a block-based provider: txbuilder.provider = TransactionBuilder::Provider.new {|builder| [...] }.
Instance Method Summary collapse
- #btc_txbuilder_outpoint_id(output) ⇒ Object
-
#consume_unspent_output(output) ⇒ Object
Allows provider to track unspents that are actually used by the transaction builder, so it can avoid providing the same outputs to another transaction builder.
- #consumed_unspent_output?(output) ⇒ Boolean
-
#unspent_outputs(transaction_builder) ⇒ Object
Returns an Enumerable object yielding unspent outputs for the given addresses.
Class Method Details
.new(&block) ⇒ Object
Creates a block-based provider: txbuilder.provider = TransactionBuilder::Provider.new {|builder| [...] }
38 39 40 |
# File 'lib/btcruby/transaction_builder/provider.rb', line 38 def self.new(&block) BlockProvider.new(&block) end |
Instance Method Details
#btc_txbuilder_outpoint_id(output) ⇒ Object
30 31 32 33 34 |
# File 'lib/btcruby/transaction_builder/provider.rb', line 30 def btc_txbuilder_outpoint_id(output) raise ArgumentError, "Output must have txid" if !output.transaction_hash raise ArgumentError, "Output must have txid" if !output.index output.outpoint_id end |
#consume_unspent_output(output) ⇒ Object
Allows provider to track unspents that are actually used by the transaction builder, so it can avoid providing the same outputs to another transaction builder.
18 19 20 21 22 23 |
# File 'lib/btcruby/transaction_builder/provider.rb', line 18 def consume_unspent_output(output) #puts "========> BTCRUBY: Provider #{self.object_id} consumes output #{btc_txbuilder_outpoint_id(output)}." @btc_txbuilder_provider_consumed_unspent_outputs ||= {} @btc_txbuilder_provider_consumed_unspent_outputs[btc_txbuilder_outpoint_id(output)] = 1 self end |
#consumed_unspent_output?(output) ⇒ Boolean
25 26 27 28 |
# File 'lib/btcruby/transaction_builder/provider.rb', line 25 def consumed_unspent_output?(output) #puts "========> BTCRUBY: Does Provider #{self.object_id} have output #{btc_txbuilder_outpoint_id(output)}?" !!((@btc_txbuilder_provider_consumed_unspent_outputs ||= {})[btc_txbuilder_outpoint_id(output)]) end |
#unspent_outputs(transaction_builder) ⇒ Object
Returns an Enumerable object yielding unspent outputs for the given addresses.
Each unspent output is a BTC::TransactionOutput instance with non-nil transaction_hash and index attributes.
Additional information about outputs and fees may be used to optimize the set of unspents.
If builder's outputs_amount is nil, all available unspent outputs are expected to be returned.
12 13 14 |
# File 'lib/btcruby/transaction_builder/provider.rb', line 12 def unspent_outputs(transaction_builder) [] end |