| 315 | f.write(option + "\n") |
| 316 | |
| 317 | def get_auth_cookie(datadir): |
| 318 | user = None |
| 319 | password = None |
| 320 | if os.path.isfile(os.path.join(datadir, "bitcoingold.conf")): |
| 321 | with open(os.path.join(datadir, "bitcoingold.conf"), 'r', encoding='utf8') as f: |
| 322 | for line in f: |
| 323 | if line.startswith("rpcuser="): |
| 324 | assert user is None # Ensure that there is only one rpcuser line |
| 325 | user = line.split("=")[1].strip("\n") |
| 326 | if line.startswith("rpcpassword="): |
| 327 | assert password is None # Ensure that there is only one rpcpassword line |
| 328 | password = line.split("=")[1].strip("\n") |
| 329 | if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")): |
| 330 | with open(os.path.join(datadir, "regtest", ".cookie"), 'r', encoding="ascii") as f: |
| 331 | userpass = f.read() |
| 332 | split_userpass = userpass.split(':') |
| 333 | user = split_userpass[0] |
| 334 | password = split_userpass[1] |
| 335 | if user is None or password is None: |
| 336 | raise ValueError("No RPC credentials") |
| 337 | return user, password |
| 338 | |
| 339 | # If a cookie file exists in the given datadir, delete it. |
| 340 | def delete_cookie_file(datadir): |