class Tapyrus::Block
Attributes
header[RW]
transactions[RW]
Public Class Methods
new(header, transactions = [])
click to toggle source
# File lib/tapyrus/block.rb, line 8 def initialize(header, transactions = []) @header = header @transactions = transactions end
parse_from_payload(payload)
click to toggle source
# File lib/tapyrus/block.rb, line 13 def self.parse_from_payload(payload) Tapyrus::Message::Block.parse_from_payload(payload).to_block end
Public Instance Methods
block_hash()
click to toggle source
# File lib/tapyrus/block.rb, line 21 def block_hash header.block_hash end
calculate_merkle_root()
click to toggle source
calculate merkle root from tx list.
# File lib/tapyrus/block.rb, line 31 def calculate_merkle_root Tapyrus::MerkleTree.build_from_leaf(transactions.map(&:tx_hash)).merkle_root end
hash()
click to toggle source
# File lib/tapyrus/block.rb, line 17 def hash header.hash end
height()
click to toggle source
return this block height. block height is included in coinbase. @return [Integer] block height.
# File lib/tapyrus/block.rb, line 37 def height transactions.first.in.first.out_point.index end
valid_merkle_root?()
click to toggle source
check the merkle root in the block header matches merkle root calculated from tx list.
# File lib/tapyrus/block.rb, line 26 def valid_merkle_root? calculate_merkle_root == header.merkle_root end