Skip to main content

A simlpe Merkle Patricia Trie implementation

Project description

PyPi Version Python Versions pre-commit Code style: black

Credits

This is a fork of eth_mpt package with minor improvements.

Modified Merkle Paticia Trie

MPT is the data structure used in Ethereum as a cryptographically authenticated key-value data storage.

This library is a Python implementation of Modified Merkle Patrica Trie with a very simple interface.

Example

storage = {}
trie = MerklePatriciaTrie(storage)

trie.update(b'do', b'verb')
trie.update(b'dog', b'puppy')
trie.update(b'doge', b'coin')
trie.update(b'horse', b'stallion')

old_root = trie.root()
old_root_hash = trie.root_hash()

print("Root hash is {}".format(old_root_hash.hex()))

trie.delete(b'doge')

print("New root hash is {}".format(trie.root_hash().hex()))

trie_from_old_hash = MerklePatriciaTrie(storage, root=old_root)

print(trie_from_old_hash.get(b'doge'))

try:
    print(trie.get(b'doge'))
except KeyError:
    print('Not accessible in a new trie.')

Installing

Install and update using pip:

pip install -U mercle_patricia_trie

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

merkle_patricia_trie-0.4.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

merkle_patricia_trie-0.4.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file merkle_patricia_trie-0.4.0.tar.gz.

File metadata

File hashes

Hashes for merkle_patricia_trie-0.4.0.tar.gz
Algorithm Hash digest
SHA256 3ed7f430587b1e47679c25c5baee51a3a57fcc5423aaf9f05caf1b7176a6e7cd
MD5 8d2b7edfe65f400592e19a2f1f2fc80d
BLAKE2b-256 40720f95928c9f9d21259c7900974dfd777688acd5df828ff719f673ac51cb4e

See more details on using hashes here.

File details

Details for the file merkle_patricia_trie-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for merkle_patricia_trie-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1299e0b59dfcf7876582bf631f33d997640051852daaff94625de9f1fe835b3
MD5 46cb5f5c3392247ef2fcac2eead6c5f3
BLAKE2b-256 a4bb984d01835a07264525d37bb300b6728a4149772dbef1d3bd6696185ba5dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page