From 4ed639d61ec9f6a76adc62e0df3b01ec0e878343 Mon Sep 17 00:00:00 2001 From: Lucy Cifferello <12953208+elvece@users.noreply.github.com> Date: Wed, 30 Oct 2024 22:17:28 -0400 Subject: [PATCH] fixes for wallet rpc and update version --- Dockerfile | 7 +- manifest.yaml | 2 +- scripts/migrations/1_13_5_1_down_migration.ts | 28 ---- scripts/migrations/1_13_5_1_up_migration.ts | 35 ----- scripts/migrations/2_0_0_1_down_migration.ts | 30 +++++ scripts/migrations/2_0_0_1_up_migration.ts | 34 +++++ scripts/procedures/migrations.ts | 127 +++++++++--------- ...nero-wallet-rpc.btcpayserver.conf.template | 3 +- .../s6-overlay/services/monero-wallet-rpc/run | 105 ++++++++------- 9 files changed, 192 insertions(+), 179 deletions(-) delete mode 100644 scripts/migrations/1_13_5_1_down_migration.ts delete mode 100644 scripts/migrations/1_13_5_1_up_migration.ts create mode 100644 scripts/migrations/2_0_0_1_down_migration.ts create mode 100644 scripts/migrations/2_0_0_1_up_migration.ts diff --git a/Dockerfile b/Dockerfile index 57331cf..5424591 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM btcpayserver/monero:0.18.3.3 AS monero-wallet-rpc +FROM --platform=$BUILDPLATFORM btcpayserver/monero:0.18.3.3 AS monero-wallet-rpc -FROM nicolasdorier/nbxplorer:2.5.5 AS nbx-builder +FROM nicolasdorier/nbxplorer:2.5.9 AS nbx-builder FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS actions-builder ARG TARGETARCH @@ -10,7 +10,7 @@ RUN dotnet restore "utils/actions/actions.csproj" -a $TARGETARCH WORKDIR "/actions" RUN dotnet build "utils/actions/actions.csproj" -c Release -a $TARGETARCH -o /actions/build -FROM --platform=$BUILDPLATFORM btcpayserver/btcpayserver:1.13.5-altcoins +FROM --platform=$BUILDPLATFORM btcpayserver/btcpayserver:2.0.0-altcoins COPY --from=nbx-builder "/app" /nbxplorer COPY --from=actions-builder "/actions/build" /actions @@ -36,7 +36,6 @@ RUN apt-get update \ && apt-get clean autoclean \ && rm -rf /var/lib/apt/lists/* - # install S6 overlay for proces mgmt # https://github.com/just-containers/s6-overlay ARG S6_OVERLAY_VERSION=3.1.2.1 diff --git a/manifest.yaml b/manifest.yaml index 588cb81..2450516 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -1,6 +1,6 @@ id: btcpayserver title: BTCPay Server -version: 1.13.5.1 +version: 2.0.0.1 release-notes: | * Adds optional Monero integration for payment processing license: mit diff --git a/scripts/migrations/1_13_5_1_down_migration.ts b/scripts/migrations/1_13_5_1_down_migration.ts deleted file mode 100644 index 743a388..0000000 --- a/scripts/migrations/1_13_5_1_down_migration.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { types as T, matches } from "../deps.ts" - -const { shape, string } = matches - -export const migration_down_1_13_5_1 = (config: T.Config): T.Config => { - - if (Object.keys(config).length === 0) { - // service was never configured - return config - } - - const matchAltcoinConfig = shape({ - altcoins: shape({ - monero: shape({ - status: string, - }) - }), - }, ["altcoins"]) - - if (!matchAltcoinConfig.test(config)) { - throw `Incorrect shape for config: ${matchAltcoinConfig.errorMessage(config)}` - } - - if (config.altcoins) { - delete config.altcoins - } - return config -} diff --git a/scripts/migrations/1_13_5_1_up_migration.ts b/scripts/migrations/1_13_5_1_up_migration.ts deleted file mode 100644 index 5dff83e..0000000 --- a/scripts/migrations/1_13_5_1_up_migration.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { types as T, matches } from "../deps.ts" - -const { shape, string } = matches - -export const migration_up_1_13_5_1 = (config: T.Config): T.Config => { - - if (Object.keys(config).length === 0) { - // service was never configured - return config - } - - const altcoinsConfig = shape({ - monero: shape({ - status: string - }) - }) - - const matchConfigWithAltcoins = shape({ - altcoins: altcoinsConfig - }) - - if (!matchConfigWithAltcoins.test(config)) { - const newAltcoinsConfig: typeof altcoinsConfig._TYPE = { - monero: { - status: 'disabled' - } - } - return { - ...config, - altcoins: newAltcoinsConfig - } - } else { - return config - } -} diff --git a/scripts/migrations/2_0_0_1_down_migration.ts b/scripts/migrations/2_0_0_1_down_migration.ts new file mode 100644 index 0000000..ad46e5b --- /dev/null +++ b/scripts/migrations/2_0_0_1_down_migration.ts @@ -0,0 +1,30 @@ +import { types as T, matches } from "../deps.ts"; + +const { shape, string } = matches; + +export const migration_down_2_0_0_1 = (config: T.Config): T.Config => { + if (Object.keys(config).length === 0) { + // service was never configured + return config; + } + + const matchAltcoinConfig = shape( + { + altcoins: shape({ + monero: shape({ + status: string, + }), + }), + }, + ["altcoins"] + ); + + if (!matchAltcoinConfig.test(config)) { + throw `Incorrect shape for config: ${matchAltcoinConfig.errorMessage(config)}`; + } + + if (config.altcoins) { + delete config.altcoins; + } + return config; +}; diff --git a/scripts/migrations/2_0_0_1_up_migration.ts b/scripts/migrations/2_0_0_1_up_migration.ts new file mode 100644 index 0000000..ba0c65d --- /dev/null +++ b/scripts/migrations/2_0_0_1_up_migration.ts @@ -0,0 +1,34 @@ +import { types as T, matches } from "../deps.ts"; + +const { shape, string } = matches; + +export const migration_up_2_0_0_1 = (config: T.Config): T.Config => { + if (Object.keys(config).length === 0) { + // service was never configured + return config; + } + + const altcoinsConfig = shape({ + monero: shape({ + status: string, + }), + }); + + const matchConfigWithAltcoins = shape({ + altcoins: altcoinsConfig, + }); + + if (!matchConfigWithAltcoins.test(config)) { + const newAltcoinsConfig: typeof altcoinsConfig._TYPE = { + monero: { + status: "disabled", + }, + }; + return { + ...config, + altcoins: newAltcoinsConfig, + }; + } else { + return config; + } +}; diff --git a/scripts/procedures/migrations.ts b/scripts/procedures/migrations.ts index f0d8cc1..87d4229 100644 --- a/scripts/procedures/migrations.ts +++ b/scripts/procedures/migrations.ts @@ -1,71 +1,72 @@ -import { types as T, compat } from "../deps.ts" +import { types as T, compat } from "../deps.ts"; import { migration_up_1_4_7 } from "../migrations/1_4_7_up_migration.ts"; import { migration_down_1_4_7 } from "../migrations/1_4_7_down_migration.ts"; import { migration_up_1_10_3 } from "../migrations/1_10_3_up_migration.ts"; -import { migration_up_1_13_5_1 } from "../migrations/1_13_5_1_up_migration.ts"; -import { migration_down_1_13_5_1 } from "../migrations/1_13_5_1_down_migration.ts"; +import { migration_up_2_0_0_1 } from "../migrations/2_0_0_1_up_migration.ts"; +import { migration_down_2_0_0_1 } from "../migrations/2_0_0_1_down_migration.ts"; -export const migration: T.ExpectedExports.migration = async (effects, version, ...args) => { +export const migration: T.ExpectedExports.migration = async ( + effects, + version, + ...args +) => { await effects.createDir({ path: "start9", - volumeId: "main" + volumeId: "main", }); - return compat.migrations - .fromMapping( - { - // 1.1.2.5: initial (updated) version released with eOS 0.3.0 - bitcoin config was internal (proxy) or external - "1.4.7.1": { - up: compat.migrations.updateConfig( - (config) => { - return migration_up_1_4_7(config) - }, - false, - { version: "1.4.7.1", type: "up" }, - ), - down: compat.migrations.updateConfig( - (config) => { - return migration_down_1_4_7(config) - }, - true, - { version: "1.4.7.1", type: "down" }, - ), - }, - // 1.4.7.3: JS config/properties conversion occurred - "1.10.2": { - up: compat.migrations.updateConfig( - (config) => { - return migration_up_1_10_3(config) - }, - true, - { version: "1.10.2", type: "up"} - ), - down: compat.migrations.updateConfig( - (_config) => { - throw new Error( - "Cannot downgrade this version" - ) - }, - true, - { version: "1.10.2", type: "down" }, - ), - }, - "1.13.5.1": { - up: compat.migrations.updateConfig( - (config) => { - return migration_up_1_13_5_1(config) - }, - true, - { version: "1.13.5.1", type: "up"} - ), - down: compat.migrations.updateConfig( - (config) => { - return migration_down_1_13_5_1(config) - }, - true, - { version: "1.13.5.1", type: "down" }, - ), - }, + return compat.migrations.fromMapping( + { + // 1.1.2.5: initial (updated) version released with eOS 0.3.0 - bitcoin config was internal (proxy) or external + "1.4.7.1": { + up: compat.migrations.updateConfig( + (config) => { + return migration_up_1_4_7(config); + }, + false, + { version: "1.4.7.1", type: "up" } + ), + down: compat.migrations.updateConfig( + (config) => { + return migration_down_1_4_7(config); + }, + true, + { version: "1.4.7.1", type: "down" } + ), }, - "1.13.5.1", - )(effects, version, ...args) -} \ No newline at end of file + // 1.4.7.3: JS config/properties conversion occurred + "1.10.2": { + up: compat.migrations.updateConfig( + (config) => { + return migration_up_1_10_3(config); + }, + true, + { version: "1.10.2", type: "up" } + ), + down: compat.migrations.updateConfig( + (_config) => { + throw new Error("Cannot downgrade this version"); + }, + true, + { version: "1.10.2", type: "down" } + ), + }, + "2.0.0.1": { + up: compat.migrations.updateConfig( + (config) => { + return migration_up_2_0_0_1(config); + }, + true, + { version: "2.0.0.1", type: "up" } + ), + down: compat.migrations.updateConfig( + (config) => { + return migration_down_2_0_0_1(config); + }, + true, + { version: "2.0.0.1", type: "down" } + ), + }, + }, + "2.0.0.1" + )(effects, version, ...args); +}; diff --git a/utils/config/monero-wallet-rpc.btcpayserver.conf.template b/utils/config/monero-wallet-rpc.btcpayserver.conf.template index f1704b9..2e4353b 100644 --- a/utils/config/monero-wallet-rpc.btcpayserver.conf.template +++ b/utils/config/monero-wallet-rpc.btcpayserver.conf.template @@ -23,6 +23,7 @@ rpc-bind-port=MONERO_BTCPAY_WALLET_RPC_PORT shared-ringdb-dir=MONERO_DIR -MONERO_DAEMON_RPC_CREDENTIALS +# if empty, placeholder for if/when monerod rpc credentials are enabled +#daemon-login= tx-notify=/usr/bin/curl -so /dev/null -X GET http://127.0.0.1:23000/monerolikedaemoncallback/tx?cryptoCode=xmr&hash=%s diff --git a/utils/s6-overlay/services/monero-wallet-rpc/run b/utils/s6-overlay/services/monero-wallet-rpc/run index 1f3f6ff..9b92759 100644 --- a/utils/s6-overlay/services/monero-wallet-rpc/run +++ b/utils/s6-overlay/services/monero-wallet-rpc/run @@ -5,57 +5,68 @@ # -e Exit immediately if a command exits with a non-zero status set -ea -# check readiness of altcoin connections if configured to use +# Check readiness of altcoin connections if configured to use monero_status=$(yq e '.altcoins.monero.status' /datadir/start9/config.yaml) if [[ $monero_status = "enabled" ]] then - MONERO_DIR=/datadir/btcpayserver/altcoins/monero - mkdir -p $MONERO_DIR - MONERO_UID=30236 - MONERO_GID=302340 - chown $MONERO_UID:$MONERO_GID $MONERO_DIR - chmod 755 $MONERO_DIR - CONF_FILENAME="monero-wallet-rpc.btcpayserver.conf" - MONERO_BTCPAY_WALLET_RPC_CONF="${MONERO_DIR}/${CONF_FILENAME}" - MONERO_BTCPAY_WALLET_RPC_PORT=18082 - #change directory to where the monero wallets, conf, rpc db file & logs dir will go and auth file can be written successfully - cd "$MONERO_DIR" - #remove old auth file in case it stuck around from an incomplete shutdown - mwr_auth_file="monero-wallet-rpc.${MONERO_BTCPAY_WALLET_RPC_PORT}.login" - if [ -f "$mwr_auth_file" ] ; then - rm -f "$mwr_auth_file" - fi - - #Ensure that the monero wallet directory exists - MONERO_BTCPAY_WALLET_DIR=${MONERO_DIR}/wallets - mkdir -p $MONERO_BTCPAY_WALLET_DIR - chown $MONERO_UID:$MONERO_GID $MONERO_BTCPAY_WALLET_DIR - chmod 775 $MONERO_BTCPAY_WALLET_DIR - -#Construct a fully-formed monero-wallet-rpc config file from the template - cp -f /etc/$CONF_FILENAME.template $MONERO_BTCPAY_WALLET_RPC_CONF - sed -i "s|MONERO_DIR|$MONERO_DIR|g" $MONERO_BTCPAY_WALLET_RPC_CONF && \ - sed -i "s|MONERO_BTCPAY_WALLET_RPC_PORT|$MONERO_BTCPAY_WALLET_RPC_PORT|g" $MONERO_BTCPAY_WALLET_RPC_CONF && \ - sed -i "s|MONERO_BTCPAY_WALLET_DIR|$MONERO_BTCPAY_WALLET_DIR|g" $MONERO_BTCPAY_WALLET_RPC_CONF && \ - - monero_daemon_rpc_credentials="" - monero_rpc_enabled="$(yq e '.rpc.rpc-credentials.enabled' /mnt/monerod/start9/config.yaml)" - #If a monero daemon RPC username has been setup: - if [ "$monero_rpc_enabled" == "enabled" ] - then - monero_daemon_rpc_username=$(yq e '.rpc.rpc-credentials.username' /mnt/monerod/start9/config.yaml) - monero_daemon_rpc_password=$(yq e '.rpc.rpc-credentials.password' /mnt/monerod/start9/config.yaml) - monero_daemon_rpc_credentials="daemon-login=$monero_daemon_rpc_username:$monero_daemon_rpc_password" - sed -i "s|MONERO_DAEMON_RPC_CREDENTIALS|$monero_daemon_rpc_credentials|g" $MONERO_BTCPAY_WALLET_RPC_CONF - fi + CURRENT_DIR=$(pwd) + MONERO_DIR="/datadir/btcpayserver/altcoins/monero" + mkdir -p $MONERO_DIR + MONERO_UID=30236 + MONERO_GID=302340 + chown $MONERO_UID:$MONERO_GID $MONERO_DIR + chmod 755 $MONERO_DIR + CONF_FILENAME="monero-wallet-rpc.btcpayserver.conf" + MONERO_BTCPAY_WALLET_RPC_CONF="${MONERO_DIR}/${CONF_FILENAME}" + MONERO_BTCPAY_WALLET_RPC_PORT=18082 + # Change directory to where the monero wallets, conf, rpc db file & logs dir will go and auth file can be written successfully + cd "$MONERO_DIR" + # Remove old auth file in case it stuck around from an incomplete shutdown + mwr_auth_file="monero-wallet-rpc.${MONERO_BTCPAY_WALLET_RPC_PORT}.login" + if [ -f "$mwr_auth_file" ] ; then + rm -f "$mwr_auth_file" + fi + cd "$CURRENT_DIR" + # Setup wallet logs + mkdir -p $MONERO_DIR/logs + wallet_log_file="$MONERO_DIR/logs/monero-wallet-rpc.btcpayserver.log" + if [ ! -f "$wallet_log_file" ] + then + touch $MONERO_DIR/logs/monero-wallet-rpc.btcpayserver.log + fi + + # Ensure that the monero wallet directory exists + MONERO_BTCPAY_WALLET_DIR=${MONERO_DIR}/wallets + mkdir -p $MONERO_BTCPAY_WALLET_DIR + chown $MONERO_UID:$MONERO_GID $MONERO_BTCPAY_WALLET_DIR + chmod 775 $MONERO_BTCPAY_WALLET_DIR + + # Construct a fully-formed monero-wallet-rpc config file from the template + cp -f /etc/$CONF_FILENAME.template $MONERO_BTCPAY_WALLET_RPC_CONF + chown $MONERO_UID:$MONERO_GID $MONERO_BTCPAY_WALLET_RPC_CONF + sed -i "s|MONERO_DIR|$MONERO_DIR|g" $MONERO_BTCPAY_WALLET_RPC_CONF && \ + sed -i "s|MONERO_BTCPAY_WALLET_RPC_PORT|$MONERO_BTCPAY_WALLET_RPC_PORT|g" $MONERO_BTCPAY_WALLET_RPC_CONF && \ + sed -i "s|MONERO_BTCPAY_WALLET_DIR|$MONERO_BTCPAY_WALLET_DIR|g" $MONERO_BTCPAY_WALLET_RPC_CONF && \ + + monero_daemon_rpc_credentials="" + monero_rpc_enabled="$(yq e '.rpc.rpc-credentials.enabled' /mnt/monerod/start9/config.yaml)" + # If a monero daemon RPC username has been setup: + if [ "$monero_rpc_enabled" == "enabled" ] + then + monero_daemon_rpc_username=$(yq e '.rpc.rpc-credentials.username' /mnt/monerod/start9/config.yaml) + monero_daemon_rpc_password=$(yq e '.rpc.rpc-credentials.password' /mnt/monerod/start9/config.yaml) + monero_daemon_rpc_credentials="$monero_daemon_rpc_username:$monero_daemon_rpc_password" + sed -i "s|#daemon-login=.*|daemon-login=$monero_daemon_rpc_credentials|g" $MONERO_BTCPAY_WALLET_RPC_CONF + fi - #Delay and try again if the wallet files are not already in place... - while [[ ! -f "$MONERO_BTCPAY_WALLET_DIR/wallet" || ! -f "$MONERO_BTCPAY_WALLET_DIR/password" ]] - do - sleep 7 - done - # start monero-wallet-rpc, copying stderr onto stdout - exec s6-setuidgid $MONERO_UID:$MONERO_GID /usr/local/bin/monero-wallet-rpc --non-interactive --config-file $MONERO_BTCPAY_WALLET_RPC_CONF 2>&1 + # Delay and try again if the wallet files are not already in place... + while [[ ! -f "$MONERO_BTCPAY_WALLET_DIR/wallet" || ! -f "$MONERO_BTCPAY_WALLET_DIR/password" ]] + do + sleep 7 + done + + # Start monero-wallet-rpc, copying stderr onto stdout + exec s6-setuidgid $MONERO_UID:$MONERO_GID /usr/local/bin/monero-wallet-rpc --non-interactive --config-file $MONERO_BTCPAY_WALLET_RPC_CONF 2>&1 fi