Class: Ethereum::EthashRuby::Cache
Instance Method Summary
collapse
Methods included from Utils
#decode_int, #deserialize_hash, #encode_int, #hash_words, #keccak256, #keccak512, #serialize_hash, #zpad
Constructor Details
#initialize(block_number) ⇒ Cache
Returns a new instance of Cache.
11
12
13
|
# File 'lib/ethereum/ethash_ruby/cache.rb', line 11
def initialize(block_number)
@block_number = block_number
end
|
Instance Method Details
32
33
34
|
# File 'lib/ethereum/ethash_ruby/cache.rb', line 32
def seed
@seed ||= self.class.get_seed(@block_number)
end
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/ethereum/ethash_ruby/cache.rb', line 15
def to_a
n = size / HASH_BYTES
o = [keccak512(seed)]
(1...n).each {|i| o.push keccak512(o.last) }
CACHE_ROUNDS.times do
n.times do |i|
v = o[i][0] % n
xor = o[(i-1+n) % n].zip(o[v]).map {|(a,b)| a^b }
o[i] = keccak512 xor
end
end
o
end
|