astreum 0.1.19__py3-none-any.whl → 0.1.20__py3-none-any.whl

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/node/__init__.py CHANGED
@@ -8,7 +8,7 @@ from .relay import Relay, Topic
8
8
  from ..machine import AstreumMachine
9
9
  from .utils import hash_data
10
10
  from .validation.block import Block
11
- from .storage import Storage
11
+ from .storage.storage import Storage
12
12
 
13
13
  class Node:
14
14
  def __init__(self, config: dict):
@@ -1,13 +0,0 @@
1
- """
2
- Storage utilities for the Astreum node.
3
- """
4
-
5
- from .merkle import MerkleTree, MerkleProof, MerkleNode
6
- from .merkle import find_first, find_all, map, binary_search
7
- from .storage import Storage
8
-
9
- __all__ = [
10
- "MerkleTree", "MerkleProof", "MerkleNode",
11
- "find_first", "find_all", "map", "binary_search",
12
- "Storage"
13
- ]
@@ -1,7 +1,71 @@
1
1
  import blake3
2
2
  from .storage import Storage
3
- import astreum.utils.bytes_format as bytes_format bytes_format.decode, bytes_format.encode
3
+ from astreum.utils import bytes_format
4
4
 
5
+ class MerkleNode:
6
+ def __init__(self, leaf: bool, data: bytes):
7
+ """
8
+ Initialize a Merkle node.
9
+
10
+ For a leaf node, `data` is the actual content to be stored.
11
+ For an internal node, `data` should be the concatenation of the two child hashes.
12
+
13
+ :param leaf: A boolean flag indicating whether this node is a leaf node (True) or an internal node (False).
14
+ :param data: The node's data. For leaves, the stored data; for internal nodes, concatenated child hashes.
15
+ """
16
+ self.leaf = leaf
17
+ self.data = data
18
+ self._hash = None # Cached hash value to avoid recomputation.
19
+
20
+ @classmethod
21
+ def from_bytes(cls, data: bytes) -> 'MerkleNode':
22
+ """
23
+ Deserialize a MerkleNode from its byte representation.
24
+
25
+ The input bytes are expected to be in the Astreum format, containing a leaf flag and node data.
26
+
27
+ :param data: The serialized node data.
28
+ :return: A new MerkleNode instance.
29
+ """
30
+ leaf_flag, node_data = bytes_format.decode(data)
31
+ return cls(True if leaf_flag == 1 else False, node_data)
32
+
33
+ @classmethod
34
+ def from_storage(cls, storage: Storage, hash_value: bytes) -> 'MerkleNode' or None:
35
+ """
36
+ Retrieve and deserialize a MerkleNode from storage using its hash.
37
+
38
+ :param storage: The Storage instance used to retrieve the node.
39
+ :param hash_value: The hash key under which the node is stored.
40
+ :return: A MerkleNode instance if found, otherwise None.
41
+ """
42
+ node_bytes = storage.get(hash_value)
43
+ if node_bytes is None:
44
+ return None
45
+ return cls.from_bytes(node_bytes)
46
+
47
+ def to_bytes(self) -> bytes:
48
+ """
49
+ Serialize the MerkleNode into bytes using the Astreum format.
50
+
51
+ The format encodes a list containing the leaf flag and the node data.
52
+
53
+ :return: The serialized bytes representing the node.
54
+ """
55
+ return bytes_format.encode([1 if self.leaf else 0, self.data])
56
+
57
+ def hash(self) -> bytes:
58
+ """
59
+ Compute (or retrieve a cached) hash of the node using the Blake3 algorithm.
60
+
61
+ For leaf nodes, the hash is computed over the actual data.
62
+ For internal nodes, the hash is computed over the concatenated child hashes.
63
+
64
+ :return: The Blake3 digest of the node's data.
65
+ """
66
+ if self._hash is None:
67
+ self._hash = blake3.blake3(self.data).digest()
68
+ return self._hash
5
69
 
6
70
 
