astreum 0.2.18__tar.gz → 0.2.19__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of astreum might be problematic. Click here for more details.
- {astreum-0.2.18/src/astreum.egg-info → astreum-0.2.19}/PKG-INFO +1 -1
- {astreum-0.2.18 → astreum-0.2.19}/pyproject.toml +1 -1
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/models/merkle.py +21 -50
- {astreum-0.2.18 → astreum-0.2.19/src/astreum.egg-info}/PKG-INFO +1 -1
- {astreum-0.2.18 → astreum-0.2.19}/LICENSE +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/README.md +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/setup.cfg +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/__init__.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/crypto/__init__.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/crypto/ed25519.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/crypto/quadratic_form.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/crypto/wesolowski.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/crypto/x25519.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/format.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/lispeum/__init__.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/lispeum/parser.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/lispeum/tokenizer.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/models/__init__.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/models/account.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/models/block.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/models/patricia.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/models/transaction.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum/node.py +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum.egg-info/SOURCES.txt +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum.egg-info/dependency_links.txt +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum.egg-info/requires.txt +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/src/astreum.egg-info/top_level.txt +0 -0
- {astreum-0.2.18 → astreum-0.2.19}/tests/test_node_machine.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: astreum
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.19
|
|
4
4
|
Summary: Python library to interact with the Astreum blockchain and its Lispeum virtual machine.
|
|
5
5
|
Author-email: "Roy R. O. Okello" <roy@stelar.xyz>
|
|
6
6
|
Project-URL: Homepage, https://github.com/astreum/lib
|
|
@@ -2,18 +2,10 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import Callable, Dict, List, Optional, Tuple
|
|
4
4
|
|
|
5
|
-
import blake3
|
|
5
|
+
import blake3
|
|
6
6
|
from ..format import encode, decode
|
|
7
7
|
|
|
8
8
|
class MerkleNode:
|
|
9
|
-
"""A node in a binary Merkle tree.
|
|
10
|
-
|
|
11
|
-
*Leaf* : ``value`` is **not** ``None``.
|
|
12
|
-
*Interior*: ``value`` is ``None``.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
__slots__ = ("left", "right", "value", "_hash")
|
|
16
|
-
|
|
17
9
|
def __init__(
|
|
18
10
|
self,
|
|
19
11
|
left: Optional[bytes],
|
|
@@ -25,9 +17,6 @@ class MerkleNode:
|
|
|
25
17
|
self.value = value
|
|
26
18
|
self._hash: Optional[bytes] = None
|
|
27
19
|
|
|
28
|
-
# ------------------------------------------------------------------
|
|
29
|
-
# serialisation helpers
|
|
30
|
-
# ------------------------------------------------------------------
|
|
31
20
|
def to_bytes(self) -> bytes:
|
|
32
21
|
return encode([self.left, self.right, self.value])
|
|
33
22
|
|
|
@@ -36,11 +25,8 @@ class MerkleNode:
|
|
|
36
25
|
left, right, value = decode(blob)
|
|
37
26
|
return cls(left, right, value)
|
|
38
27
|
|
|
39
|
-
# ------------------------------------------------------------------
|
|
40
|
-
# content hash (blake3)
|
|
41
|
-
# ------------------------------------------------------------------
|
|
42
28
|
def _compute_hash(self) -> bytes:
|
|
43
|
-
if self.value is not None:
|
|
29
|
+
if self.value is not None:
|
|
44
30
|
return blake3.blake3(self.value).digest()
|
|
45
31
|
left = self.left or b""
|
|
46
32
|
right = self.right or b""
|
|
@@ -52,21 +38,7 @@ class MerkleNode:
|
|
|
52
38
|
return self._hash
|
|
53
39
|
|
|
54
40
|
|
|
55
|
-
# ─────────────────────────────────────────────────────────────────────────────
|
|
56
|
-
# Merkle tree – fixed‑height, no dynamic growth
|
|
57
|
-
# ─────────────────────────────────────────────────────────────────────────────
|
|
58
|
-
|
|
59
|
-
|
|
60
41
|
class MerkleTree:
|
|
61
|
-
"""Binary Merkle tree addressed by *leaf position* (0‑based).
|
|
62
|
-
|
|
63
|
-
* The number of levels is fixed once the tree is built (``_height``).
|
|
64
|
-
* ``put`` can **only update** existing leaves; it never adds capacity.
|
|
65
|
-
"""
|
|
66
|
-
|
|
67
|
-
# ------------------------------------------------------------------
|
|
68
|
-
# construction helpers
|
|
69
|
-
# ------------------------------------------------------------------
|
|
70
42
|
def __init__(
|
|
71
43
|
self,
|
|
72
44
|
node_get: Callable[[bytes], Optional[bytes]],
|
|
@@ -84,11 +56,6 @@ class MerkleTree:
|
|
|
84
56
|
leaves: List[bytes],
|
|
85
57
|
node_get: Callable[[bytes], Optional[bytes]] | None = None,
|
|
86
58
|
) -> "MerkleTree":
|
|
87
|
-
"""Build a complete tree from *leaves* (left‑to‑right order).
|
|
88
|
-
|
|
89
|
-
Missing right siblings in the top levels are allowed; they are encoded
|
|
90
|
-
as interior nodes with a single child.
|
|
91
|
-
"""
|
|
92
59
|
if not leaves:
|
|
93
60
|
raise ValueError("must supply at least one leaf")
|
|
94
61
|
|
|
@@ -125,9 +92,6 @@ class MerkleTree:
|
|
|
125
92
|
tree._height = height
|
|
126
93
|
return tree
|
|
127
94
|
|
|
128
|
-
# ------------------------------------------------------------------
|
|
129
|
-
# internal helpers
|
|
130
|
-
# ------------------------------------------------------------------
|
|
131
95
|
def _fetch(self, h: bytes | None) -> Optional[MerkleNode]:
|
|
132
96
|
if h is None:
|
|
133
97
|
return None
|
|
@@ -141,11 +105,10 @@ class MerkleTree:
|
|
|
141
105
|
return node
|
|
142
106
|
|
|
143
107
|
def _invalidate(self, node: MerkleNode) -> None:
|
|
144
|
-
node._hash = None
|
|
108
|
+
node._hash = None
|
|
145
109
|
|
|
146
110
|
def _ensure_height(self) -> None:
|
|
147
111
|
if self._height is None:
|
|
148
|
-
# Recompute by traversing leftmost branch
|
|
149
112
|
h = 0
|
|
150
113
|
nh = self.root_hash
|
|
151
114
|
while nh is not None:
|
|
@@ -186,11 +149,7 @@ class MerkleTree:
|
|
|
186
149
|
return leaf.value if leaf else None
|
|
187
150
|
|
|
188
151
|
def put(self, index: int, value: bytes) -> None:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
Raises ``IndexError`` if *index* is outside current capacity **or** if
|
|
192
|
-
the path to that leaf is missing in the stored structure.
|
|
193
|
-
"""
|
|
152
|
+
# 1 . input validation
|
|
194
153
|
if index < 0:
|
|
195
154
|
raise IndexError("negative index")
|
|
196
155
|
if self.root_hash is None:
|
|
@@ -198,6 +157,7 @@ class MerkleTree:
|
|
|
198
157
|
if index >= self._capacity():
|
|
199
158
|
raise IndexError("index beyond tree capacity")
|
|
200
159
|
|
|
160
|
+
# 2 . walk down to the target leaf
|
|
201
161
|
node_hash = self.root_hash
|
|
202
162
|
stack: List[Tuple[MerkleNode, bytes, bool]] = []
|
|
203
163
|
for bit in self._path_bits(index):
|
|
@@ -207,28 +167,39 @@ class MerkleTree:
|
|
|
207
167
|
went_right = bool(bit)
|
|
208
168
|
child_hash = node.right if went_right else node.left
|
|
209
169
|
if child_hash is None:
|
|
210
|
-
raise IndexError("path leads into non
|
|
170
|
+
raise IndexError("path leads into non-existent branch")
|
|
211
171
|
stack.append((node, node.hash(), went_right))
|
|
212
172
|
node_hash = child_hash
|
|
213
173
|
|
|
174
|
+
# 3 . update the leaf
|
|
214
175
|
leaf = self._fetch(node_hash)
|
|
215
176
|
if leaf is None or leaf.value is None:
|
|
216
177
|
raise IndexError("target leaf missing")
|
|
178
|
+
|
|
179
|
+
old_hash = leaf.hash()
|
|
217
180
|
leaf.value = value
|
|
218
181
|
self._invalidate(leaf)
|
|
219
182
|
new_hash = leaf.hash()
|
|
183
|
+
|
|
184
|
+
if new_hash != old_hash:
|
|
185
|
+
self.nodes.pop(old_hash, None)
|
|
220
186
|
self.nodes[new_hash] = leaf
|
|
221
|
-
|
|
222
|
-
# bubble
|
|
187
|
+
|
|
188
|
+
# 4 . bubble the change up
|
|
223
189
|
for parent, old_hash, went_right in reversed(stack):
|
|
224
190
|
if went_right:
|
|
225
191
|
parent.right = new_hash
|
|
226
192
|
else:
|
|
227
193
|
parent.left = new_hash
|
|
194
|
+
|
|
228
195
|
self._invalidate(parent)
|
|
229
196
|
new_hash = parent.hash()
|
|
197
|
+
|
|
230
198
|
if new_hash != old_hash:
|
|
231
|
-
|
|
232
|
-
|
|
199
|
+
self.nodes.pop(old_hash, None)
|
|
200
|
+
self.nodes[new_hash] = parent
|
|
201
|
+
|
|
202
|
+
# 5 . finalise the new root
|
|
233
203
|
self.root_hash = new_hash
|
|
234
204
|
|
|
205
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: astreum
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.19
|
|
4
4
|
Summary: Python library to interact with the Astreum blockchain and its Lispeum virtual machine.
|
|
5
5
|
Author-email: "Roy R. O. Okello" <roy@stelar.xyz>
|
|
6
6
|
Project-URL: Homepage, https://github.com/astreum/lib
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|