Class: Bitcoin::Builder::TxOutBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/builder.rb

Overview

Create a Bitcoin::Protocol::TxOut used by TxBuilder#output.

t.output 12345, address
t.output 12345, p2sh_address, :script_hash

t.output {|o| o.value 12345; o.to address }

t.output do |o|
  o.value 12345
  o.script {|s| s.recipient address }
end

t.output {|o| o.to "deadbeef", :op_return }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTxOutBuilder

Returns a new instance of TxOutBuilder.



488
489
490
# File 'lib/bitcoin/builder.rb', line 488

def initialize
  @txout = P::TxOut.new(0)
end

Instance Attribute Details

#txoutObject (readonly)

Returns the value of attribute txout.



486
487
488
# File 'lib/bitcoin/builder.rb', line 486

def txout
  @txout
end

Instance Method Details

#script {|c| ... } ⇒ Object

Add a script to the output (see ScriptBuilder).

Yields:

  • (c)


503
504
505
506
507
# File 'lib/bitcoin/builder.rb', line 503

def script &block
  c = ScriptBuilder.new
  yield c
  @txout.pk_script, @txout.redeem_script = c.script, c.redeem_script
end

#to(recipient, type = :address) ⇒ Object

Set recipient address and script type (defaults to :address).



498
499
500
# File 'lib/bitcoin/builder.rb', line 498

def to recipient, type = :address
  @txout.pk_script, @txout.redeem_script = *Bitcoin::Script.send("to_#{type}_script", *recipient)
end

#value(value) ⇒ Object

Set output value (in base units / “satoshis”)



493
494
495
# File 'lib/bitcoin/builder.rb', line 493

def value value
  @txout.value = value
end