astreum 0.2.8__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 +185 -0
- {astreum-0.2.8.dist-info → astreum-0.2.10.dist-info}/METADATA +1 -1
- {astreum-0.2.8.dist-info → astreum-0.2.10.dist-info}/RECORD +6 -6
- {astreum-0.2.8.dist-info → astreum-0.2.10.dist-info}/WHEEL +0 -0
- {astreum-0.2.8.dist-info → astreum-0.2.10.dist-info}/licenses/LICENSE +0 -0
- {astreum-0.2.8.dist-info → astreum-0.2.10.dist-info}/top_level.txt +0 -0
astreum/node.py
CHANGED
|
@@ -324,6 +324,181 @@ class Env:
|
|
|
324
324
|
)
|
|
325
325
|
|
|
326
326
|
|
|
327
|
+
class Transaction:
|
|
328
|
+
def __init__(
|
|
329
|
+
self,
|
|
330
|
+
sender_pk: bytes,
|
|
331
|
+
recipient_pk: bytes,
|
|
332
|
+
amount: int,
|
|
333
|
+
fee: int,
|
|
334
|
+
nonce: int,
|
|
335
|
+
signature: bytes | None = None,
|
|
336
|
+
) -> None:
|
|
337
|
+
self.sender_pk = sender_pk
|
|
338
|
+
self.recipient_pk = recipient_pk
|
|
339
|
+
self.amount = amount
|
|
340
|
+
self.fee = fee
|
|
341
|
+
self.nonce = nonce
|
|
342
|
+
self.signature = signature
|
|
343
|
+
|
|
344
|
+
if self.amount < 0 or self.fee < 0:
|
|
345
|
+
raise ValueError("amount and fee must be non-negative")
|
|
346
|
+
|
|
347
|
+
if self.fee % 2 != 0:
|
|
348
|
+
raise ValueError("fee must be divisible by two")
|
|
349
|
+
|
|
350
|
+
self.tx_body_hash: bytes = blake3.blake3(self._body_bytes()).digest()
|
|
351
|
+
|
|
352
|
+
if self.signature is not None:
|
|
353
|
+
self.tx_hash = blake3.blake3(self.tx_body_hash + self.signature).digest()
|
|
354
|
+
else:
|
|
355
|
+
self.tx_hash = None
|
|
356
|
+
|
|
357
|
+
def sign(self, priv_key: ed25519.Ed25519PrivateKey) -> None:
|
|
358
|
+
if self.signature is not None:
|
|
359
|
+
raise ValueError("transaction already signed")
|
|
360
|
+
sig = priv_key.sign(self.tx_body_hash)
|
|
361
|
+
self.signature = sig
|
|
362
|
+
self.tx_hash = blake3.blake3(self.tx_body_hash + sig).digest()
|
|
363
|
+
|
|
364
|
+
def verify_signature(self) -> bool:
|
|
365
|
+
if self.signature is None:
|
|
366
|
+
return False
|
|
367
|
+
try:
|
|
368
|
+
pub = ed25519.Ed25519PublicKey.from_public_bytes(self.sender_pk)
|
|
369
|
+
pub.verify(self.signature, self.tx_body_hash)
|
|
370
|
+
return True
|
|
371
|
+
except Exception:
|
|
372
|
+
return False
|
|
373
|
+
|
|
374
|
+
def to_bytes(self) -> bytes:
|
|
375
|
+
sig = self.signature or b""
|
|
376
|
+
return encode([
|
|
377
|
+
self.sender_pk,
|
|
378
|
+
self.recipient_pk,
|
|
379
|
+
self.amount,
|
|
380
|
+
self.fee,
|
|
381
|
+
self.nonce,
|
|
382
|
+
sig,
|
|
383
|
+
])
|
|
384
|
+
|
|
385
|
+
@classmethod
|
|
386
|
+
def from_bytes(cls, blob: bytes) -> 'Transaction':
|
|
387
|
+
sender, recipient, amount, fee, nonce, sig = decode(blob)
|
|
388
|
+
return cls(sender, recipient, int(amount), int(fee), int(nonce), sig)
|
|
389
|
+
|
|
390
|
+
def _body_bytes(self) -> bytes:
|
|
391
|
+
return encode([
|
|
392
|
+
self.sender_pk,
|
|
393
|
+
self.recipient_pk,
|
|
394
|
+
self.amount,
|
|
395
|
+
self.fee,
|
|
396
|
+
self.nonce,
|
|
397
|
+
])
|
|
398
|
+
|
|
399
|
+
def __eq__(self, other: Any) -> bool:
|
|
400
|
+
if not isinstance(other, Transaction):
|
|
401
|
+
return NotImplemented
|
|
402
|
+
return self.tx_hash == other.tx_hash
|
|
403
|
+
|
|
404
|
+
def __hash__(self) -> int:
|
|
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()
|
|
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
|
+
|
|
327
502
|
class Node:
|
|
328
503
|
def __init__(self, config: dict = {}):
|
|
329
504
|
self._machine_setup()
|
|
@@ -331,6 +506,16 @@ class Node:
|
|
|
331
506
|
if not machine_only:
|
|
332
507
|
self._storage_setup(config=config)
|
|
333
508
|
self._relay_setup(config=config)
|
|
509
|
+
self._validation_setup(config=config)
|
|
510
|
+
|
|
511
|
+
def _validation_setup(self, config: dict):
|
|
512
|
+
if True:
|
|
513
|
+
self.validator_transactions: Dict[bytes, Transaction] = {}
|
|
514
|
+
# validator thread
|
|
515
|
+
pass
|
|
516
|
+
|
|
517
|
+
def _create_block(self):
|
|
518
|
+
pass
|
|
334
519
|
|
|
335
520
|
# STORAGE METHODS
|
|
336
521
|
def _storage_setup(self, config: dict):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: astreum
|
|
3
|
-
Version: 0.2.
|
|
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=
|
|
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.
|
|
17
|
-
astreum-0.2.
|
|
18
|
-
astreum-0.2.
|
|
19
|
-
astreum-0.2.
|
|
20
|
-
astreum-0.2.
|
|
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,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|