astreum 0.2.21__tar.gz → 0.2.23__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 (30) hide show
  1. {astreum-0.2.21/src/astreum.egg-info → astreum-0.2.23}/PKG-INFO +1 -1
  2. {astreum-0.2.21 → astreum-0.2.23}/pyproject.toml +1 -1
  3. astreum-0.2.23/src/astreum/models/accounts.py +34 -0
  4. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/models/block.py +40 -0
  5. {astreum-0.2.21 → astreum-0.2.23/src/astreum.egg-info}/PKG-INFO +1 -1
  6. astreum-0.2.21/src/astreum/models/accounts.py +0 -80
  7. {astreum-0.2.21 → astreum-0.2.23}/LICENSE +0 -0
  8. {astreum-0.2.21 → astreum-0.2.23}/README.md +0 -0
  9. {astreum-0.2.21 → astreum-0.2.23}/setup.cfg +0 -0
  10. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/__init__.py +0 -0
  11. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/crypto/__init__.py +0 -0
  12. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/crypto/ed25519.py +0 -0
  13. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/crypto/quadratic_form.py +0 -0
  14. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/crypto/wesolowski.py +0 -0
  15. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/crypto/x25519.py +0 -0
  16. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/format.py +0 -0
  17. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/lispeum/__init__.py +0 -0
  18. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/lispeum/parser.py +0 -0
  19. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/lispeum/tokenizer.py +0 -0
  20. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/models/__init__.py +0 -0
  21. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/models/account.py +0 -0
  22. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/models/merkle.py +0 -0
  23. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/models/patricia.py +0 -0
  24. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/models/transaction.py +0 -0
  25. {astreum-0.2.21 → astreum-0.2.23}/src/astreum/node.py +0 -0
  26. {astreum-0.2.21 → astreum-0.2.23}/src/astreum.egg-info/SOURCES.txt +0 -0
  27. {astreum-0.2.21 → astreum-0.2.23}/src/astreum.egg-info/dependency_links.txt +0 -0
  28. {astreum-0.2.21 → astreum-0.2.23}/src/astreum.egg-info/requires.txt +0 -0
  29. {astreum-0.2.21 → astreum-0.2.23}/src/astreum.egg-info/top_level.txt +0 -0
  30. {astreum-0.2.21 → astreum-0.2.23}/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.21
3
+ Version: 0.2.23
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.21"
3
+ version = "0.2.23"
4
4
  authors = [
5
5
  { name="Roy R. O. Okello", email="roy@stelar.xyz" },
6
6
  ]
@@ -0,0 +1,34 @@
1
+ from __future__ import annotations
2
+ from typing import Dict, Optional, Callable
3
+ from .patricia import PatriciaTrie
4
+ from .account import Account
5
+
6
+ class Accounts:
7
+ def __init__(
8
+ self,
9
+ root_hash: Optional[bytes] = None,
10
+ global_get_fn: Optional[Callable[[bytes], Optional[bytes]]] = None,
11
+ ) -> None:
12
+ self._global_get_fn = global_get_fn
13
+ self._trie = PatriciaTrie(node_get=global_get_fn, root_hash=root_hash)
14
+ self._cache: Dict[bytes, Account] = {}
15
+
16
+ @property
17
+ def root_hash(self) -> Optional[bytes]:
18
+ return self._trie.root_hash
19
+
20
+ def get_account(self, address: bytes) -> Optional[Account]:
21
+ if address in self._cache:
22
+ return self._cache[address]
23
+
24
+ body_hash: Optional[bytes] = self._trie.get(address)
25
+ if body_hash is None:
26
+ return None
27
+
28
+ acc = Account(body_hash, get_node_fn=self._global_get_fn)
29
+ self._cache[address] = acc
30
+ return acc
31
+
32
+ def set_account(self, address: bytes, account: Account) -> None:
33
+ self._cache[address] = account
34
+ self._trie.put(address, account.body_hash())
@@ -1,6 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from typing import List, Dict, Any, Optional, Union
4
+
5
+ from astreum.models.account import Account
6
+ from astreum.models.accounts import Accounts
7
+ from astreum.models.patricia import PatriciaTrie
4
8
  from ..crypto import ed25519
5
9
  from .merkle import MerkleTree
6
10
 
@@ -128,3 +132,39 @@ class Block:
128
132
  return True
129
133
  except Exception:
130
134
  return False
135
+
136
+ @classmethod
137
+ def genesis(cls, validator_addr: bytes) -> "Block":
138
+ # 1 . validator-stakes sub-trie
139
+ stake_trie = PatriciaTrie()
140
+ stake_trie.put(validator_addr, (1).to_bytes(32, "big"))
141
+ stake_root = stake_trie.root_hash
142
+
143
+ # 2 . build the two Account bodies
144
+ validator_acct = Account.create(balance=0, data=b"", nonce=0)
145
+ treasury_acct = Account.create(balance=1, data=stake_root, nonce=0)
146
+
147
+ # 3 . global Accounts structure
148
+ accts = Accounts()
149
+ accts.set_account(validator_addr, validator_acct)
150
+ accts.set_account(b"\x11" * 32, treasury_acct)
151
+ accounts_hash = accts.root_hash
152
+
153
+ # 4 . constant body fields for genesis
154
+ body_kwargs = dict(
155
+ number = 0,
156
+ prev_block_hash = b"\x00" * 32,
157
+ timestamp = 0,
158
+ accounts_hash = accounts_hash,
159
+ transactions_total_fees = 0,
160
+ transaction_limit = 0,
161
+ transactions_root_hash = b"\x00" * 32,
162
+ delay_difficulty = 0,
163
+ delay_output = b"",
164
+ delay_proof = b"",
165
+ validator_pk = validator_addr,
166
+ signature = b"",
167
+ )
168
+
169
+ # 5 . build and return the block
170
+ return cls.create(**body_kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astreum
3
- Version: 0.2.21
3
+ Version: 0.2.23
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,80 +0,0 @@
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
File without changes
File without changes
File without changes
File without changes
File without changes