merkle_patricia_tree v0.2.2 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) <<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> MerklePatriciaTree.Trie.Storage.get_node(%{trie| root_hash: <<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>>}) [“AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA”]

Link to this function put_node(rlp_encoded_node, trie)
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)
<<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>>