Class: Block

Inherits:
Object
  • Object
show all
Defined in:
lib/centralbank/block.rb

Overview

add more methods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_h(h) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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

Instance Method Details

#to_hObject



13
14
15
16
17
18
19
20
21
# 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?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/centralbank/block.rb', line 39

def valid?
  true   ## for now always valid
end