astreum 0.2.19__tar.gz → 0.2.21__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.

Files changed (29) hide show
  1. {astreum-0.2.19/src/astreum.egg-info → astreum-0.2.21}/PKG-INFO +1 -1
  2. {astreum-0.2.19 → astreum-0.2.21}/pyproject.toml +1 -1
  3. astreum-0.2.21/src/astreum/models/accounts.py +80 -0
  4. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/models/patricia.py +19 -3
  5. {astreum-0.2.19 → astreum-0.2.21/src/astreum.egg-info}/PKG-INFO +1 -1
  6. {astreum-0.2.19 → astreum-0.2.21}/src/astreum.egg-info/SOURCES.txt +1 -0
  7. {astreum-0.2.19 → astreum-0.2.21}/LICENSE +0 -0
  8. {astreum-0.2.19 → astreum-0.2.21}/README.md +0 -0
  9. {astreum-0.2.19 → astreum-0.2.21}/setup.cfg +0 -0
  10. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/__init__.py +0 -0
  11. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/crypto/__init__.py +0 -0
  12. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/crypto/ed25519.py +0 -0
  13. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/crypto/quadratic_form.py +0 -0
  14. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/crypto/wesolowski.py +0 -0
  15. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/crypto/x25519.py +0 -0
  16. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/format.py +0 -0
  17. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/lispeum/__init__.py +0 -0
  18. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/lispeum/parser.py +0 -0
  19. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/lispeum/tokenizer.py +0 -0
  20. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/models/__init__.py +0 -0
  21. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/models/account.py +0 -0
  22. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/models/block.py +0 -0
  23. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/models/merkle.py +0 -0
  24. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/models/transaction.py +0 -0
  25. {astreum-0.2.19 → astreum-0.2.21}/src/astreum/node.py +0 -0
  26. {astreum-0.2.19 → astreum-0.2.21}/src/astreum.egg-info/dependency_links.txt +0 -0
  27. {astreum-0.2.19 → astreum-0.2.21}/src/astreum.egg-info/requires.txt +0 -0
  28. {astreum-0.2.19 → astreum-0.2.21}/src/astreum.egg-info/top_level.txt +0 -0
  29. {astreum-0.2.19 → astreum-0.2.21}/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.19
3
+ Version: 0.2.21
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "astreum"
3
- version = "0.2.19"
3
+ version = "0.2.21"
4
4
  authors = [
5
5
  { name="Roy R. O. Okello", email="roy@stelar.xyz" },
6
6
  ]
@@ -0,0 +1,80 @@
1
+ """Account‐state management built on a PatriciaTrie.
2
+
3
+ Only the *initial skeleton* is provided here per current request:
4
+ • __init__: wrap an existing trie root (or start empty).
5
+ • get_account: look up an Account object, using a cache so multiple
6
+ balance/nonce updates in one block operate on the same instance.
7
+
8
+ Additional mutation helpers (set_account, change_balance, etc.) will be
9
+ added next, once confirmed.
10
+ """
11
+ from __future__ import annotations
12
+
13
+ from typing import Dict, Optional, Callable
14
+
15
+ from .patricia import PatriciaTrie
16
+ from .account import Account
17
+
18
+
19
+ class Accounts:
20
+ """Light wrapper around a PatriciaTrie (address → body_hash) plus
21
+ an in‑memory cache of Account objects currently being worked on.
22
+ """
23
+
24
+ # ------------------------------------------------------------
25
+ # construction
26
+ # ------------------------------------------------------------
27
+ def __init__(
28
+ self,
29
+ root_hash: Optional[bytes] = None,
30
+ *,
31
+ get_node_fn: Optional[Callable[[bytes], Optional[bytes]]] = None,
32
+ ) -> None:
33
+ """Wrap an existing state trie *or* start empty (root_hash=None).
34
+
35
+ `get_node_fn` (optional) is a callback that retrieves raw node bytes
36
+ when the underlying PatriciaTrie encounters an unknown hash – useful
37
+ for disk or network-backed light clients.
38
+ """
39
+ self._remote_get = get_node_fn
40
+ # Instantiate the trie; we pass the external fetcher straight in.
41
+ # PatriciaTrie is expected to accept `node_get` and `root_hash`.
42
+ self._trie = PatriciaTrie(node_get=get_node_fn, root_hash=root_hash)
43
+
44
+ # Working‑set cache: address → Account instance
45
+ self._cache: Dict[bytes, Account] = {}
46
+
47
+ # ------------------------------------------------------------
48
+ # public introspection
49
+ # ------------------------------------------------------------
50
+ @property
51
+ def root_hash(self) -> Optional[bytes]:
52
+ """Current trie root (updates automatically after puts)."""
53
+ return self._trie.root_hash
54
+
55
+ # ------------------------------------------------------------
56
+ # account access – read‑only for now
57
+ # ------------------------------------------------------------
58
+ def get_account(self, address: bytes) -> Optional[Account]:
59
+ """Return an *Account* for `address`, or *None* if it doesn't exist.
60
+
61
+ • First check the in‑memory cache (so repeat reads/updates reuse the
62
+ same object).
63
+ • Otherwise look up `body_hash` in the PatriciaTrie.
64
+ • If found, create a lightweight `Account` wrapper, cache it, and
65
+ return it. The Account is initialised with the same external
66
+ node‑fetcher so its own Merkle lookups can go remote if needed.
67
+ """
68
+ # cache hit → hot path
69
+ if address in self._cache:
70
+ return self._cache[address]
71
+
72
+ # trie lookup (raw body_hash)
73
+ body_hash: Optional[bytes] = self._trie.get(address)
74
+ if body_hash is None:
75
+ return None
76
+
77
+ # wrap in Account and cache
78
+ acc = Account(body_hash, get_node_fn=self._remote_get)
79
+ self._cache[address] = acc
80
+ return acc
@@ -195,9 +195,12 @@ class PatriciaTrie:
195
195
 
