diff --git a/blockchain.py b/blockchain.py index e5f289a..807c560 100644 --- a/blockchain.py +++ b/blockchain.py @@ -84,6 +84,40 @@ class FullBlock: previous_block = blockchain.get_block(self.previous_hash) return previous_block.get_difficulty_info(steps-1, blockchain) +@dataclass +class Datastructure: + nonce:int + timestamp: int + previous_hash: bytes + message: bytes + difficulty_sum: int + miner_pubkey: bytes + transaction: int + + + def get_block_raw(self): + sender_pubkey_raw = Ed25519PublicKey.from_public_bytes(self.sender) + msg_raw = self.nonce.to_bytes(8, "big") + \ + self.timestamp.to_bytes(8, "big") + \ + self.previous_hash + \ + self.message + \ + self.difficulty_sum.to_bytes(32, "big") + \ + self.miner_pubkey +\ + self.transaction.to_bytes(148, "big") + try: + sender_pubkey_raw.verify(self.previous_hash,msg_raw) + except InvalidSignature: + return False + return self.transaction >=1 + def is_valid_after_transaction(self.tansaction): + if(self.transaction is None): + return False + + + + + + class Blockchain: def __init__(self): # maps block hashes to block instances