-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbech32_converter.py
46 lines (33 loc) · 1.16 KB
/
bech32_converter.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
import sys
import bech32
def convert_bech32_address(address, new_hrp):
# Split the address into HRP and data
current_hrp, data = bech32.bech32_decode(address)
# Check if the address is a valid Bech32 address
if not data:
print(f"Invalid Bech32 address: {address}")
return None
# Replace the HRP with the new one
new_address = bech32.bech32_encode(new_hrp, data)
return new_address
def main():
if len(sys.argv) != 2:
print("Usage: python convert_addresses.py <new_hrp>")
sys.exit(1)
new_hrp = sys.argv[1]
try:
with open("addresses.txt", "r") as f:
addresses = [line.strip() for line in f.readlines()]
except FileNotFoundError:
print("addresses.txt not found")
sys.exit(1)
converted_addresses = []
for address in addresses:
converted_address = convert_bech32_address(address, new_hrp)
if converted_address:
converted_addresses.append(converted_address)
with open(f"addresses-{new_hrp}.txt", "w") as f:
for address in converted_addresses:
f.write(address + "\n")
if __name__ == "__main__":
main()