astreum 0.2.9__py3-none-any.whl → 0.2.10__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.py CHANGED
@@ -403,7 +403,102 @@ class Transaction:
403
403
 
404
404
  def __hash__(self) -> int:
405
405
  return int.from_bytes(self.tx_hash, 'big')
406
+
407
+ class Block:
408
+ def __init__(
409
+ self,
410
+ *,
411
+ number: int,
412
+ prev_block_hash: bytes,
413
+ timestamp: int,
414
+ accounts_hash: bytes,
415
+ total_astre_burned: int,
416
+ tx_limit: int,
417
+ tx_root: bytes,
418
+ vdf_difficulty: int,
419
+ vdf_output: bytes,
420
+ vdf_proof: bytes,
421
+ validator_pk: bytes,
422
+ signature: bytes,
423
+ ) -> None:
424
+ self.accounts_hash = accounts_hash
425
+ self.number = int(number)
426
+ self.prev_block_hash = prev_block_hash
427
+ self.timestamp = int(timestamp)
428
+ self.total_astre_burned = int(total_astre_burned)
429
+ self.tx_limit = int(tx_limit)
430
+ self.tx_root = tx_root
431
+ self.validator_pk = validator_pk
432
+ self.vdf_difficulty = int(vdf_difficulty)
433
+ self.vdf_output = vdf_output
434
+ self.vdf_proof = vdf_proof
435
+ self.signature = signature
436
+ self.body_hash = self._compute_body_hash()
437
+
438
+ def _body_fields_without_sig(self) -> list:
439
+ return [
440
+ self.accounts_hash,
441
+ self.number,
442
+ self.prev_block_hash,
443
+ self.timestamp,
444
+ self.total_astre_burned,
445
+ self.tx_limit,
446
+ self.tx_root,
447
+ self.validator_pk,
448
+ self.vdf_difficulty,
449
+ self.vdf_output,
450
+ self.vdf_proof,
451
+ ]
452
+
453
+ def _compute_body_hash(self) -> bytes:
454
+ return blake3.blake3(encode(self._body_fields_without_sig())).digest()
406
455
 
456
+ def to_bytes(self) -> bytes:
457
+ return encode(self._body_fields_without_sig() + [self.signature])
458
+
459
+ @classmethod
460
+ def from_bytes(cls, blob: bytes) -> "Block":
461
+ (
462
+ accounts_hash,
463
+ number,
464
+ prev_block_hash,
465
+ timestamp,
466
+ total_astre_burned,
467
+ tx_limit,
468
+ tx_root,
469
+ validator_pk,
470
+ vdf_difficulty,
471
+ vdf_output,
472
+ vdf_proof,
473
+ signature
474
+ ) = decode(blob)
475
+ return cls(
476
+ number=int(number),
477
+ prev_block_hash=prev_block_hash,
478
+ timestamp=int(timestamp),
479
+ accounts_hash=accounts_hash,
480
+ total_astre_burned=int(total_astre_burned),
481
+ tx_limit=int(tx_limit),
482
+ tx_root=tx_root,
483
+ vdf_difficulty=int(vdf_difficulty),
484
+ vdf_output=vdf_output,
485
+ vdf_proof=vdf_proof,
486
+ validator_pk=validator_pk,
487
+ signature=signature,
488
+ )
489
+
490
+ @property
491
+ def hash(self) -> bytes:
492
+ return blake3.blake3(self.body_hash + self.signature).digest()
493
+
494
+ def verify_block_signature(self) -> bool:
495
+ try:
496
+ pub = ed25519.Ed25519PublicKey.from_public_bytes(self.validator_pk)
497
+ pub.verify(self.signature, self.body_hash)
498
+ return True
499
+ except Exception:
500
+ return False
501
+
407
502
  class Node:
408
503
  def __init__(self, config: dict = {}):
409
504
  self._machine_setup()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astreum
3
- Version: 0.2.9
3
+ Version: 0.2.10
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
  astreum/__init__.py,sha256=y2Ok3EY_FstcmlVASr80lGR_0w-dH-SXDCCQFmL6uwA,28
2
2
  astreum/format.py,sha256=X4tG5GGPweNCE54bHYkLFiuLTbmpy5upO_s1Cef-MGA,2711
3
- astreum/node.py,sha256=LImdMz2-eeVrR67p_67bVBUaVgo-atoe4fgU42bnXAA,48659
3
+ astreum/node.py,sha256=neP-Ix5m0dm0eGOpaVkk9YmtB6LMvtCN8bnx25ZkW1E,51513
4
4
  astreum/_node/__init__.py,sha256=7yz1YHo0DCUgUQvJf75qdUo_ocl5-XZRU-Vc2NhcvJs,18639
5
5
  astreum/_node/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  astreum/_node/storage/merkle.py,sha256=XCQBrHbwI0FuPTCUwHOy-Kva3uWbvCdw_-13hRPf1UI,10219
@@ -13,8 +13,8 @@ astreum/crypto/x25519.py,sha256=i29v4BmwKRcbz9E7NKqFDQyxzFtJUqN0St9jd7GS1uA,1137
13
13
  astreum/lispeum/__init__.py,sha256=K-NDzIjtIsXzC9X7lnYvlvIaVxjFcY7WNsgLIE3DH3U,58
14
14
  astreum/lispeum/parser.py,sha256=jQRzZYvBuSg8t_bxsbt1-WcHaR_LPveHNX7Qlxhaw-M,1165
15
15
  astreum/lispeum/tokenizer.py,sha256=J-I7MEd0r2ZoVqxvRPlu-Afe2ZdM0tKXXhf1R4SxYTo,1429
16
- astreum-0.2.9.dist-info/licenses/LICENSE,sha256=gYBvRDP-cPLmTyJhvZ346QkrYW_eleke4Z2Yyyu43eQ,1089
17
- astreum-0.2.9.dist-info/METADATA,sha256=XISFbnyLNnvRhitMrPeQVC78T15Ipy9JNgO8IhVbSH8,5453
18
- astreum-0.2.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
- astreum-0.2.9.dist-info/top_level.txt,sha256=1EG1GmkOk3NPmUA98FZNdKouhRyget-KiFiMk0i2Uz0,8
20
- astreum-0.2.9.dist-info/RECORD,,
16
+ astreum-0.2.10.dist-info/licenses/LICENSE,sha256=gYBvRDP-cPLmTyJhvZ346QkrYW_eleke4Z2Yyyu43eQ,1089
17
+ astreum-0.2.10.dist-info/METADATA,sha256=R1hg4dzmqSOqaPLpAM6hBpB_erKa_ooOq15SnKtwxZw,5454
18
+ astreum-0.2.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
+ astreum-0.2.10.dist-info/top_level.txt,sha256=1EG1GmkOk3NPmUA98FZNdKouhRyget-KiFiMk0i2Uz0,8
20
+ astreum-0.2.10.dist-info/RECORD,,