Class: Bitcoin::Storage::Models::Tx
- Inherits:
-
Protocol::Tx
- Object
- Protocol::Tx
- Bitcoin::Storage::Models::Tx
- Defined in:
- lib/bitcoin/storage/models.rb
Overview
Transaction retrieved from storage. (see Bitcoin::Protocol::Tx)
Constant Summary
Constants inherited from Protocol::Tx
Protocol::Tx::DEFAULT_BLOCK_PRIORITY_SIZE, Protocol::Tx::SIGHASH_TYPE
Instance Attribute Summary collapse
-
#blk_id ⇒ Object
readonly
Returns the value of attribute blk_id.
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#idx ⇒ Object
readonly
Returns the value of attribute idx.
-
#lock_time ⇒ Object
Returns the value of attribute lock_time.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#ver ⇒ Object
Returns the value of attribute ver.
Attributes inherited from Protocol::Tx
Instance Method Summary collapse
-
#confirmations ⇒ Object
get the number of blocks that confirm this tx in the main chain.
- #fee ⇒ Object
-
#get_block ⇒ Object
get the block this transaction is in.
-
#initialize(store, data) ⇒ Tx
constructor
A new instance of Tx.
-
#total_in ⇒ Object
if tx_in is coinbase, set in value as total_out, fee could be 0.
- #total_out ⇒ Object
Methods inherited from Protocol::Tx
#==, #add_in, #add_out, binary_from_hash, binary_from_json, #binary_hash, #calculate_minimum_fee, from_file, from_hash, from_json, from_json_file, #hash_from_payload, #is_coinbase?, #minimum_block_fee, #minimum_relay_fee, #parse_data_from_io, #signature_hash_for_input, #to_hash, #to_json, #to_json_file, #to_payload, #validator, #verify_input_signature
Constructor Details
#initialize(store, data) ⇒ Tx
Returns a new instance of Tx.
58 59 60 61 62 63 64 65 |
# File 'lib/bitcoin/storage/models.rb', line 58 def initialize store, data @store = store @id = data[:id] @blk_id = data[:blk_id] @size = data[:size] @idx = data[:idx] super(nil) end |
Instance Attribute Details
#blk_id ⇒ Object (readonly)
Returns the value of attribute blk_id.
56 57 58 |
# File 'lib/bitcoin/storage/models.rb', line 56 def blk_id @blk_id end |
#hash ⇒ Object
Returns the value of attribute hash.
55 56 57 |
# File 'lib/bitcoin/storage/models.rb', line 55 def hash @hash end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
56 57 58 |
# File 'lib/bitcoin/storage/models.rb', line 56 def id @id end |
#idx ⇒ Object (readonly)
Returns the value of attribute idx.
56 57 58 |
# File 'lib/bitcoin/storage/models.rb', line 56 def idx @idx end |
#lock_time ⇒ Object
Returns the value of attribute lock_time.
55 56 57 |
# File 'lib/bitcoin/storage/models.rb', line 55 def lock_time @lock_time end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
56 57 58 |
# File 'lib/bitcoin/storage/models.rb', line 56 def size @size end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
56 57 58 |
# File 'lib/bitcoin/storage/models.rb', line 56 def store @store end |
#ver ⇒ Object
Returns the value of attribute ver.
55 56 57 |
# File 'lib/bitcoin/storage/models.rb', line 55 def ver @ver end |
Instance Method Details
#confirmations ⇒ Object
get the number of blocks that confirm this tx in the main chain
74 75 76 77 |
# File 'lib/bitcoin/storage/models.rb', line 74 def confirmations return 0 unless get_block @store.get_head.depth - get_block.depth + 1 end |
#fee ⇒ Object
90 91 92 |
# File 'lib/bitcoin/storage/models.rb', line 90 def fee @fee ||= total_in - total_out end |
#get_block ⇒ Object
get the block this transaction is in
68 69 70 71 |
# File 'lib/bitcoin/storage/models.rb', line 68 def get_block return nil unless @blk_id @block ||= @store.get_block_by_id(@blk_id) end |
#total_in ⇒ Object
if tx_in is coinbase, set in value as total_out, fee could be 0
84 85 86 87 88 |
# File 'lib/bitcoin/storage/models.rb', line 84 def total_in @total_in ||= self.in.inject(0){ |m, input| m + (input.coinbase? ? total_out : (input.get_prev_out.try(:value) || 0)) } end |
#total_out ⇒ Object
79 80 81 |
# File 'lib/bitcoin/storage/models.rb', line 79 def total_out @total_out ||= self.out.inject(0){ |e, o| e + o.value } end |