Class: Tapyrus::Block
Constant Summary
Constants included from Util
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
-
#transactions ⇒ Object
Returns the value of attribute transactions.
Class Method Summary collapse
Instance Method Summary collapse
- #block_hash ⇒ Object
-
#calculate_merkle_root ⇒ Object
calculate merkle root from tx list.
- #hash ⇒ Object
-
#height ⇒ Integer
return this block height.
-
#initialize(header, transactions = []) ⇒ Block
constructor
A new instance of Block.
-
#valid_merkle_root? ⇒ Boolean
check the merkle root in the block header matches merkle root calculated from tx list.
Methods included from Util
#byte_to_bit, #calc_checksum, #decode_base58_address, #double_sha256, #encode_base58_address, #hash160, #hmac_sha256, #pack_boolean, #pack_var_int, #pack_var_string, #padding_zero, #sha256, #unpack_boolean, #unpack_var_int, #unpack_var_int_from_io, #unpack_var_string, #valid_address?
Constructor Details
#initialize(header, transactions = []) ⇒ Block
Returns a new instance of Block.
8 9 10 11 |
# File 'lib/tapyrus/block.rb', line 8 def initialize(header, transactions = []) @header = header @transactions = transactions end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
5 6 7 |
# File 'lib/tapyrus/block.rb', line 5 def header @header end |
#transactions ⇒ Object
Returns the value of attribute transactions.
6 7 8 |
# File 'lib/tapyrus/block.rb', line 6 def transactions @transactions end |
Class Method Details
.parse_from_payload(payload) ⇒ Object
13 14 15 |
# File 'lib/tapyrus/block.rb', line 13 def self.parse_from_payload(payload) Tapyrus::Message::Block.parse_from_payload(payload).to_block end |
Instance Method Details
#block_hash ⇒ Object
21 22 23 |
# File 'lib/tapyrus/block.rb', line 21 def block_hash header.block_hash end |
#calculate_merkle_root ⇒ Object
calculate merkle root from tx list.
31 32 33 |
# File 'lib/tapyrus/block.rb', line 31 def calculate_merkle_root Tapyrus::MerkleTree.build_from_leaf(transactions.map(&:tx_hash)).merkle_root end |
#hash ⇒ Object
17 18 19 |
# File 'lib/tapyrus/block.rb', line 17 def hash header.hash end |
#height ⇒ Integer
return this block height. block height is included in coinbase.
37 38 39 |
# File 'lib/tapyrus/block.rb', line 37 def height transactions.first.in.first.out_point.index end |
#valid_merkle_root? ⇒ Boolean
check the merkle root in the block header matches merkle root calculated from tx list.
26 27 28 |
# File 'lib/tapyrus/block.rb', line 26 def valid_merkle_root? calculate_merkle_root == header.merkle_root end |