Skip to content

Commit fadf078

Browse files
committed
Merge #10104: linearize script: Option to use RPC cookie
bd41d98 Datadir option in linearize scripts (Andrew Chow) Tree-SHA512: 0d11866b574986c087ec962a8a9fc0b6dfee8175ae20ef827f8b4a143f657c5bffc9f9696e9dabf29b68002003a5b6a7d8ac473231b5c9c81c3a4fa0318f5bd0
2 parents 080d7c7 + bd41d98 commit fadf078

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

contrib/linearize/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ run using Python 3 but are compatible with Python 2.
77
$ ./linearize-hashes.py linearize.cfg > hashlist.txt
88

99
Required configuration file settings for linearize-hashes:
10-
* RPC: `rpcuser`, `rpcpassword`
10+
* RPC: `datadir` (Required if `rpcuser` and `rpcpassword` are not specified)
11+
* RPC: `rpcuser`, `rpcpassword` (Required if `datadir` is not specified)
1112

1213
Optional config file setting for linearize-hashes:
1314
* RPC: `host` (Default: `127.0.0.1`)

contrib/linearize/example-linearize.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# bitcoind RPC settings (linearize-hashes)
22
rpcuser=someuser
33
rpcpassword=somepassword
4+
#datadir=~/.bitcoin
45
host=127.0.0.1
56
port=8332
67
#port=18332

contrib/linearize/linearize-hashes.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import re
1717
import base64
1818
import sys
19+
import os
20+
import os.path
1921

2022
settings = {}
2123

@@ -93,6 +95,14 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
9395

9496
height += num_blocks
9597

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+
96106
if __name__ == '__main__':
97107
if len(sys.argv) != 2:
98108
print("Usage: linearize-hashes.py CONFIG-FILE")
@@ -122,8 +132,15 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
122132
settings['max_height'] = 313000
123133
if 'rev_hash_bytes' not in settings:
124134
settings['rev_hash_bytes'] = 'false'
135+
136+
use_userpass = True
137+
use_datadir = False
125138
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)
127144
sys.exit(1)
128145

129146
settings['port'] = int(settings['port'])
@@ -133,4 +150,8 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
133150
# Force hash byte format setting to be lowercase to make comparisons easier.
134151
settings['rev_hash_bytes'] = settings['rev_hash_bytes'].lower()
135152

153+
# Get the rpc user and pass from the cookie if the datadir is set
154+
if use_datadir:
155+
get_rpc_cookie()
156+
136157
get_block_hashes(settings)

0 commit comments

Comments
 (0)