-
Notifications
You must be signed in to change notification settings - Fork 1
/
genaddresses.py
executable file
·68 lines (59 loc) · 1.74 KB
/
genaddresses.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import json
import requests
from config import *
rpcurl = (
'http://' +
rpcuser +
':' +
rpcpassword +
'@' +
rpcip +
':' +
rpcport)
# define function that posts json data
def post_rpc(url, payload, auth=None):
try:
r = requests.post(url, data=json.dumps(payload), auth=auth)
return(json.loads(r.text))
except Exception as e:
raise Exception("Couldn't connect to " + url + ": ", e)
# generate address, validate address, dump private key
def genvaldump():
# get new address
payload = {"method": "getnewaddress"}
getnewaddress_result = post_rpc(rpcurl, payload)
address = getnewaddress_result['result']
# validate address
payload = {
"method": "validateaddress",
"params": [address]}
validateaddress_result = post_rpc(rpcurl, payload)
segid = validateaddress_result['result']['segid']
pubkey = validateaddress_result['result']['pubkey']
address = validateaddress_result['result']['address']
# dump private key for the address
payload = {
"method": "dumpprivkey",
"params": [address]
}
dumpprivkey_result = post_rpc(rpcurl, payload)
privkey = dumpprivkey_result['result']
# function output
output = [segid, pubkey, privkey, address]
return(output)
# fill a list of sigids with matching segid address data
segids = {}
while len(segids.keys()) < 64:
genvaldump_result = genvaldump()
segid = genvaldump_result[0]
if segid in segids:
pass
else:
segids[segid] = genvaldump_result
# convert dictionary to array
segids_array = []
for position in range(64):
segids_array.append(segids[position])
# print output
print("segids = " + str(json.dumps(segids_array)))