Allow clients to transmit payments

This commit is contained in:
2024-03-20 22:59:44 +01:00
parent c6394d2ca1
commit 54c81810ee
3 changed files with 12 additions and 3 deletions

View File

@@ -232,7 +232,7 @@ class OpenTransactions:
used_transaction_ids = latest_block.used_transaction_ids.copy()
balances = latest_block.balances.copy()
def is_valid(transaction):
sender_tuple = (transaction.sender, transation.id)
sender_tuple = (transaction.sender, transaction.id)
if sender_tuple in used_transaction_ids:
return False
balance = balances.get(transaction.sender) or 0
@@ -254,7 +254,7 @@ class OpenTransactions:
else:
transaction = self.__open_transactions[i]
transaction_data = transaction.transaction_fee.to_bytes(8, "big") + \
transaction.sender_pubkey + \
transaction.sender + \
transaction.id.to_bytes(4, "big")
current_hash = hashlib.sha256(current_hash + transaction_data).digest()
self.__hashes.append(current_hash)
@@ -265,8 +265,8 @@ class Blockchain:
self.__block_map = {}
self.__latest_block_hash = None
self.__lock = Lock()
self.__load_blocks_from_disk()
self.open_transactions = OpenTransactions(self)
self.__load_blocks_from_disk()
def __load_blocks_from_disk(self):
last_valid = None
try:

View File

@@ -360,6 +360,15 @@ def receiver(node, b):
}
identifier = (addr[0:2], "transaction")
receive_observer.publish(identifier, event_obj)
elif msg_type == 9:
# payment request
if msg_len != 153:
log(f"Got a payment of wrong length ({msg_len} bytes from {sender}, but expected 153 bytes)")
continue
parsed_transaction = blockchain.Transaction.from_bytes(msg[5:153])
if not parsed_transaction.is_valid():
continue
b.open_transactions.add(parsed_transaction)
else:
log(f"Got a udp message of unknown type from {sender}. (type {msg_type})")

View File