Class: Cryptoruby::Blockchain::Block
- Inherits:
-
Object
- Object
- Cryptoruby::Blockchain::Block
- Defined in:
- lib/cryptoruby/block.rb
Instance Attribute Summary collapse
-
#blockchain ⇒ Object
readonly
Returns the value of attribute blockchain.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#difficult ⇒ Object
readonly
Returns the value of attribute difficult.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#nonce ⇒ Object
readonly
Returns the value of attribute nonce.
-
#previous_hash ⇒ Object
readonly
Returns the value of attribute previous_hash.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #digest_hash ⇒ Object
-
#initialize(args) ⇒ Block
constructor
A new instance of Block.
Constructor Details
#initialize(args) ⇒ Block
Returns a new instance of Block.
8 9 10 11 12 13 14 |
# File 'lib/cryptoruby/block.rb', line 8 def initialize(args) setup_args(args) @timestamp = Time.now.to_i @difficult = difficult @nonce = 0 mine end |
Instance Attribute Details
#blockchain ⇒ Object (readonly)
Returns the value of attribute blockchain.
7 8 9 |
# File 'lib/cryptoruby/block.rb', line 7 def blockchain @blockchain end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/cryptoruby/block.rb', line 7 def data @data end |
#difficult ⇒ Object (readonly)
Returns the value of attribute difficult.
7 8 9 |
# File 'lib/cryptoruby/block.rb', line 7 def difficult @difficult end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
7 8 9 |
# File 'lib/cryptoruby/block.rb', line 7 def hash @hash end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
7 8 9 |
# File 'lib/cryptoruby/block.rb', line 7 def index @index end |
#nonce ⇒ Object (readonly)
Returns the value of attribute nonce.
7 8 9 |
# File 'lib/cryptoruby/block.rb', line 7 def nonce @nonce end |
#previous_hash ⇒ Object (readonly)
Returns the value of attribute previous_hash.
7 8 9 |
# File 'lib/cryptoruby/block.rb', line 7 def previous_hash @previous_hash end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/cryptoruby/block.rb', line 7 def @timestamp end |
Instance Method Details
#digest_hash ⇒ Object
16 17 18 |
# File 'lib/cryptoruby/block.rb', line 16 def digest_hash OpenSSL::Digest::SHA512.hexdigest "#{index}#{previous_hash}#{stringfied_data}#{.to_s}#{nonce}" end |