forked from graymauser/btcposbal2csv
-
Notifications
You must be signed in to change notification settings - Fork 2
/
convert2ripemd160.py
46 lines (36 loc) · 1.32 KB
/
convert2ripemd160.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 base58
import binascii
import argparse
import bech32
def tocondensed(add_or_pk):
return base58.b58decode(add_or_pk)[1:-4]
def process(csvfile):
with open(csvfile, 'r') as f:
for i, row in enumerate(f):
if i == 0:
print(row[:-1] + ',ripemd')
continue
elif row.strip() == '':
break
if row[:3].lower() == 'bc1':
_, script_int = bech32.decode('bc', row.split(',')[0].lower())
ripemd_encoded = binascii.hexlify(bytearray(script_int))
else:
ripemd_bin = tocondensed(row.split(',')[0])
ripemd_encoded = binascii.hexlify(ripemd_bin)
print(row[: -1] + ',' + ripemd_encoded.decode())
def input_args():
parser = argparse.ArgumentParser(description='Read csv file with btc address as first column'\
' encodes it to ripemd160 binascii representation and writes to stdout'
)
parser.add_argument(
'csvin',
metavar='csv file',
type=str,
help='path to csv file with btc address in first column (usually output of btcposbal2csv)'
)
a = parser.parse_args()
return a
if __name__ == '__main__':
args = input_args()
process(args.csvin)