16
16
import re
17
17
import base64
18
18
import sys
19
+ import os
20
+ import os .path
19
21
20
22
settings = {}
21
23
@@ -93,6 +95,14 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
93
95
94
96
height += num_blocks
95
97
98
+ def get_rpc_cookie ():
99
+ # Open the cookie file
100
+ with open (os .path .join (os .path .expanduser (settings ['datadir' ]), '.cookie' ), 'r' ) as f :
101
+ combined = f .readline ()
102
+ combined_split = combined .split (":" )
103
+ settings ['rpcuser' ] = combined_split [0 ]
104
+ settings ['rpcpassword' ] = combined_split [1 ]
105
+
96
106
if __name__ == '__main__' :
97
107
if len (sys .argv ) != 2 :
98
108
print ("Usage: linearize-hashes.py CONFIG-FILE" )
@@ -122,8 +132,15 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
122
132
settings ['max_height' ] = 313000
123
133
if 'rev_hash_bytes' not in settings :
124
134
settings ['rev_hash_bytes' ] = 'false'
135
+
136
+ use_userpass = True
137
+ use_datadir = False
125
138
if 'rpcuser' not in settings or 'rpcpassword' not in settings :
126
- print ("Missing username and/or password in cfg file" , file = stderr )
139
+ use_userpass = False
140
+ if 'datadir' in settings and not use_userpass :
141
+ use_datadir = True
142
+ if not use_userpass and not use_datadir :
143
+ print ("Missing datadir or username and/or password in cfg file" , file = stderr )
127
144
sys .exit (1 )
128
145
129
146
settings ['port' ] = int (settings ['port' ])
@@ -133,4 +150,8 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
133
150
# Force hash byte format setting to be lowercase to make comparisons easier.
134
151
settings ['rev_hash_bytes' ] = settings ['rev_hash_bytes' ].lower ()
135
152
153
+ # Get the rpc user and pass from the cookie if the datadir is set
154
+ if use_datadir :
155
+ get_rpc_cookie ()
156
+
136
157
get_block_hashes (settings )
0 commit comments