Class: Bitcoin::Storage::Models::Tx

Inherits:
Protocol::Tx show all
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

Attributes inherited from Protocol::Tx

#in, #out, #payload

Instance Method Summary collapse

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.



46
47
48
49
50
51
# File 'lib/bitcoin/storage/models.rb', line 46

def initialize store, data
  @store = store
  @id = data[:id]
  @blk_id = data[:blk_id]
  super(nil)
end

Instance Attribute Details

#blk_idObject (readonly)

Returns the value of attribute blk_id.



44
45
46
# File 'lib/bitcoin/storage/models.rb', line 44

def blk_id
  @blk_id
end

#hashObject

Returns the value of attribute hash.



43
44
45
# File 'lib/bitcoin/storage/models.rb', line 43

def hash
  @hash
end

#idObject (readonly)

Returns the value of attribute id.



44
45
46
# File 'lib/bitcoin/storage/models.rb', line 44

def id
  @id
end

#lock_timeObject

Returns the value of attribute lock_time.



43
44
45
# File 'lib/bitcoin/storage/models.rb', line 43

def lock_time
  @lock_time
end

#storeObject (readonly)

Returns the value of attribute store.



44
45
46
# File 'lib/bitcoin/storage/models.rb', line 44

def store
  @store
end

#verObject

Returns the value of attribute ver.



43
44
45
# File 'lib/bitcoin/storage/models.rb', line 43

def ver
  @ver
end

Instance Method Details

#confirmationsObject

get the number of blocks that confirm this tx in the main chain



60
61
62
63
# File 'lib/bitcoin/storage/models.rb', line 60

def confirmations
  return 0  unless get_block
  @store.get_head.depth - get_block.depth + 1
end

#get_blockObject

get the block this transaction is in



54
55
56
57
# File 'lib/bitcoin/storage/models.rb', line 54

def get_block
  return nil  unless @blk_id
  @store.get_block_by_id(@blk_id)
end