MCPcopy Create free account
hub / github.com/ElementsProject/elements / get_auth_cookie

Function get_auth_cookie

test/functional/test_framework/util.py:440–462  ·  view source on GitHub ↗
(datadir, chain)

Source from the content-addressed store, hash-verified

438
439
440def get_auth_cookie(datadir, chain):
441 user = None
442 password = None
443 if os.path.isfile(os.path.join(datadir, "elements.conf")):
444 with open(os.path.join(datadir, "elements.conf"), 'r', encoding='utf8') as f:
445 for line in f:
446 if line.startswith("rpcuser="):
447 assert user is None # Ensure that there is only one rpcuser line
448 user = line.split("=")[1].strip("\n")
449 if line.startswith("rpcpassword="):
450 assert password is None # Ensure that there is only one rpcpassword line
451 password = line.split("=")[1].strip("\n")
452 try:
453 with open(os.path.join(datadir, chain, ".cookie"), 'r', encoding="ascii") as f:
454 userpass = f.read()
455 split_userpass = userpass.split(':')
456 user = split_userpass[0]
457 password = split_userpass[1]
458 except OSError:
459 pass
460 if user is None or password is None:
461 raise ValueError("No RPC credentials")
462 return user, password
463
464
465# If a cookie file exists in the given datadir, delete it.

Callers 4

run_testMethod · 0.90
setup_networkMethod · 0.90
rpc_urlFunction · 0.70

Calls 2

joinMethod · 0.45
readMethod · 0.45

Tested by 1