astreum 0.2.8__py3-none-any.whl → 0.2.9__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 +90 -0
- {astreum-0.2.8.dist-info → astreum-0.2.9.dist-info}/METADATA +1 -1
- {astreum-0.2.8.dist-info → astreum-0.2.9.dist-info}/RECORD +6 -6
- {astreum-0.2.8.dist-info → astreum-0.2.9.dist-info}/WHEEL +0 -0
- {astreum-0.2.8.dist-info → astreum-0.2.9.dist-info}/licenses/LICENSE +0 -0
- {astreum-0.2.8.dist-info → astreum-0.2.9.dist-info}/top_level.txt +0 -0
astreum/node.py
CHANGED
|
@@ -324,6 +324,86 @@ 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
|
+
|
|
327
407
|
class Node:
|
|
328
408
|
def __init__(self, config: dict = {}):
|
|
329
409
|
self._machine_setup()
|
|
@@ -331,6 +411,16 @@ class Node:
|
|
|
331
411
|
if not machine_only:
|
|
332
412
|
self._storage_setup(config=config)
|
|
333
413
|
self._relay_setup(config=config)
|
|
414
|
+
self._validation_setup(config=config)
|
|
415
|
+
|
|
416
|
+
def _validation_setup(self, config: dict):
|
|
417
|
+
if True:
|
|
418
|
+
self.validator_transactions: Dict[bytes, Transaction] = {}
|
|
419
|
+
# validator thread
|
|
420
|
+
pass
|
|
421
|
+
|
|
422
|
+
def _create_block(self):
|
|
423
|
+
pass
|
|
334
424
|
|
|
335
425
|
# STORAGE METHODS
|
|
336
426
|
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.9
|
|
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=LImdMz2-eeVrR67p_67bVBUaVgo-atoe4fgU42bnXAA,48659
|
|
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.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,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|