-
Notifications
You must be signed in to change notification settings - Fork 83
/
transaction_pool.py
39 lines (34 loc) · 1.21 KB
/
transaction_pool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class TransactionPool:
def __init__(self):
self.transaction_map = {}
def set_transaction(self, transaction):
"""
Set a transaction in the transaction pool.
"""
self.transaction_map[transaction.id] = transaction
def existing_transaction(self, address):
"""
Find a transaction generated by the address in the transaction pool
"""
for transaction in self.transaction_map.values():
if transaction.input['address'] == address:
return transaction
def transaction_data(self):
"""
Return the transactions of thje transaction pool represented in their
json serialized form.
"""
return list(map(
lambda transaction: transaction.to_json(),
self.transaction_map.values()
))
def clear_blockchain_transactions(self, blockchain):
"""
Delete blockchain recorded transactions from the transaction pool.
"""
for block in blockchain.chain:
for transaction in block.data:
try:
del self.transaction_map[transaction['id']]
except KeyError:
pass