Class: BTC::MerkleTree
- Inherits:
-
Object
- Object
- BTC::MerkleTree
- Defined in:
- lib/btcruby/merkle_tree.rb
Instance Attribute Summary collapse
-
#merkle_root ⇒ Object
readonly
Returns the value of attribute merkle_root.
Instance Method Summary collapse
-
#initialize(hashes: nil, transactions: nil, items: nil) ⇒ MerkleTree
constructor
A new instance of MerkleTree.
- #tail_duplicates? ⇒ Boolean
Constructor Details
#initialize(hashes: nil, transactions: nil, items: nil) ⇒ MerkleTree
Returns a new instance of MerkleTree.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/btcruby/merkle_tree.rb', line 6 def initialize(hashes: nil, transactions: nil, items: nil) raise ArgumentError, "None of the arguments are used" if !transactions && !hashes && !items if transactions hashes = transactions.map{|tx| tx.transaction_hash} elsif items hashes = items.map{|item| BTC.hash256(item) } end raise ArgumentError, "Empty list is not allowed" if hashes.size == 0 @hashes = hashes end |
Instance Attribute Details
#merkle_root ⇒ Object (readonly)
Returns the value of attribute merkle_root.
4 5 6 |
# File 'lib/btcruby/merkle_tree.rb', line 4 def merkle_root @merkle_root end |
Instance Method Details
#tail_duplicates? ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/btcruby/merkle_tree.rb', line 21 def tail_duplicates? if !@merkle_root @merkle_root = compute_merkle_root end @tail_duplicates end |