Class: Ethereum::PruningTrie

Inherits:
Trie show all
Defined in:
lib/ethereum/pruning_trie.rb

Constant Summary

Constants inherited from Trie

Trie::BLANK_NODE, Trie::BLANK_ROOT, Trie::BRANCH_CARDINAL, Trie::BRANCH_WIDTH, Trie::KV_WIDTH, Trie::NODE_KV_TYPE, Trie::NODE_TYPES

Instance Attribute Summary

Attributes inherited from Trie

#db

Instance Method Summary collapse

Methods inherited from Trie

#[], #[]=, #clear, #delete, #each, #find, #has_key?, #initialize, #root_hash, #root_hash_valid?, #set_root_hash, #size, #to_h

Constructor Details

This class inherits a constructor from Ethereum::Trie

Instance Method Details

#clear_all(node = nil) ⇒ Object

TODO: pruning trie implementation



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ethereum/pruning_trie.rb', line 7

def clear_all(node=nil)
  if node.nil?
    node = @root_node
    delete_node_storage node
  end

  return if node == BLANK_NODE

  node_type = get_node_type node
  delete_node_storage node

  if NODE_KV_TYPE.include?(node_type)
    value_is_node = node_type == :extension
    clear_all decode_to_node(node[1]) if value_is_node
  elsif node_type == :branch
    16.times do |i|
      clear_all decode_to_node(node[i])
    end
  end
end