merkle_patricia_tree v0.2.3 MerklePatriciaTree.Trie.Storage
Module to get and put nodes in a trie by the given
storage mechanism. Generally, handles the function n(I, i)
,
Eq.(178) from the Yellow Paper.
Link to this section Summary
Functions
Gets the RLP encoded value of a given trie root. Specifically,
we invert the function n(I, i)
Eq.(178) from the Yellow Paper
Takes an RLP-encoded node and pushes it to storage,
as defined by n(I, i)
Eq.(178) of the Yellow Paper
Link to this section Functions
Gets the RLP encoded value of a given trie root. Specifically,
we invert the function n(I, i)
Eq.(178) from the Yellow Paper.
Examples
iex> MerklePatriciaTree.Trie.new(MerklePatriciaTree.Test.random_ets_db(), <<>>) …> |> MerklePatriciaTree.Trie.Storage.get_node() “”
iex> MerklePatriciaTree.Trie.new(MerklePatriciaTree.Test.random_ets_db(), <<130, 72, 105>>) …> |> MerklePatriciaTree.Trie.Storage.get_node() “Hi”
iex> MerklePatriciaTree.Trie.new(MerklePatriciaTree.Test.random_ets_db(), <<254, 112, 17, 90, 21, 82, 19, 29, 72, 106, 175, 110, 87, 220, 249, 140, 74, 165, 64, 94, 174, 79, 78, 189, 145, 143, 92, 53, 173, 136, 220, 145>>) …> |> MerklePatriciaTree.Trie.Storage.get_node() ** (RuntimeError) Cannot find value in DB: <<254, 112, 17, 90, 21, 82, 19, 29, 72, 106, 175, 110, 87, 220, 249, 140, 74, 165, 64, 94, 174, 79, 78, 189, 145, 143, 92, 53, 173, 136, 220, 145>>
iex> trie = MerklePatriciaTree.Trie.new(MerklePatriciaTree.Test.random_ets_db(), <<130, 72, 105>>) iex> MerklePatriciaTree.Trie.Storage.put_node(ExRLP.encode([“AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA”]), trie) <<141, 163, 93, 242, 120, 27, 128, 97, 138, 56, 116, 101, 165, 201, 165, 139, 86, 73, 85, 153, 45, 38, 207, 186, 196, 202, 111, 84, 214, 26, 122, 164>> iex> MerklePatriciaTree.Trie.Storage.get_node(%{trie| root_hash: <<141, 163, 93, 242, 120, 27, 128, 97, 138, 56, 116, 101, 165, 201, 165, 139, 86, 73, 85, 153, 45, 38, 207, 186, 196, 202, 111, 84, 214, 26, 122, 164>>}) [“AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA”]
put_node(ExRLP.t, MerklePatriciaTree.Trie.t) :: nil | binary
Takes an RLP-encoded node and pushes it to storage,
as defined by n(I, i)
Eq.(178) of the Yellow Paper.
Examples
iex> trie = MerklePatriciaTree.Trie.new(MerklePatriciaTree.Test.random_ets_db())
iex> MerklePatriciaTree.Trie.Storage.put_node(<<>>, trie)
nil
iex> MerklePatriciaTree.Trie.Storage.put_node(ExRLP.encode("Hi"), trie)
<<130, 72, 105>>
iex> MerklePatriciaTree.Trie.Storage.put_node(ExRLP.encode(["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"]), trie)
<<141, 163, 93, 242, 120, 27, 128, 97, 138, 56, 116, 101, 165, 201,
165, 139, 86, 73, 85, 153, 45, 38, 207, 186, 196, 202, 111, 84,
214, 26, 122, 164>>