Class: Rubychain::Block
- Inherits:
-
Object
- Object
- Rubychain::Block
- Defined in:
- lib/rubychain/block.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#prev_hash ⇒ Object
readonly
Returns the value of attribute prev_hash.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#hash_block ⇒ Object
Create the blocks hash by encrypting all the blocks data using SHA256.
-
#initialize(index, timestamp, data, prev_hash) ⇒ Block
constructor
A new instance of Block.
Constructor Details
#initialize(index, timestamp, data, prev_hash) ⇒ Block
Returns a new instance of Block.
8 9 10 11 12 13 14 |
# File 'lib/rubychain/block.rb', line 8 def initialize(index, , data, prev_hash) @index = index @timestamp = @data = data @prev_hash = prev_hash @hash = hash_block end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/rubychain/block.rb', line 6 def data @data end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
6 7 8 |
# File 'lib/rubychain/block.rb', line 6 def hash @hash end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
6 7 8 |
# File 'lib/rubychain/block.rb', line 6 def index @index end |
#prev_hash ⇒ Object (readonly)
Returns the value of attribute prev_hash.
6 7 8 |
# File 'lib/rubychain/block.rb', line 6 def prev_hash @prev_hash end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/rubychain/block.rb', line 6 def @timestamp end |
Instance Method Details
#hash_block ⇒ Object
Create the blocks hash by encrypting all the blocks data using SHA256
18 19 20 21 22 23 |
# File 'lib/rubychain/block.rb', line 18 def hash_block hash_string = [index,,data,prev_hash].join sha = Digest::SHA256.new sha.update(hash_string) sha.hexdigest end |