Class: Bitcoin::Builder::TxInBuilder
- Inherits:
-
Object
- Object
- Bitcoin::Builder::TxInBuilder
- Defined in:
- lib/bitcoin/builder.rb
Overview
create a Bitcoin::Protocol::TxIn used by TxBuilder#input.
inputs need a #prev_out tx and #prev_out_index of the output they spend.
Instance Attribute Summary collapse
-
#coinbase_data ⇒ Object
readonly
Returns the value of attribute coinbase_data.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#coinbase(data = nil) ⇒ Object
specify that this is a coinbase input.
-
#initialize ⇒ TxInBuilder
constructor
A new instance of TxInBuilder.
-
#prev_out(tx, idx = nil) ⇒ Object
previous transaction that contains the output we want to use.
-
#prev_out_index(i) ⇒ Object
index of the output in the #prev_out transaction.
-
#sequence(s) ⇒ Object
specify sequence.
-
#signature_key(key) ⇒ Object
Bitcoin::Key used to sign the signature_hash for the input.
-
#txin ⇒ Object
create the txin according to values specified via DSL.
Constructor Details
#initialize ⇒ TxInBuilder
Returns a new instance of TxInBuilder.
207 208 209 |
# File 'lib/bitcoin/builder.rb', line 207 def initialize @txin = P::TxIn.new end |
Instance Attribute Details
#coinbase_data ⇒ Object (readonly)
Returns the value of attribute coinbase_data.
205 206 207 |
# File 'lib/bitcoin/builder.rb', line 205 def coinbase_data @coinbase_data end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
205 206 207 |
# File 'lib/bitcoin/builder.rb', line 205 def key @key end |
Instance Method Details
#coinbase(data = nil) ⇒ Object
specify that this is a coinbase input. optionally set data
.
233 234 235 236 237 |
# File 'lib/bitcoin/builder.rb', line 233 def coinbase data = nil @coinbase_data = data || OpenSSL::Random.random_bytes(32) @prev_out = nil @prev_out_index = 4294967295 end |
#prev_out(tx, idx = nil) ⇒ Object
previous transaction that contains the output we want to use.
212 213 214 |
# File 'lib/bitcoin/builder.rb', line 212 def prev_out tx, idx = nil @prev_out, @prev_out_index = tx, idx end |
#prev_out_index(i) ⇒ Object
index of the output in the #prev_out transaction.
217 218 219 |
# File 'lib/bitcoin/builder.rb', line 217 def prev_out_index i @prev_out_index = i end |
#sequence(s) ⇒ Object
specify sequence. this is usually not needed.
222 223 224 |
# File 'lib/bitcoin/builder.rb', line 222 def sequence s @sequence = s end |
#signature_key(key) ⇒ Object
Bitcoin::Key used to sign the signature_hash for the input. see Bitcoin::Script.signature_hash_for_input and Bitcoin::Key.sign.
228 229 230 |
# File 'lib/bitcoin/builder.rb', line 228 def signature_key key @key = key end |
#txin ⇒ Object
create the txin according to values specified via DSL
240 241 242 243 244 245 |
# File 'lib/bitcoin/builder.rb', line 240 def txin @txin.prev_out = (@prev_out ? @prev_out.binary_hash : "\x00"*32) @txin.prev_out_index = @prev_out_index @txin.sequence = @sequence || "\xff\xff\xff\xff" @txin end |