7
71
  class MerkleTree:
@@ -158,67 +222,3 @@ class MerkleTree:
158
222
  return new_node_hash
159
223
 
160
224
 
161
- class MerkleNode:
162
- def __init__(self, leaf: bool, data: bytes):
163
- """
164
- Initialize a Merkle node.
165
-
166
- For a leaf node, `data` is the actual content to be stored.
167
- For an internal node, `data` should be the concatenation of the two child hashes.
168
-
169
- :param leaf: A boolean flag indicating whether this node is a leaf node (True) or an internal node (False).
170
- :param data: The node's data. For leaves, the stored data; for internal nodes, concatenated child hashes.
171
- """
172
- self.leaf = leaf
173
- self.data = data
174
- self._hash = None # Cached hash value to avoid recomputation.
175
-
176
- @classmethod
177
- def from_bytes(cls, data: bytes) -> 'MerkleNode':
178
- """
179
- Deserialize a MerkleNode from its byte representation.
180
-
181
- The input bytes are expected to be in the Astreum format, containing a leaf flag and node data.
182
-
183
- :param data: The serialized node data.
184
- :return: A new MerkleNode instance.
185
- """
186
- leaf_flag, node_data = bytes_format.decode(data)
187
- return cls(True if leaf_flag == 1 else False, node_data)
188
-
189
- @classmethod
190
- def from_storage(cls, storage: Storage, hash_value: bytes) -> 'MerkleNode' or None:
191
- """
192
- Retrieve and deserialize a MerkleNode from storage using its hash.
193
-
194
- :param storage: The Storage instance used to retrieve the node.
195
- :param hash_value: The hash key under which the node is stored.
196
- :return: A MerkleNode instance if found, otherwise None.
197
- """
198
- node_bytes = storage.get(hash_value)
199
- if node_bytes is None:
200
- return None
201
- return cls.from_bytes(node_bytes)
202
-
203
- def to_bytes(self) -> bytes:
204
- """
205
- Serialize the MerkleNode into bytes using the Astreum format.
206
-
207
- The format encodes a list containing the leaf flag and the node data.
208
-
209
- :return: The serialized bytes representing the node.
210
- """
211
- return bytes_format.encode([1 if self.leaf else 0, self.data])
212
-
213
- def hash(self) -> bytes:
214
- """
215
- Compute (or retrieve a cached) hash of the node using the Blake3 algorithm.
216
-
217
- For leaf nodes, the hash is computed over the actual data.
218
- For internal nodes, the hash is computed over the concatenated child hashes.
219
-
220
- :return: The Blake3 digest of the node's data.
221
- """
222
- if self._hash is None:
223
- self._hash = blake3.blake3(self.data).digest()
224
- return self._hash
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astreum
3
- Version: 0.1.19
3
+ Version: 0.1.20
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
@@ -21,7 +21,7 @@ astreum/lispeum/special/number/addition.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5
21
21
  astreum/machine/__init__.py,sha256=GOdZl1tS9uIJHbq5WVcplifMDPDLQroX7CVew-K2YbA,15262
22
22
  astreum/machine/environment.py,sha256=K0084U6B7wwjrDZ9b2_7cEcbBzsB7UOy_Zpbrr7B3GY,834
23
23
  astreum/machine/error.py,sha256=MvqBaZZt33rNELNhUJ2lER3TE3aS8WVqsWF2hz2AwoA,38
24
- astreum/node/__init__.py,sha256=obb-ap7YuRrMblNN7IAK79xEq__9aNBVzt1ciSTMvoU,18631
24
+ astreum/node/__init__.py,sha256=7yz1YHo0DCUgUQvJf75qdUo_ocl5-XZRU-Vc2NhcvJs,18639
25
25
  astreum/node/utils.py,sha256=amGhNYHVMjvAO-9vBRAcim-S5LlLSRudqooBN-XPdm4,702
