jam/docker/regtest/common.sh

238 lines
7.2 KiB
Bash
Raw Permalink Normal View History

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
#!/usr/bin/env bash
# A script containing many useful functions and common operations.
# This file is suitable for sourcing into other scripts.
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
}
# setup colors to enable using `msg_*` functions immediately
setup_colors
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
msg() {
echo >&2 -e "${1-}"
}
msg_success() {
msg "${GREEN}${1-}${NOFORMAT}"
}
msg_warn() {
msg "${ORANGE}${1-}${NOFORMAT}"
}
msg_error() {
msg "${RED}${1-}${NOFORMAT}"
}
msg_highlight() {
msg "${YELLOW}${1-}${NOFORMAT}"
}
die() {
local code=${2-1} # default exit status 1
msg_error "${1-}"
exit "$code"
}
### Check if dependencies are installed.
################################################################################
if ! command -v curl &> /dev/null; then
die "This script needs 'curl' to run. Consider installing it."
fi
if ! command -v jq &> /dev/null; then
die "This script needs 'jq' to run. Consider installing it."
fi
if ! command -v docker &> /dev/null; then
die "This script needs 'docker' to run. Consider installing it."
fi
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
is_docker_container_running() {
[ -z "${1-}" ] && die "is_docker_container_running: Missing required parameter: name"
local result; result=$(docker ps --filter "name=^/${1-}$" --filter status=running -q)
echo "$result"
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
}
# --------------------------
# Unlock existing wallet
# --------------------------
## API: POST /api/v1/wallet/$wallet_name/unlock
##
## Response:
## 200 OK
## {
## "walletname": "Satoshi.jmdat",
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
## "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
## }
unlock_wallet() {
local base_url; base_url=${1:-}
local wallet_name; wallet_name=${2:-}
local wallet_password; wallet_password=${3:-}
local unlock_request_payload; unlock_request_payload="{\"password\":\"$wallet_password\"}"
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
# param "--insecure": Is needed because a self-signed certificate is used in joinmarket regtest container
# param "--silent": Don't show progress meter or error messages (errors are reactivated with "--show-error").
# param "--show-error": When used with -s, --silent, it makes curl show an error message if it fails.
local unlock_result; unlock_result="$(curl "$base_url/api/v1/wallet/$wallet_name/unlock" --silent --show-error --insecure --data "$unlock_request_payload" | jq ".")"
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
local unlock_result_error_msg; unlock_result_error_msg=$(jq -r '. | select(.message != null) | .message' <<< "$unlock_result")
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
if [ "$unlock_result_error_msg" != "" ]; then
die "$unlock_result_error_msg"
fi
echo "$unlock_result"
}
# --------------------------
# Lock wallet
# --------------------------
## API: GET /api/v1/wallet/$wallet_name/lock
##
## Response:
## 200 OK
## {
## "walletname": "Satoshi.jmdat",
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
## "already_locked": false
## }
lock_wallet() {
local base_url; base_url=${1:-}
local auth_header; auth_header=${2:-}
local wallet_name; wallet_name=${3:-}
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
local lock_result; lock_result=$(curl "$base_url/api/v1/wallet/$wallet_name/lock" --silent --show-error --insecure -H "$auth_header" | jq ".")
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
local locked_wallet_name; locked_wallet_name=$(jq -r '.walletname' <<< "$lock_result")
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
[ "$locked_wallet_name" != "$wallet_name" ] && die "Problem while locking wallet $wallet_name"
echo "$lock_result"
}
# --------------------------
# Create new wallet
# --------------------------
## API: POST /api/v1/wallet/create
##
## Response:
## 200 OK
## {
## "walletname": "Satoshi.jmdat",
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
## "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
## "seedphrase": "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
## }
## or (if wallet already exists):
## 409 Conflict
## {
## "message": "Wallet file cannot be overwritten."
## }
create_wallet() {
local base_url; base_url=${1:-}
local wallet_name; wallet_name=${2:-}
local wallet_password; wallet_password=${3:-}
local create_request_payload; create_request_payload="{\"password\":\"$wallet_password\",\"walletname\":\"$wallet_name\",\"wallettype\":\"sw-fb\"}"
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
local create_result; create_result="$(curl "$base_url/api/v1/wallet/create" --silent --show-error --insecure --data "$create_request_payload" | jq ".")"
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
local create_result_error_msg; create_result_error_msg=$(jq -r '. | select(.message != null) | .message' <<< "$create_result")
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
if [ "$create_result_error_msg" != "" ]; then
die "$create_result_error_msg"
fi
echo "$create_result"
}
# --------------------------
# Fetch new address
# --------------------------
## API: GET /api/v1/wallet/$wallet_name/address/new/$mixdepth
##
## Response:
## 200 OK
## {
## "address": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
## }
fetch_new_address() {
local base_url; base_url=${1:-}
local auth_header; auth_header=${2:-}
local wallet_name; wallet_name=${3:-}
local mixdepth; mixdepth=${4:-}
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
local address_result; address_result=$(curl "$base_url/api/v1/wallet/$wallet_name/address/new/$mixdepth" --silent --show-error --insecure -H "$auth_header" | jq ".")
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
local address; address=$(jq -r '.address' <<< "$address_result")
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
echo "$address"
}
# --------------------------
# Fetch available wallets
# --------------------------
## API: GET /api/v1/wallet/all
##
## Response:
## 200 OK
## {
## "wallets": ["Satoshi.jmdat", "test0.jmdat", "test1.jmdat", "test2.jmdat"]
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
## }
##
fetch_available_wallets() {
local base_url; base_url=${1:-}
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
local wallet_all_result; wallet_all_result="$(curl "$base_url/api/v1/wallet/all" --silent --show-error --insecure | jq ".")"
local available_wallets; available_wallets="$(jq -r '.wallets' <<< "$wallet_all_result")"
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
echo "$available_wallets"
}
# --------------------------
# Fetch Session Information
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
# --------------------------
## API: GET /api/v1/session
##
## Response:
## 200 OK
## {
## "session": false,
## "maker_running": false,
## "coinjoin_in_process": false,
## "wallet_name": "None"
## }
##
fetch_session() {
local base_url; base_url=${1:-}
local session_result; session_result="$(curl "$base_url/api/v1/session" --silent --show-error --insecure | jq ".")"
echo "$session_result"
}
# --------------------------
# Verify no open session
# --------------------------
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
verify_no_open_session_or_throw() {
local base_url; base_url=${1:-}
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
if session_result=$(fetch_session "$base_url"); then
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
msg_success "Successfully established connection to jmwalletd"
else rc=$?
die "Could not connect to joinmarket. Please make sure jmwalletd is running inside container."
fi
[ "$(jq -r '.session' <<< "$session_result")" != "false" ] && die "Please make sure no session is active."
[ "$(jq -r '.wallet_name' <<< "$session_result")" != "None" ] && die "Please make sure no wallet is active."
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
return 0
}
is_maker_running() {
local base_url; base_url=${1:-}
local session_result; session_result=$(fetch_session "$base_url")
local maker_running; maker_running=$(jq -r '.maker_running' <<< "$session_result")
echo "$maker_running"
}