Class: Bitcoin::Storage::Models::Block

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

Overview

Block retrieved from storage. (see Bitcoin::Protocol::Block)

Constant Summary

Constants inherited from Protocol::Block

Protocol::Block::BLOCK_VERSION_AUXPOW, Protocol::Block::BLOCK_VERSION_CHAIN_END, Protocol::Block::BLOCK_VERSION_CHAIN_START, Protocol::Block::BLOCK_VERSION_DEFAULT

Instance Attribute Summary collapse

Attributes inherited from Protocol::Block

#aux_pow, #hash, #payload

Instance Method Summary collapse

Methods inherited from Protocol::Block

#==, binary_from_hash, binary_from_json, #binary_hash, #bip34_block_height, #block_work, #decimaltarget, #difficulty, from_file, from_hash, from_json, from_json_file, #header_info, #header_to_json, #hextarget, #parse_data, #parse_data_from_io, #prev_block_hex, #recalc_block_hash, #recalc_mrkl_root, #to_hash, #to_json, #to_json_file, #to_payload, #validator, #verify_mrkl_root

Constructor Details

#initialize(store, data) ⇒ Block

Returns a new instance of Block.



19
20
21
22
23
24
25
26
27
# File 'lib/bitcoin/storage/models.rb', line 19

def initialize store, data
  @store = store
  @id = data[:id]
  @depth = data[:depth]
  @chain = data[:chain]
  @work = data[:work]
  @size = data[:size]
  @tx = []
end

Instance Attribute Details

#bitsObject

Returns the value of attribute bits.



16
17
18
# File 'lib/bitcoin/storage/models.rb', line 16

def bits
  @bits
end

#chainObject (readonly)

Returns the value of attribute chain.



17
18
19
# File 'lib/bitcoin/storage/models.rb', line 17

def chain
  @chain
end

#depthObject (readonly)

Returns the value of attribute depth.



17
18
19
# File 'lib/bitcoin/storage/models.rb', line 17

def depth
  @depth
end

#idObject (readonly)

Returns the value of attribute id.



17
18
19
# File 'lib/bitcoin/storage/models.rb', line 17

def id
  @id
end

#mrkl_rootObject

Returns the value of attribute mrkl_root.



16
17
18
# File 'lib/bitcoin/storage/models.rb', line 16

def mrkl_root
  @mrkl_root
end

#nonceObject

Returns the value of attribute nonce.



16
17
18
# File 'lib/bitcoin/storage/models.rb', line 16

def nonce
  @nonce
end

#prev_blockObject

Returns the value of attribute prev_block.



16
17
18
# File 'lib/bitcoin/storage/models.rb', line 16

def prev_block
  @prev_block
end

#sizeObject (readonly)

Returns the value of attribute size.



17
18
19
# File 'lib/bitcoin/storage/models.rb', line 17

def size
  @size
end

#storeObject (readonly)

Returns the value of attribute store.



17
18
19
# File 'lib/bitcoin/storage/models.rb', line 17

def store
  @store
end

#timeObject

Returns the value of attribute time.



16
17
18
# File 'lib/bitcoin/storage/models.rb', line 16

def time
  @time
end

#txObject

Returns the value of attribute tx.



16
17
18
# File 'lib/bitcoin/storage/models.rb', line 16

def tx
  @tx
end

#verObject

Returns the value of attribute ver.



16
17
18
# File 'lib/bitcoin/storage/models.rb', line 16

def ver
  @ver
end

#workObject (readonly)

Returns the value of attribute work.



17
18
19
# File 'lib/bitcoin/storage/models.rb', line 17

def work
  @work
end

Instance Method Details

#get_next_blockObject

get the block that builds upon this one



35
36
37
# File 'lib/bitcoin/storage/models.rb', line 35

def get_next_block
  @store.get_block_by_prev_hash(@hash)
end

#get_prev_blockObject

get the block this one builds upon



30
31
32
# File 'lib/bitcoin/storage/models.rb', line 30

def get_prev_block
  @store.get_block(@prev_block.reverse_hth)
end

#total_feeObject



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

def total_fee
  @total_fee ||= tx.inject(0){ |m,t| m + t.fee }
end

#total_inObject



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

def total_in
  @total_in ||= tx.inject(0){ |m,t| m + t.total_in }
end

#total_outObject



39
40
41
# File 'lib/bitcoin/storage/models.rb', line 39

def total_out
  @total_out ||= tx.inject(0){ |m,t| m + t.total_out }
end