Class: Blockchain::Block

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(b) ⇒ Block

Returns a new instance of Block.



13
14
15
16
17
18
19
20
# File 'lib/block.rb', line 13

def initialize(b)
  @hsh = b.delete('hash') # hash is an unfortunate word
  b.each_key { |k| instance_variable_set("@#{k}", b[k]) }
  @time = DateTime.strptime(@time.to_s, '%s')
  @received_time = DateTime.strptime(@received_time.to_s, '%s')
  @tx.map! { |t| Blockchain::Transaction.new(t) }
  @fee = Btc.from_satoshis(fee)
end

Instance Attribute Details

#bitsObject (readonly)

Returns the value of attribute bits.



4
5
6
# File 'lib/block.rb', line 4

def bits
  @bits
end

#block_indexObject (readonly)

Returns the value of attribute block_index.



5
6
7
# File 'lib/block.rb', line 5

def block_index
  @block_index
end

#feeObject (readonly)

Returns the value of attribute fee.



4
5
6
# File 'lib/block.rb', line 4

def fee
  @fee
end

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/block.rb', line 5

def height
  @height
end

#hshObject (readonly)

Returns the value of attribute hsh.



3
4
5
# File 'lib/block.rb', line 3

def hsh
  @hsh
end

#main_chainObject (readonly)

Returns the value of attribute main_chain.



5
6
7
# File 'lib/block.rb', line 5

def main_chain
  @main_chain
end

#mrkl_rootObject (readonly)

Returns the value of attribute mrkl_root.



3
4
5
# File 'lib/block.rb', line 3

def mrkl_root
  @mrkl_root
end

#n_txObject (readonly)

Returns the value of attribute n_tx.



4
5
6
# File 'lib/block.rb', line 4

def n_tx
  @n_tx
end

#nonceObject (readonly)

Returns the value of attribute nonce.



4
5
6
# File 'lib/block.rb', line 4

def nonce
  @nonce
end

#prev_blockObject (readonly)

Returns the value of attribute prev_block.



3
4
5
# File 'lib/block.rb', line 3

def prev_block
  @prev_block
end

#received_timeObject (readonly)

Returns the value of attribute received_time.



5
6
7
# File 'lib/block.rb', line 5

def received_time
  @received_time
end

#relayed_byObject (readonly)

Returns the value of attribute relayed_by.



6
7
8
# File 'lib/block.rb', line 6

def relayed_by
  @relayed_by
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/block.rb', line 4

def size
  @size
end

#timeObject (readonly)

Returns the value of attribute time.



4
5
6
# File 'lib/block.rb', line 4

def time
  @time
end

#txObject (readonly)

Returns the value of attribute tx.



6
7
8
# File 'lib/block.rb', line 6

def tx
  @tx
end

#verObject (readonly)

Returns the value of attribute ver.



3
4
5
# File 'lib/block.rb', line 3

def ver
  @ver
end

Class Method Details

.find(id) ⇒ Object

id can be block_hash or block_index



9
10
11
# File 'lib/block.rb', line 9

def self.find(id)
  self.new(Blockchain.rawblock(id)) rescue nil
end

Instance Method Details

#previousObject



22
23
24
# File 'lib/block.rb', line 22

def previous
  Block.find(@prev_block)
end