Class: CoinOp::Bit::Input

Inherits:
Object
  • Object
show all
Includes:
Encodings
Defined in:
lib/coin-op/bit/input.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Encodings

#base58, #decode_base58, #decode_hex, #hex

Constructor Details

#initialize(options = {}) ⇒ Input

Takes a Hash containing these fields:

  • :transaction - a Transaction instance

  • :index - the index of the input within the transaction

  • :output - a value representing this input’s unspent output

Optionally:

  • script_sig_asm - the string form of the scriptSig for this input



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/coin-op/bit/input.rb', line 21

def initialize(options={})
  @transaction, @index, @output, @network =
    options.values_at :transaction, :index, :output, :network

  script_sig_asm = options[:script_sig_asm]

  unless @output.is_a? Output
    @output = Output.new(@output, network: @network)
  end

  @native = Bitcoin::Protocol::TxIn.new

  # TODO: the reverse is cargo-culted from a function in bitcoin-ruby
  # that doesn't document the reason.  Find the explanation in the bitcoin
  # wiki or in the reference client source and document here.
  @native.prev_out = decode_hex(@output.transaction_hash).reverse
  @native.prev_out_index = @output.index

  if script_sig_asm
    self.script_sig = Bitcoin::Script.binary_from_string(script_sig_asm)
  end
  @signatures = []
end

Instance Attribute Details

#binary_sig_hashObject

Returns the value of attribute binary_sig_hash.



8
9
10
# File 'lib/coin-op/bit/input.rb', line 8

def binary_sig_hash
  @binary_sig_hash
end

#indexObject (readonly)

Returns the value of attribute index.



8
9
10
# File 'lib/coin-op/bit/input.rb', line 8

def index
  @index
end

#nativeObject (readonly)

Returns the value of attribute native.



8
9
10
# File 'lib/coin-op/bit/input.rb', line 8

def native
  @native
end

#outputObject (readonly)

Returns the value of attribute output.



8
9
10
# File 'lib/coin-op/bit/input.rb', line 8

def output
  @output
end

#script_sigObject

Returns the value of attribute script_sig.



8
9
10
# File 'lib/coin-op/bit/input.rb', line 8

def script_sig
  @script_sig
end

#sig_hashObject (readonly)

Returns the value of attribute sig_hash.



8
9
10
# File 'lib/coin-op/bit/input.rb', line 8

def sig_hash
  @sig_hash
end

#signaturesObject (readonly)

Returns the value of attribute signatures.



8
9
10
# File 'lib/coin-op/bit/input.rb', line 8

def signatures
  @signatures
end

Instance Method Details

#to_json(*a) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/coin-op/bit/input.rb', line 64

def to_json(*a)
  {
    :output => self.output,
    :signatures => self.signatures.map {|b| hex(b) },
    :sig_hash => self.sig_hash || "",
    :script_sig => self.script_sig || ""
  }.to_json(*a)
end