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.3.1.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

merkle_patricia_trie-0.3.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file merkle-patricia-trie-0.3.1.tar.gz.

File metadata

  • Download URL: merkle-patricia-trie-0.3.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for merkle-patricia-trie-0.3.1.tar.gz
Algorithm Hash digest
SHA256 f12a4acba29581341c48262bef317f13b2bb5ce398012d4f32408ce1706d840b
MD5 f37345a2c092a1564dfa0f0979302b56
BLAKE2b-256 d76f09f54856bc7c585ca541b8d6c9063fdce41d66c7f823a0ba15345f32e7ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for merkle_patricia_trie-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0deebb2bb5c482311bf2f7c252bbd5426543655d883e575ada5609956ce77f65
MD5 cc89e6d7e6cc08b110be94eb6ca39f72
BLAKE2b-256 65031326f31b242fb95f129e8efe4011e4b0669aea9c8c188690787726a18aae

See more details on using hashes here.

Supported by

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