class Block

add more methods

Public Class Methods

from_h( h ) click to toggle source
# File lib/centralbank/block.rb, line 23
def self.from_h( h )
  transactions = h['transactions'].map { |h_tx| Tx.from_h( h_tx ) }

  ## todo: use hash and transactions_hash to check integrity of block - why? why not?

  ## parse iso8601 format e.g 2017-10-05T22:26:12-04:00
  timestamp    = Time.parse( h['timestamp'] )

  self.new( h['index'],
            transactions,
            h['previous_hash'],
            timestamp: timestamp,
            nonce: h['nonce'].to_i )
end

Public Instance Methods

to_h() click to toggle source
# File lib/centralbank/block.rb, line 13
def to_h
  { index:             @index,
    timestamp:         @timestamp,
    nonce:             @nonce,
    transactions:      @transactions.map { |tx| tx.to_h },
    transactions_hash: @transactions_hash,
    previous_hash:     @previous_hash,
    hash:              @hash }
end
valid?() click to toggle source
# File lib/centralbank/block.rb, line 39
def valid?
  true   ## for now always valid
end