-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutxodust.py
More file actions
71 lines (59 loc) · 1.87 KB
/
utxodust.py
File metadata and controls
71 lines (59 loc) · 1.87 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import csv
p2pkh_total = 0
p2pkh_dust = 0
p2sh_total = 0
p2sh_dust = 0
p2wpkh_total = 0
p2wpkh_dust = 0
p2wsh_total = 0
p2wsh_dust = 0
p2tr_total = 0
p2tr_dust = 0
other_total = 0
other_dust = 0
with open('utxoset.csv', newline='') as f:
# discard header line
next(f)
reader = csv.DictReader(f)
reader.fieldnames = ['value', 'scriptPubKey']
for row in reader:
value = int(row['value'])
spk = row['scriptPubKey']
if spk.startswith('76a914') and spk.endswith('88ac') and len(spk) == 50:
p2pkh_total += 1
if value < 1000:
p2pkh_dust += 1
continue
if spk.startswith('a914') and spk.endswith('87') and len(spk) == 46:
p2sh_total += 1
if value < 1000:
p2sh_dust += 1
continue
if spk.startswith('0014') and len(spk) == 44:
p2wpkh_total += 1
if value < 1000:
p2wpkh_dust += 1
continue
if spk.startswith('0020') and len(spk) == 68:
p2wsh_total += 1
if value < 1000:
p2wsh_dust += 1
continue
if spk.startswith('5120') and len(spk) == 68:
p2tr_total += 1
if value < 1000:
p2tr_dust += 1
continue
other_total += 1
if value < 1000:
other_dust += 1
def print_summary(name: str, total: int, dust: int) -> None:
pct = (dust / total * 100) if total > 0 else 0
print(f"total {name} outputs: {total}")
print(f" dust {name} outputs: {dust} ({pct:.2f}%)\n")
print_summary("P2PKH", p2pkh_total, p2pkh_dust)
print_summary("P2SH", p2sh_total, p2sh_dust)
print_summary("P2WPKH", p2wpkh_total, p2wpkh_dust)
print_summary("P2WSH", p2wsh_total, p2wsh_dust)
print_summary("P2TR", p2tr_total, p2tr_dust)
print_summary("other", other_total, other_dust)