Expand ~ in bitcoin_datadir in bitcoin_core.py and fix Black formatting

Agent-Logs-Url: https://github.com/cryptoadvance/specter-desktop/sessions/376d87d6-b9af-4e58-ba3f-c005f1689cce

Co-authored-by: k9ert <117085+k9ert@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-08 20:17:48 +00:00 committed by k9ert
parent 200ec8ee75
commit 70f6dd2864
3 changed files with 5 additions and 5 deletions

View file

@ -254,6 +254,7 @@ class BitcoinCore(Device):
wallet_manager.rpc.unloadwallet(wallet_rpc_path)
# Try deleting wallet file
if bitcoin_datadir:
bitcoin_datadir = os.path.expanduser(bitcoin_datadir)
# Check walletdir in bitcoin.conf; network-specific section takes precedence over default
walletdir = get_walletdir(bitcoin_datadir, chain)
if walletdir:

View file

@ -128,9 +128,9 @@ def get_walletdir(datadir, chain):
datadir = os.path.expanduser(datadir)
config = get_rpcconfig(datadir)
btc_conf = config.get("bitcoin.conf", {})
return btc_conf.get(chain, {}).get("walletdir") or btc_conf.get(
"default", {}
).get("walletdir")
return btc_conf.get(chain, {}).get("walletdir") or btc_conf.get("default", {}).get(
"walletdir"
)
def _detect_rpc_confs_via_datadir(config=None, datadir=get_default_datadir()):

View file

@ -123,8 +123,7 @@ def test_get_walletdir_dot_notation_network_override(tmp_path):
"""Dot-notation network walletdir overrides the default walletdir."""
bitcoin_conf = tmp_path / "bitcoin.conf"
bitcoin_conf.write_text(
"walletdir=/default/wallets\n"
"regtest.walletdir=/regtest/wallets\n"
"walletdir=/default/wallets\n" "regtest.walletdir=/regtest/wallets\n"
)
assert get_walletdir(str(tmp_path), "regtest") == "/regtest/wallets"
assert get_walletdir(str(tmp_path), "main") == "/default/wallets"