jam/docker/regtest/init-setup.sh
Thebora Kompanioni 5d886d7a3f
Enable coinjoin on regtest env (#6)
* fix: prevent 'config value not set' on cj in regtest env

'max_cj_fee' config values must be present when invoking a
coinjoin via the api. the default config for the regtest env
did not include these values before, hence they could not
be overridden in docker-compose setup file.

* dev: switch irc server from miniirc to ergochat

* dev: start second joinmarket container

In order to successfully perform a CoinJoin, there must be at least one
maker. This commit adds a second JoinMarket container with
jmwalletd accessible on port 29183.

* dev: add helper script to mine a block

* dev: add container switch to regtest-control script

* dev: invoke mine-block in regtest-control script

* dev: add flag '--unmatured' to regtest-control script

Sometimes it is desired that block rewards do not reach maturity
immediately. This is convenient if you want to supply several wallets
with coins, but do not want to generate many blocks all the time.

* dev: add helper script to start maker service

This script helps in providing both JoinMarket containers a wallet with
spendable coins and starting the Maker Service in the secondary
container. Its main goal is to make CoinJoin transactions possible in the
regtest environment.

* dev: move common functions to script common.sh

* fix: use correct irc host in docker setup

* dev: use ergochat image from ghcr.io

* dev: dont lock secondary wallet in setup script

normally the wallet should be locked, but it seems this leads to the
maker service responding very slowly which causes failing coinjoins.
as the secondary instance is never interacted with directly, we can
refrain from unlocking the wallet for now.

* docs: add debug log command to docker readme

* cleanup: rename script 'regtest-control' to 'fund-wallet'

* dev: upgrade joinmarket from v0.9.3 to use current master branch

* review: add more descriptive comments and cleanup files
2022-01-22 17:09:14 +01:00

79 lines
2.9 KiB
Bash
Executable file

#!/usr/bin/env bash
###
#
# This script helps initializing the joinmarket docker containers.
# Its main goal is to make CoinJoin transactions possible in the regtest environment.
#
# It has two responsibilities:
# - funding wallets in both containers with some coins
# - starting the maker service in the secondary container
#
###
set -Eeuo pipefail
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
# fund wallet in primary joinmarket container
. "$script_dir/fund-wallet.sh" --container jm_regtest_joinmarket --unmatured --blocks 3
# fund wallet in secondary joinmarket container
. "$script_dir/fund-wallet.sh" --container jm_regtest_joinmarket2 --unmatured --blocks 3
# make block rewards spendable
. "$script_dir/mine-block.sh" 110 &>/dev/null
base_url='https://localhost:29183'
wallet_name='funded.jmdat'
wallet_password='test'
msg "Attempt to start maker service for wallet $wallet_name in secondary container.."
# --------------------------
# Check if maker service is not yet running
# --------------------------
if session_result=$(curl "$base_url/api/v1/session" --silent --show-error --insecure | jq "."); then
msg_success "Successfully established connection to jmwalletd"
else rc=$?
die "Could not connect to joinmarket. Please make sure jmwalletd is running inside container."
fi
maker_running=$(jq -r '.maker_running' <<< "$session_result")
if [ "$maker_running" != false ]; then
msg_success "Maker is already running"
else
# --------------------------
# Unlock wallet
# --------------------------
unlock_result=$(unlock_wallet "$base_url" "$wallet_name" "$wallet_password")
auth_token=$(jq -r '.token' <<< "$unlock_result")
auth_header="Authorization: Bearer $auth_token"
# --------------------------
# Start maker
# --------------------------
## API: POST /api/v1/wallet/$wallet_name/maker/start
##
## Response:
## 200 OK
## {}
msg "Starting maker service for wallet $wallet_name.."
start_maker_request_payload="{\"txfee\":0,\"cjfee_a\":250,\"cjfee_r\":0.0003,\"ordertype\":\"sw0absoffer\",\"minsize\":10000}"
start_maker_result=$(curl "$base_url/api/v1/wallet/$wallet_name/maker/start" --silent --show-error --insecure -H "$auth_header" --data $start_maker_request_payload | jq ".")
if [ "$start_maker_result" != "{}" ]; then
msg_warn "There has been a problem starting the maker service: $start_maker_result"
else
msg_success "Successfully started maker for wallet $wallet_name in secondary container."
fi
# normally we should lock the wallet again, but it seems this leads to the maker service
# responding very slowly which causes failing coinjoins. as the secondary instance is never
# interacted with directly, we can refrain from unlocking the wallet for now.
msg_warn "Wallet $wallet_name in secondary container remains unlocked!"
fi