Class: Bitcoin::Storage::Models::TxIn

Inherits:
Protocol::TxIn show all
Defined in:
lib/bitcoin/storage/models.rb

Overview

Transaction input retrieved from storage. (see Bitcoin::Protocol::TxIn

Constant Summary

Constants inherited from Protocol::TxIn

Protocol::TxIn::COINBASE_INDEX, Protocol::TxIn::DEFAULT_SEQUENCE, Protocol::TxIn::NULL_HASH

Instance Attribute Summary collapse

Attributes inherited from Protocol::TxIn

#prev_out, #prev_out_index, #script_sig, #script_sig_length, #sequence, #sig_address, #sig_hash

Instance Method Summary collapse

Methods inherited from Protocol::TxIn

#==, #add_signature_pubkey_script, #coinbase?, from_hash, from_hex_hash, from_io, #parse_data, #parse_data_from_io, #previous_output, #to_hash, #to_payload

Constructor Details

#initialize(store, data) ⇒ TxIn

Returns a new instance of TxIn.



100
101
102
103
104
105
# File 'lib/bitcoin/storage/models.rb', line 100

def initialize store, data
  @store = store
  @id = data[:id]
  @tx_id = data[:tx_id]
  @tx_idx = data[:tx_idx]
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



98
99
100
# File 'lib/bitcoin/storage/models.rb', line 98

def id
  @id
end

#storeObject (readonly)

Returns the value of attribute store.



98
99
100
# File 'lib/bitcoin/storage/models.rb', line 98

def store
  @store
end

#tx_idObject (readonly)

Returns the value of attribute tx_id.



98
99
100
# File 'lib/bitcoin/storage/models.rb', line 98

def tx_id
  @tx_id
end

#tx_idxObject (readonly)

Returns the value of attribute tx_idx.



98
99
100
# File 'lib/bitcoin/storage/models.rb', line 98

def tx_idx
  @tx_idx
end

Instance Method Details

#get_prev_outObject

get the previous output referenced by this input



113
114
115
116
117
118
119
# File 'lib/bitcoin/storage/models.rb', line 113

def get_prev_out
  @prev_tx_out ||= begin
    prev_tx = @store.get_tx(@prev_out.reverse_hth)
    return nil  unless prev_tx
    prev_tx.out[@prev_out_index]
  end
end

#get_txObject

get the transaction this input is in



108
109
110
# File 'lib/bitcoin/storage/models.rb', line 108

def get_tx
  @tx ||= @store.get_tx_by_id(@tx_id)
end