class Block
add more methods
Public Class Methods
from_h( h )
click to toggle source
# File lib/shilling/block.rb, line 18 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/shilling/block.rb, line 8 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/shilling/block.rb, line 34 def valid? true ## for now always valid end