method get_block_raw

This commit is contained in:
2024-03-04 18:42:17 +01:00
parent f57eab2e3e
commit c48d2d8e0d

View File

@@ -84,6 +84,40 @@ class FullBlock:
previous_block = blockchain.get_block(self.previous_hash) previous_block = blockchain.get_block(self.previous_hash)
return previous_block.get_difficulty_info(steps-1, blockchain) 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: class Blockchain:
def __init__(self): def __init__(self):
# maps block hashes to block instances # maps block hashes to block instances