astreum 0.2.40__py3-none-any.whl → 0.2.41__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.
astreum/_storage/atom.py CHANGED
@@ -52,11 +52,11 @@ class Atom:
52
52
  data = buf[len(ZERO32):]
53
53
  return Atom(data=data, next=next_hash, size=len(data))
54
54
 
55
- def expr_to_atoms(e: Expr) -> Tuple[bytes, List[Atom]]:
56
- def symbol(value: str) -> Tuple[bytes, List[Atom]]:
57
- val = value.encode("utf-8")
58
- val_atom = Atom.from_data(data=val)
59
- typ_atom = Atom.from_data(b"symbol", val_atom.object_id())
55
+ def expr_to_atoms(e: Expr) -> Tuple[bytes, List[Atom]]:
56
+ def symbol(value: str) -> Tuple[bytes, List[Atom]]:
57
+ val = value.encode("utf-8")
58
+ val_atom = Atom.from_data(data=val)
59
+ typ_atom = Atom.from_data(b"symbol", val_atom.object_id())
60
60
  return typ_atom.object_id(), [val_atom, typ_atom]
61
61
 
62
62
  def bytes(data: bytes) -> Tuple[bytes, List[Atom]]:
@@ -96,5 +96,22 @@ def expr_to_atoms(e: Expr) -> Tuple[bytes, List[Atom]]:
96
96
  if isinstance(e, Expr.Error):
97
97
  return err(e.topic, e.origin)
98
98
  if isinstance(e, Expr.ListExpr):
99
- return lst(e.elements)
100
- raise TypeError("unknown Expr variant")
99
+ return lst(e.elements)
100
+ raise TypeError("unknown Expr variant")
101
+
102
+
103
+ def bytes_list_to_atoms(values: List[bytes]) -> Tuple[bytes, List[Atom]]:
104
+ """Build a forward-ordered linked list of atoms from byte payloads.
105
+
106
+ Returns the head object's hash (ZERO32 if no values) and the atoms created.
107
+ """
108
+ next_hash = ZERO32
109
+ atoms: List[Atom] = []
110
+
111
+ for value in reversed(values):
112
+ atom = Atom.from_data(data=bytes(value), next_hash=next_hash)
113
+ atoms.append(atom)
114
+ next_hash = atom.object_id()
115
+
116
+ atoms.reverse()
117
+ return (next_hash if values else ZERO32), atoms
astreum/models/block.py CHANGED
@@ -4,8 +4,8 @@ from threading import Thread
4
4
  from typing import List, Dict, Any, Optional, Union
5
5
 
6
6
  from astreum.crypto.wesolowski import vdf_generate, vdf_verify
7
- from astreum.models.account import Account
8
- from astreum.models.accounts import Accounts
7
+ from astreum._consensus.account import Account
8
+ from astreum._consensus.accounts import Accounts
9
9
  from astreum.models.patricia import PatriciaTrie
10
10
  from astreum.models.transaction import Transaction
11
11
  from ..crypto import ed25519