Allow clients to transmit payments
This commit is contained in:
@@ -232,7 +232,7 @@ class OpenTransactions:
|
|||||||
used_transaction_ids = latest_block.used_transaction_ids.copy()
|
used_transaction_ids = latest_block.used_transaction_ids.copy()
|
||||||
balances = latest_block.balances.copy()
|
balances = latest_block.balances.copy()
|
||||||
def is_valid(transaction):
|
def is_valid(transaction):
|
||||||
sender_tuple = (transaction.sender, transation.id)
|
sender_tuple = (transaction.sender, transaction.id)
|
||||||
if sender_tuple in used_transaction_ids:
|
if sender_tuple in used_transaction_ids:
|
||||||
return False
|
return False
|
||||||
balance = balances.get(transaction.sender) or 0
|
balance = balances.get(transaction.sender) or 0
|
||||||
@@ -254,7 +254,7 @@ class OpenTransactions:
|
|||||||
else:
|
else:
|
||||||
transaction = self.__open_transactions[i]
|
transaction = self.__open_transactions[i]
|
||||||
transaction_data = transaction.transaction_fee.to_bytes(8, "big") + \
|
transaction_data = transaction.transaction_fee.to_bytes(8, "big") + \
|
||||||
transaction.sender_pubkey + \
|
transaction.sender + \
|
||||||
transaction.id.to_bytes(4, "big")
|
transaction.id.to_bytes(4, "big")
|
||||||
current_hash = hashlib.sha256(current_hash + transaction_data).digest()
|
current_hash = hashlib.sha256(current_hash + transaction_data).digest()
|
||||||
self.__hashes.append(current_hash)
|
self.__hashes.append(current_hash)
|
||||||
@@ -265,8 +265,8 @@ class Blockchain:
|
|||||||
self.__block_map = {}
|
self.__block_map = {}
|
||||||
self.__latest_block_hash = None
|
self.__latest_block_hash = None
|
||||||
self.__lock = Lock()
|
self.__lock = Lock()
|
||||||
self.__load_blocks_from_disk()
|
|
||||||
self.open_transactions = OpenTransactions(self)
|
self.open_transactions = OpenTransactions(self)
|
||||||
|
self.__load_blocks_from_disk()
|
||||||
def __load_blocks_from_disk(self):
|
def __load_blocks_from_disk(self):
|
||||||
last_valid = None
|
last_valid = None
|
||||||
try:
|
try:
|
||||||
|
|||||||
9
node.py
9
node.py
@@ -360,6 +360,15 @@ def receiver(node, b):
|
|||||||
}
|
}
|
||||||
identifier = (addr[0:2], "transaction")
|
identifier = (addr[0:2], "transaction")
|
||||||
receive_observer.publish(identifier, event_obj)
|
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:
|
else:
|
||||||
log(f"Got a udp message of unknown type from {sender}. (type {msg_type})")
|
log(f"Got a udp message of unknown type from {sender}. (type {msg_type})")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user