Class: Bitcoin::Protocol::TxIn

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (TxIn) initialize(*args)

A new instance of TxIn



8
9
10
11
# File 'lib/bitcoin/protocol/txin.rb', line 8

def initialize *args
  @prev_out, @prev_out_index, @script_sig_length,
  @script_sig, @sequence = *args
end

Instance Attribute Details

- (Object) prev_out

Returns the value of attribute prev_out



6
7
8
# File 'lib/bitcoin/protocol/txin.rb', line 6

def prev_out
  @prev_out
end

- (Object) prev_out_index

Returns the value of attribute prev_out_index



6
7
8
# File 'lib/bitcoin/protocol/txin.rb', line 6

def prev_out_index
  @prev_out_index
end

- (Object) script_sig

Returns the value of attribute script_sig



6
7
8
# File 'lib/bitcoin/protocol/txin.rb', line 6

def script_sig
  @script_sig
end

- (Object) script_sig_length

Returns the value of attribute script_sig_length



6
7
8
# File 'lib/bitcoin/protocol/txin.rb', line 6

def script_sig_length
  @script_sig_length
end

- (Object) sequence

Returns the value of attribute sequence



6
7
8
# File 'lib/bitcoin/protocol/txin.rb', line 6

def sequence
  @sequence
end

Instance Method Details

- (Object) [](idx)



13
14
15
16
17
18
19
20
21
# File 'lib/bitcoin/protocol/txin.rb', line 13

def [] idx
  case idx
  when 0 then @prev_out
  when 1 then @prev_out_index
  when 2 then @script_sig_length
  when 3 then @script_sig
  when 4 then @sequence
  end
end

- (Object) []=(idx, val)



23
24
25
26
27
28
29
30
31
# File 'lib/bitcoin/protocol/txin.rb', line 23

def []= idx, val
  case idx
  when 0 then @prev_out = val
  when 1 then @prev_out_index = val
  when 2 then @script_sig_length = val
  when 3 then @script_sig = val
  when 4 then @sequence = val
  end
end

- (Boolean) coinbase?

Returns:

  • (Boolean)


49
50
51
# File 'lib/bitcoin/protocol/txin.rb', line 49

def coinbase?
  (@prev_out_index == 4294967295) && (@prev_out == "\x00"*32)
end

- (Object) parse_data(data)

parse raw binary data for transaction input



34
35
36
37
38
39
40
41
42
# File 'lib/bitcoin/protocol/txin.rb', line 34

def parse_data(data)
  idx = 0
  @prev_out, @prev_out_index = data[idx...idx+=36].unpack("a32I")
  @script_sig_length, tmp = Protocol.unpack_var_int(data[idx..-1])
  idx += data[idx..-1].bytesize - tmp.bytesize
  @script_sig = data[idx...idx+=@script_sig_length]
  @sequence = data[idx...idx+=4]
  idx
end

- (Object) previous_output

previous output in hex



45
46
47
# File 'lib/bitcoin/protocol/txin.rb', line 45

def previous_output
  @prev_out.reverse.unpack("H*")[0]
end