Module: Nano::Hash
Overview
The Hash module is responsible for producing a block hash given a Block object.
Constant Summary collapse
- STATE_BLOCK_PREAMBLE_BITS =
Nano::Utils.bytes_to_bin( Array.new(32) {|i| i == 31 ? 6 : 0} ).freeze
Instance Method Summary collapse
-
#hash_block(block) ⇒ String
This method will produce a hash for the given block.
Instance Method Details
#hash_block(block) ⇒ String
This method will produce a hash for the given block
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nano/hash.rb', line 22 def hash_block(block) account_bits = Nano::Utils.hex_to_bin( Nano::Key.derive_public_key(block.account) ) previous_bits = Nano::Utils.hex_to_bin( block.previous ) representative_bits = Nano::Utils.hex_to_bin( Nano::Key.derive_public_key(block.representative) ) balance_bits = Nano::Utils.hex_to_bin( Nano::Unit.convert(block.balance, :raw, :hex) ) link_bits = Nano::Utils.hex_to_bin( block.link ) bits = STATE_BLOCK_PREAMBLE_BITS + account_bits + previous_bits + representative_bits + balance_bits + link_bits; Blake2b.hex(bits).upcase end |