Class: Block
- Inherits:
-
Object
- Object
- Block
- Defined in:
- lib/shilling/block.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_h(h) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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 = Time.parse( h['timestamp'] ) self.new( h['index'], transactions, h['previous_hash'], timestamp: , nonce: h['nonce'].to_i ) end |
Instance Method Details
#to_h ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/shilling/block.rb', line 8 def to_h { index: @index, timestamp: , nonce: @nonce, transactions: @transactions.map { |tx| tx.to_h }, transactions_hash: @transactions_hash, previous_hash: @previous_hash, hash: @hash } end |
#valid? ⇒ Boolean
34 35 36 |
# File 'lib/shilling/block.rb', line 34 def valid? true ## for now always valid end |