Class: Block

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

Overview

add more methods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_h(h) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tulipmania/block.rb', line 21

def self.from_h( h )
  transactions = h['transactions'].map { |h_tx| Tx.from_h( h_tx ) }

  ## 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
# File 'lib/tulipmania/block.rb', line 13

def to_h
  { index:         @index,
    timestamp:     @timestamp,
    nonce:         @nonce,
    transactions:  @transactions.map { |tx| tx.to_h },
    previous_hash: @previous_hash }
end

#valid?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/tulipmania/block.rb', line 35

def valid?
  true   ## for now always valid
end