-
Notifications
You must be signed in to change notification settings - Fork 1
/
UTXO_pool.py
47 lines (34 loc) · 1.13 KB
/
UTXO_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
40
41
42
43
44
45
46
47
from collections import defaultdict as dd
import sys
class UTXO_pool:
def __init__(self):
self.mappings = dict({})
def add_UTXO(self, utxo, txn_output):
# add the utxo and txn output
self.mappings[utxo] = txn_output
def delete_utxo(self, utxo):
del self.mappings[utxo]
def get_txn_output(self, utxo):
return self.mappings[utxo]
def has_utxo(self, utxo):
return utxo in self.mappings
def get_all_utxo(self):
return list(self.mappings.keys())
# return dict with Key as public key of miner
# and value as total unspent coins in that block
def get_total_unspent_coins(self):
total_unspent_coins = dd(int)
for utxo, op in self.mappings.items():
# for op in txn_outputs:
total_unspent_coins[op.pubkey_hash] += op.value
return total_unspent_coins
def get_total_unspent_utxo(self):
total_unspent_utxo = dd(list)
for utxo, op in self.mappings.items():
# for op in txn_outputs:
total_unspent_utxo[op.pubkey_hash].append((utxo,op.value))
return total_unspent_utxo
def __sizeof__(self):
size = 0
for key in self.mappings.keys():
size += sys.getsizeof(key) + sys.getsizeof(self.mappings[key])