Skip to content

Commit

Permalink
When starting bitcoind, create/load default wallet as needed
Browse files Browse the repository at this point in the history
Since Bitcoin Core will no longer do so; see
bitcoin/bitcoin#15454

Tested with all of the following bitcoind versions:

0.17.1
0.19.0.1
0.20.1
0.18.0
0.20.0
v0.21.0rc1 (from git)
  • Loading branch information
bitcoinhodler authored and bitcoinfacts committed Dec 27, 2021
1 parent 277e9af commit d4f61a0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions glacierscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,38 @@ def ensure_bitcoind_running():
while times <= 20:
times += 1
if bitcoin_cli_call("getnetworkinfo") == 0:
create_default_wallet()
return
time.sleep(0.5)

raise Exception("Timeout while starting bitcoin server")


def create_default_wallet():
"""
Ensure the default wallet exists and is loaded.
Since v0.21, Bitcoin Core will not create a default wallet when
started for the first time.
"""
loaded_wallets = bitcoin_cli_json("listwallets")
if "" in loaded_wallets:
return # default wallet already loaded
all_wallets = bitcoin_cli_json("listwalletdir")
# {
# "wallets": [
# {
# "name": ""
# }
# ]
# }
found = any(w["name"] == "" for w in all_wallets["wallets"])
cmd = "loadwallet" if found else "createwallet"
loaded_wallet = bitcoin_cli_json(cmd, "")
if len(loaded_wallet["warning"]):
raise Exception("problem running {} on default wallet".format(cmd)) # pragma: no cover


def require_minimum_bitcoind_version(min_version):
"""
Fail if the bitcoind version in use is older than required
Expand Down

0 comments on commit d4f61a0

Please sign in to comment.