26
26
  astreum/node/crypto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  astreum/node/crypto/ed25519.py,sha256=FRnvlN0kZlxn4j-sJKl-C9tqiz_0z4LZyXLj3KIj1TQ,1760
@@ -32,8 +32,8 @@ astreum/node/relay/envelope.py,sha256=sDKsIvJruQKLWgWs92sx1mCjMHF7yQVoLguPygw2Pz
32
32
  astreum/node/relay/message.py,sha256=uezmGjNaQK4fZmYQLCHd2YpiosaaFb8DOa3H58HS1jA,2887
33
33
  astreum/node/relay/peer.py,sha256=DlvTR9j0BZQ1dW-p_9UGgfLvQqwNdpNLMSCYEW4FhyI,5899
34
34
  astreum/node/relay/route.py,sha256=fyOSsAe1mfsCVeN6LtQ_OEUEb1FiC5dobZBEJKNGU9U,5814
35
- astreum/node/storage/__init__.py,sha256=eJL7ILUGKSKDhXZqkn3Rk5TUza39vIcwPwAW_AaIHTk,326
36
- astreum/node/storage/merkle.py,sha256=sC7gfxPDUBgv3iiFs5PyxPgYbC4CoE-If5TQvkuoTGU,10295
35
+ astreum/node/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
+ astreum/node/storage/merkle.py,sha256=_rt6-jTE9jOGMpj0Ze8kegObfHJ4h-7QJdHJm_a_Di8,10243
37
37
  astreum/node/storage/patricia.py,sha256=zP4whShdB7yOFcEPLE1-1PIFfx_LdK8DyMSadnF0KT0,11588
38
38
  astreum/node/storage/storage.py,sha256=czJDhRK2rQxjOo88fhZ6j10f55RW8hWp1qq7c4yur6Y,10086
39
39
  astreum/node/storage/utils.py,sha256=CxKH9GbW31aVYs2Hwg1SirCykSnH_3_JisEayDrpOvY,5169
@@ -50,8 +50,8 @@ astreum/node/validation/_block/model.py,sha256=d7x3_tX2MPLnGODL_5_vNjQfLdYa405bl
50
50
  astreum/node/validation/_block/validate.py,sha256=niLexCNhEwUJLclyrdNZSvHcVa_J6jlu7J3FiWY7XBU,6232
51
51
  astreum/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
52
52
  astreum/utils/bytes_format.py,sha256=X4tG5GGPweNCE54bHYkLFiuLTbmpy5upO_s1Cef-MGA,2711
53
- astreum-0.1.19.dist-info/licenses/LICENSE,sha256=gYBvRDP-cPLmTyJhvZ346QkrYW_eleke4Z2Yyyu43eQ,1089
54
- astreum-0.1.19.dist-info/METADATA,sha256=MvTCByomvRA9Tf_iCyOyxeGCsSnNyHSrtoRChhbx0ls,3312
55
- astreum-0.1.19.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
56
- astreum-0.1.19.dist-info/top_level.txt,sha256=1EG1GmkOk3NPmUA98FZNdKouhRyget-KiFiMk0i2Uz0,8
57
- astreum-0.1.19.dist-info/RECORD,,
53
+ astreum-0.1.20.dist-info/licenses/LICENSE,sha256=gYBvRDP-cPLmTyJhvZ346QkrYW_eleke4Z2Yyyu43eQ,1089
54
+ astreum-0.1.20.dist-info/METADATA,sha256=Br2J_FPsK6l8w7Af-CpsOcOn1yXDX7FV7BePSOXYJCQ,3312
55
+ astreum-0.1.20.dist-info/WHEEL,sha256=GHB6lJx2juba1wDgXDNlMTyM13ckjBMKf-OnwgKOCtA,91
56
+ astreum-0.1.20.dist-info/top_level.txt,sha256=1EG1GmkOk3NPmUA98FZNdKouhRyget-KiFiMk0i2Uz0,8
57
+ astreum-0.1.20.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.1.0)
2
+ Generator: setuptools (80.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5