Class: Cryptoruby::Blockchain::Block

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blockchainObject (readonly)

Returns the value of attribute blockchain.



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

def blockchain
  @blockchain
end

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#difficultObject (readonly)

Returns the value of attribute difficult.



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

def difficult
  @difficult
end

#hashObject (readonly)

Returns the value of attribute hash.



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

def hash
  @hash
end

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#nonceObject (readonly)

Returns the value of attribute nonce.



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

def nonce
  @nonce
end

#previous_hashObject (readonly)

Returns the value of attribute previous_hash.



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

def previous_hash
  @previous_hash
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



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

def timestamp
  @timestamp
end

Instance Method Details

#digest_hashObject



16
17
18
# File 'lib/cryptoruby/block.rb', line 16

def digest_hash
  OpenSSL::Digest::SHA512.hexdigest "#{index}#{previous_hash}#{stringfied_data}#{timestamp.to_s}#{nonce}"
end