CoolFace
Apppublic

Omnibus-archive/decentral-test-mod

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
node.py33 linesDownload Raw Back to node
1from Crypto.Hash import SHA2562from Crypto.PublicKey import RSA3from Crypto.Signature import pkcs1_154 5from node.block import Block6 7 8class NodeTransaction:9    def __init__(self, blockchain: Block):10        self.blockchain = blockchain11        self.transaction_data = ""12        self.signature = ""13 14    @staticmethod15    def validate_signature(public_key: bytes, signature: bytes, transaction_data: bytes):16        public_key_object = RSA.import_key(public_key)17        transaction_hash = SHA256.new(transaction_data)18        pkcs1_15.new(public_key_object).verify(transaction_hash, signature)19 20    def validate_funds(self, sender_address: bytes, amount: int) -> bool:21        sender_balance = 022        current_block = self.blockchain23        while current_block:24            if current_block.transaction_data["sender"] == sender_address:25                sender_balance = sender_balance - current_block.transaction_data["amount"]26            if current_block.transaction_data["receiver"] == sender_address:27                sender_balance = sender_balance + current_block.transaction_data["amount"]28            current_block = current_block.previous_block29        if amount <= sender_balance:30            return True31        else:32            return False33