-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtxset.py
47 lines (30 loc) · 1.12 KB
/
txset.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
import functools
# An abstract class that subsumes CandidateSets and AncestorSets
class TransactionSet():
def __init__(self, txs):
self.txs = txs
self.weight = -1
self.feerate = -1
self.hash = None
def get_weight(self):
if self.weight < 0:
self.weight = sum(tx.weight for tx in self.txs.values())
return self.weight
def get_fees(self):
return sum(tx.fee for tx in self.txs.values())
def get_feerate(self):
if self.feerate < 0:
self.feerate = self.get_fees()/self.get_weight()
return self.feerate
def get_topologically_sorted_txids(self):
return [tx.txid for tx in sorted(list(self.txs.values()), key=lambda tx: (len(tx.ancestors), tx.txid))]
def __repr__(self):
return NotImplemented
def __hash__(self):
if self.hash is None:
self.hash = hash(self.__repr__())
return self.hash
def __eq__(self, other):
return NotImplemented
def __str__(self):
return "{feerate: " + str(self.get_feerate()) + ", txs: "+ str(list(self.txs.keys())) + "}"