196
196
  # 4.3 – matched entire key → update value
197
197
  if key_pos == total_bits:
198
- self._invalidate_hash(node)
198
+ old_hash = node.hash()
199
199
  node.value = value
200
+ self._invalidate_hash(node)
200
201
  new_hash = node.hash()
202
+ if new_hash != old_hash:
203
+ self.nodes.pop(old_hash, None)
201
204
  self.nodes[new_hash] = node
202
205
  self._bubble(stack, new_hash)
203
206
  return
@@ -233,12 +236,12 @@ class PatriciaTrie:
233
236
  value: bytes,
234
237
  stack: List[Tuple[PatriciaNode, bytes, int]],
235
238
  ) -> None:
236
- # key_pos points to routing bit; leaf stores the rest after that bit
237
239
  tail_len = len(key) * 8 - (key_pos + 1)
238
240
  tail_bits, tail_len = self._bit_slice(key, key_pos + 1, tail_len)
239
241
  leaf = self._make_node(tail_bits, tail_len, value, None, None)
240
242
 
241
- # attach to parent
243
+ old_parent_hash = parent.hash()
244
+
242
245
  if dir_bit:
243
246
  parent.child_1 = leaf.hash()
244
247
  else:
@@ -246,9 +249,12 @@ class PatriciaTrie:
246
249
 
247
250
  self._invalidate_hash(parent)
248
251
  new_parent_hash = parent.hash()
252
+ if new_parent_hash != old_parent_hash:
253
+ self.nodes.pop(old_parent_hash, None)
249
254
  self.nodes[new_parent_hash] = parent
250
255
  self._bubble(stack, new_parent_hash)
251
256
 
257
+
252
258
  def _split_and_insert(
253
259
  self,
254
260
  node: PatriciaNode,
@@ -277,10 +283,14 @@ class PatriciaTrie:
277
283
  lcp + 1, # start *after* divergence bit
278
284
  node.key_len - lcp - 1 # may be zero
279
285
  )
286
+ old_node_hash = node.hash()
287
+
280
288
  node.key = old_suffix_bits
281
289
  node.key_len = old_suffix_len
282
290
  self._invalidate_hash(node)
283
291
  new_node_hash = node.hash()
292
+ if new_node_hash != old_node_hash:
293
+ self.nodes.pop(old_node_hash, None)
284
294
  self.nodes[new_node_hash] = node
285
295
 
286
296
  # ➍—new leaf for the key being inserted (unchanged)
@@ -341,15 +351,21 @@ class PatriciaTrie:
341
351
  """
342
352
  while stack:
343
353
  parent, old_hash, dir_bit = stack.pop()
354
+
344
355
  if dir_bit == 0:
345
356
  parent.child_0 = new_hash
346
357
  else:
347
358
  parent.child_1 = new_hash
359
+
348
360
  self._invalidate_hash(parent)
349
361
  new_hash = parent.hash()
362
+ if new_hash != old_hash:
363
+ self.nodes.pop(old_hash, None)
350
364
  self.nodes[new_hash] = parent
365
+
351
366
  self.root_hash = new_hash
352
367
 
368
+
353
369
  def _bit_slice(
354
370
  self,
355
371
  buf: bytes,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astreum
3
- Version: 0.2.19
3
+ Version: 0.2.21
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
@@ -19,6 +19,7 @@ src/astreum/lispeum/parser.py
19
19
  src/astreum/lispeum/tokenizer.py
20
20
  src/astreum/models/__init__.py
21
21
  src/astreum/models/account.py
22
+ src/astreum/models/accounts.py
22
23
  src/astreum/models/block.py
23
24
  src/astreum/models/merkle.py
24
25
  src/astreum/models/patricia.py
File without changes
File without changes
File without changes
File without changes
File without changes