Class: Ethereum::SecureTrie

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/ethereum/secure_trie.rb

Instance Method Summary collapse

Constructor Details

#initialize(trie) ⇒ SecureTrie

Returns a new instance of SecureTrie.



11
12
13
14
# File 'lib/ethereum/secure_trie.rb', line 11

def initialize(trie)
  @trie = trie
  @db = trie.db
end

Instance Method Details

#[](k) ⇒ Object Also known as: get



16
17
18
# File 'lib/ethereum/secure_trie.rb', line 16

def [](k)
  @trie[Utils.keccak256(k)]
end

#[]=(k, v) ⇒ Object Also known as: set



21
22
23
24
25
# File 'lib/ethereum/secure_trie.rb', line 21

def []=(k, v)
  h = Utils.keccak256 k
  @db.put h, k
  @trie[h] = v
end

#delete(k) ⇒ Object



28
29
30
# File 'lib/ethereum/secure_trie.rb', line 28

def delete(k)
  @trie.delete Utils.keccak256(k)
end

#each(&block) ⇒ Object



41
42
43
44
45
46
# File 'lib/ethereum/secure_trie.rb', line 41

def each(&block)
  @trie.each do |h, v|
    k = @db.get h
    block.call k, v
  end
end

#to_hObject



32
33
34
35
36
37
38
39
# File 'lib/ethereum/secure_trie.rb', line 32

def to_h
  o = {}
  @trie.to_h.each do |h, v|
    k = @db.get h
    o[k] = v
  end
  o
end