This commit is contained in:
parent
83b2b2bde6
commit
292ef5464d
19
README.md
19
README.md
@ -20,19 +20,34 @@ $ pip install merkle-tree-stream
|
|||||||
```python
|
```python
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
from merkle_tree_stream import MerkleTreeGenerator
|
||||||
|
|
||||||
|
|
||||||
def _leaf(node, roots=None):
|
def _leaf(node, roots=None):
|
||||||
return hashlib.sha256(node.data).digest()
|
return hashlib.sha256(node.data).digest()
|
||||||
|
|
||||||
|
|
||||||
def _parent(first, second):
|
def _parent(first, second):
|
||||||
sha256 = hashlib.sha256()
|
sha256 = hashlib.sha256()
|
||||||
sha256.update(first.data)
|
sha256.update(first.data)
|
||||||
sha256.update(second.data)
|
sha256.update(second.data)
|
||||||
return sha256.digest()
|
return sha256.digest()
|
||||||
|
|
||||||
merkle = MerkleTreeGenerator(leaf=leaf, parent=parent)
|
|
||||||
|
merkle = MerkleTreeGenerator(leaf=_leaf, parent=_parent)
|
||||||
|
|
||||||
merkle.write(b"a")
|
merkle.write(b"a")
|
||||||
merkle.write(b"b")
|
merkle.write(b"b")
|
||||||
|
|
||||||
assert len(merkle) == 2 + 1
|
print(merkle._nodes)
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
[
|
||||||
|
MerkleTreeNode(index=0, parent=1, size=1, data=b'a', hash=b'...'),
|
||||||
|
MerkleTreeNode(index=2, parent=1, size=1, data=b'b', hash=b'...'),
|
||||||
|
MerkleTreeNode(index=1, parent=3, size=2, data=b'', hash=b'...')
|
||||||
|
]
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user