Skip to content

Commit

Permalink
feat: wait for bitcoind to accept RPC calls
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Nov 3, 2022
1 parent 7e47df1 commit 1353a76
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The following environment variables control the configuration
- `READY_FILE` (optional; wait for a file to be created before starting all services, e.g. to wait for chain synchronization)
- `REMOVE_LOCK_FILES` (optional; remove leftover lockfiles from possible unclean shutdowns on startup)
- `RESTORE_DEFAULT_CONFIG` (optional; overwrites any existing `joinmarket.cfg` file the container's default config on startup)
- `WAIT_FOR_BITCOIND` (optional; wait for bitcoind to accept RPC request and report >= 100 blocks)

Variables starting with prefix `JM_` will be applied to `joinmarket.cfg` e.g.:
- `JM_GAPLIMIT: 2000` will set the `gaplimit` config value to `2000`
Expand Down Expand Up @@ -110,6 +111,7 @@ docker run --rm -it \
--env ENSURE_WALLET="true" \
--env REMOVE_LOCK_FILES="true" \
--env RESTORE_DEFAULT_CONFIG="true" \
--env WAIT_FOR_BITCOIND="true" \
--volume jmdatadir:/root/.joinmarket \
--publish "8080:80" \
joinmarket-webui/jam-standalone
Expand Down
2 changes: 1 addition & 1 deletion standalone/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ RUN addgroup --system tor \
&& apt-get update \
&& apt-get install -qq --no-install-recommends --no-install-suggests -y \
# image dependencies
tini iproute2 procps vim \
tini iproute2 procps vim jq \
# servers dependencies (see `install.sh`)
build-essential automake pkg-config libtool libltdl-dev python3-dev python3-setuptools python3-pip \
# tor
Expand Down
25 changes: 21 additions & 4 deletions standalone/jam-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,32 @@ done

# wait for a ready file to be created if necessary
if [ "${READY_FILE}" ] && [ "${READY_FILE}" != "false" ]; then
echo "Waiting for $READY_FILE to be created..."
echo "Waiting for file $READY_FILE to be created..."
while [ ! -f "$READY_FILE" ]; do sleep 1; done
echo "The chain is fully synched"
echo "Successfully waited for file $READY_FILE to be created."
fi

btcuser="${jmenv['rpc_user']}:${jmenv['rpc_password']}"
btchost="http://${jmenv['rpc_host']}:${jmenv['rpc_port']}"

# wait for bitcoind to accept RPC requests if necessary
if [ "${WAIT_FOR_BITCOIND}" = "true" ]; then
echo "Waiting for bitcoind to accept RPC requests..."
getblockchaininfo_payload="{\
\"jsonrpc\":\"2.0\",\
\"id\":\"curl\",\
\"method\":\"getblockchaininfo\",\
\"params\":{}\
}"
until curl --silent --user "${btcuser}" --data-binary "${getblockchaininfo_payload}" "${btchost}" | jq -e ".result.blocks >= 100" > /dev/null 2>&1
do
sleep 5
done
echo "Successfully waited for bitcoind to accept RPC requests."
fi

# ensure that a wallet exists and is loaded if necessary
if [ "${ENSURE_WALLET}" = "true" ]; then
btcuser="${jmenv['rpc_user']}:${jmenv['rpc_password']}"
btchost="http://${jmenv['rpc_host']}:${jmenv['rpc_port']}"
wallet_name="${jmenv['rpc_wallet_file']}"

echo "Creating wallet $wallet_name if missing..."
Expand Down

0 comments on commit 1353a76

Please sign in to comment.