Skip to main content

A simlpe Merkle Patricia Trie implementation

Project description

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.')

Testing

python -m unittest

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

eth_mpt-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

eth_mpt-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file eth_mpt-0.1.0.tar.gz.

File metadata

  • Download URL: eth_mpt-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for eth_mpt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6e2e9628c2d3082e06f69f67f1586caf07f6c510fbb480d39d01c7474f92b10f
MD5 defd4269d2a3f5174cc8d7d199b45556
BLAKE2b-256 2e9fd54426edff519c323843b1c21cdc2d325be8b54caf52014e435e733a04b5

See more details on using hashes here.

File details

Details for the file eth_mpt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: eth_mpt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for eth_mpt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45572af993b73da5c54e7cfd0423bf7d5f47dc63ff6060ec18ea06009e1801c8
MD5 414d06669449d24f522ce6aedd392d8c
BLAKE2b-256 aa158d0a02777d85622e3ed25e2d2a44ef5f99d137f4ee6c9e83455a603187d8

See more details on using hashes here.

Supported by

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