From 704760293b4fd771d9368caa81316b8e89ce9ca7 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 13 Dec 2023 14:29:01 +0100 Subject: [PATCH] Improve and update Electrum This contains several improvements: * Updates the version * Adds regtest support * Adds integration test * Fixes dependency specification * Improves the launcher to be able to run daemon --- build_rules/electrum.yaml | 6 +- electrum/assets/electrum-trustless-launcher | 95 ++++++++++++++++++ electrum/assets/electrum-trustless-mainnet | 9 -- .../assets/electrum-trustless-regtest.desktop | 14 +++ pkg_specs/electrum-trustless-@variant.sps | 5 +- pkg_specs/electrum.changelog | 6 ++ pkg_specs/electrum.sps | 2 +- pkg_specs/electrum.sss | 2 +- tests/multi-package/electrum.sh | 96 +++++++++++++++++++ 9 files changed, 220 insertions(+), 15 deletions(-) create mode 100755 electrum/assets/electrum-trustless-launcher delete mode 100644 electrum/assets/electrum-trustless-mainnet create mode 100644 electrum/assets/electrum-trustless-regtest.desktop create mode 100755 tests/multi-package/electrum.sh diff --git a/build_rules/electrum.yaml b/build_rules/electrum.yaml index c8a8333..0bfd1ad 100644 --- a/build_rules/electrum.yaml +++ b/build_rules/electrum.yaml @@ -11,7 +11,9 @@ get_assets: signature: https://download.electrum.org/$(ELECTRUM_VERSION)/electrum-$(ELECTRUM_VERSION)-$(ARCH).AppImage.asc copy_assets: + - from: electrum/assets/electrum-trustless-launcher + to: electrum-trustless-launcher - from: electrum/assets/electrum-trustless-mainnet.desktop to: electrum-trustless-mainnet.desktop - - from: electrum/assets/electrum-trustless-mainnet - to: electrum-trustless-mainnet + - from: electrum/assets/electrum-trustless-regtest.desktop + to: electrum-trustless-regtest.desktop diff --git a/electrum/assets/electrum-trustless-launcher b/electrum/assets/electrum-trustless-launcher new file mode 100755 index 0000000..f3c2605 --- /dev/null +++ b/electrum/assets/electrum-trustless-launcher @@ -0,0 +1,95 @@ +#!/bin/bash + +function scan_args() { + local prog="$0"; + network="`echo "$prog" | sed 's/^.*-//g'`" + case "$network" in + mainnet|regtest) + ;; + testnet|signet|simnet) + echo "Network supported by Electrum but $network unsupported by CADR" >&2 + echo "Use electrum directly, not this launcher" >&2 + exit 1 + ;; + *) + echo "Unrecognized network $1. Launch the binary using a symlink." + exit 1 + ;; + esac + while [ $# -gt 0 ]; + do + case "$1" in + --testnet|--regtest|--signet|--simnet) + echo "Network is implied by the binary name, don't use an argument" >&2 + exit 1 + ;; + -h|--help) + echo "Launcher for electrum with a self-hosted server" + echo "" + echo "Usage: $prog [daemon|gui] [URLS...]" + echo "" + echo "This launcher supplies its own --oneserver and --server arguments to electrum. These are currently read from /etc/electrs-{network}/conf.d/interface.toml but this will change in the future." + echo "Note that for --offline or RPC use electrum binary directly. This launcher is only intended for GUI or daemon" + ;; + daemon) + if [ "$is_daemon" = 1 ] || [ "$is_gui" = 1 ]; + then + echo "Either daemon or gui have to be specified and at most once" >&2 + exit 1 + fi + is_daemon=1 + ;; + gui) + if [ "$is_daemon" = 1 ] || [ "$is_gui" = 1 ]; + then + echo "Either daemon or gui have to be specified and at most once" >&2 + exit 1 + fi + is_gui=1 + ;; + --server) + echo "Error: --server would make this launcher pointless, use the electrum binary instead." >&2 + exit 1 + ;; + --oneserver) + echo "Warning: --oneserver is already the default" >&2 + ;; + bitcoin:*) + break + ;; + lightning:*) + break + ;; + --) + break + ;; + esac + shift + done +} + +scan_args "$@" + +first_arg="" +if [ "$is_daemon" = 1 ]; +then + cmd="daemon" + shift +elif [ "$is_gui" = 1 ]; +then + cmd="gui" + shift +fi + +if [ "$network" = regtest ]; +then + network_arg="--regtest" +fi + +SERVER="`grep '^electrum_rpc_addr' "/etc/electrs-$network/conf.d/interface.toml" | sed -e 's/^electrum_rpc_addr *= *"//' -e 's/"$//'`:t" || exit 1 + +# Skipmerklecheck is safe because we connect to our own local server +# Currently this is hardcoded to electrs, but should use /etc/electrum-server/interface +# or something similar with update-alternatives. This needs implementation of interface +# feature in debcrafter (see #2). +exec electrum $network_arg $cmd --oneserver --skipmerklecheck --server "$SERVER" "$@" diff --git a/electrum/assets/electrum-trustless-mainnet b/electrum/assets/electrum-trustless-mainnet deleted file mode 100644 index 1c62d77..0000000 --- a/electrum/assets/electrum-trustless-mainnet +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -SERVER="`grep '^electrum_rpc_addr' /etc/electrs-mainnet/conf.d/interface.toml | sed -e 's/^electrum_rpc_addr *= *"//' -e 's/"$//'`:t" || exit 1 - -# Skipmerklecheck is safe because we connect to our own local server -# Currently this is hardcoded to electrs, but should use /etc/electrum-server/interface -# or something similar with update-alternatives. This needs implementation of interface -# feature in debcrafter (see #2). -electrum --oneserver --skipmerklecheck --server "$SERVER" diff --git a/electrum/assets/electrum-trustless-regtest.desktop b/electrum/assets/electrum-trustless-regtest.desktop new file mode 100644 index 0000000..5543e1b --- /dev/null +++ b/electrum/assets/electrum-trustless-regtest.desktop @@ -0,0 +1,14 @@ +[Desktop Entry] +Comment=Trustless Bitcoin Client - Regtest +Exec=electrum-trustless-regtest %u +GenericName[en_US]=Bitcoin Wallet +GenericName=Bitcoin Wallet +Icon=electrum +Name[en_US]=Electrum Bitcoin Wallet - Regtest (trustless) +Name=Electrum Bitcoin Wallet - Regtest (trustless) +Categories=Finance;Network; +StartupNotify=true +StartupWMClass=electrum +Terminal=false +Type=Application +MimeType=x-scheme-handler/bitcoin; diff --git a/pkg_specs/electrum-trustless-@variant.sps b/pkg_specs/electrum-trustless-@variant.sps index 0dcf891..a443aa3 100644 --- a/pkg_specs/electrum-trustless-@variant.sps +++ b/pkg_specs/electrum-trustless-@variant.sps @@ -1,8 +1,9 @@ name = "electrum-trustless-@variant" architecture = "all" summary = "Electrum - Lightweight Bitcoin client (secure launcher)" -recommends = ["electrum-trustless-{variant} | electrum-trustless-regtest", "python3-pyqt5"] -add_files = ["electrum-trustless-{variant} /usr/bin/", "electrum-trustless-{variant}.desktop /usr/share/applications/"] +depends = ["electrum (>= 4.4.6)"] +add_files = ["electrum-trustless-{variant}.desktop /usr/share/applications/"] +add_links = ["/usr/share/electrum/electrum-trustless-launcher /usr/bin/electrum-trustless-{variant}"] long_doc = """Electrum is a powerful Bitcoin wallet capable of using hardware wallets. This package contains a launcher configured to make sure you don't leak diff --git a/pkg_specs/electrum.changelog b/pkg_specs/electrum.changelog index 43fa368..423d73c 100644 --- a/pkg_specs/electrum.changelog +++ b/pkg_specs/electrum.changelog @@ -1,3 +1,9 @@ +electrum (4.4.6-1) buster; urgency=medium + + * Updated upstream version + + -- Martin Habovstiak Wed, 22 Feb 2023 11:56:32 +0100 + electrum (4.0.9-1) buster; urgency=medium * Updated upstream version diff --git a/pkg_specs/electrum.sps b/pkg_specs/electrum.sps index cfe0e39..c8ad587 100644 --- a/pkg_specs/electrum.sps +++ b/pkg_specs/electrum.sps @@ -2,5 +2,5 @@ name = "electrum" architecture = "any" summary = "Electrum - Lightweight Bitcoin client (exeutable)" recommends = ["electrum-trustless-mainnet | electrum-trustless-regtest", "python3-pyqt5"] -add_files = ["electrum /usr/bin"] +add_files = ["electrum /usr/bin", "electrum-trustless-launcher /usr/share/electrum"] long_doc = """Electrum is a powerful Bitcoin wallet capable of using hardware wallets.""" diff --git a/pkg_specs/electrum.sss b/pkg_specs/electrum.sss index b6c0f17..c59eba4 100644 --- a/pkg_specs/electrum.sss +++ b/pkg_specs/electrum.sss @@ -1,6 +1,6 @@ name = "electrum" section = "net" -variants = ["mainnet"] +variants = ["mainnet", "regtest"] build_depends = [ "python3:native | python3-all:native | python3-all-dev:native" ] diff --git a/tests/multi-package/electrum.sh b/tests/multi-package/electrum.sh new file mode 100755 index 0000000..c4618d1 --- /dev/null +++ b/tests/multi-package/electrum.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +set -e + +test_dir="$(realpath "$(dirname "$0")/..")" + +. "$test_dir/common.sh" + +preload_config + +sudo apt-get install -y bitcoin-regtest bitcoin-cli electrs electrum-trustless-regtest jq + +# Heavily inspired by the one in electrs itself + +cleanup() { + trap - SIGTERM SIGINT + set +eo pipefail + jobs + for j in `jobs -rp` + do + kill $j + wait $j + done +} +trap cleanup SIGINT SIGTERM EXIT + +BTC="sudo bitcoin-cli -chain=regtest" +ELECTRUM="electrum-trustless-regtest" +EL="electrum --regtest" + +tail_log() { + tail -n +0 -F $1 || true +} + +$BTC -rpcwait getblockcount > /dev/null + +echo "Creating Electrum `electrum version --offline` wallet..." +WALLET=`$EL --offline create --seed_type=segwit` +MINING_ADDR=`$EL --offline getunusedaddress` + +$BTC generatetoaddress 110 $MINING_ADDR > /dev/null +echo `$BTC getblockchaininfo | jq -r '"Generated \(.blocks) regtest blocks (\(.size_on_disk/1e3) kB)"'` to $MINING_ADDR + +TIP=`$BTC getbestblockhash` + +wget -O metrics.txt http://localhost:24224 + +$ELECTRUM daemon -vDEBUG 2> ~/electrum-debug.log & +ELECTRUM_PID=$! +tail_log ~/electrum-debug.log | grep -m1 "connection established" +$EL getinfo | jq . + +echo "Loading Electrum wallet..." +$EL load_wallet + +echo "Running integration tests:" + +echo " * getbalance" +test "`$EL getbalance | jq -c .`" == '{"confirmed":"550","unmatured":"4950"}' + +echo " * getunusedaddress" +NEW_ADDR=`$EL getunusedaddress` + +echo " * payto & broadcast" +TXID=$($EL broadcast $($EL payto $NEW_ADDR 123 --fee 0.001 --password='')) + +echo " * get_tx_status" +test "`$EL get_tx_status $TXID | jq -c .`" == '{"confirmations":0}' + +echo " * getaddresshistory" +test "`$EL getaddresshistory $NEW_ADDR | jq -c .`" == "[{\"fee\":100000,\"height\":0,\"tx_hash\":\"$TXID\"}]" + +echo " * getbalance" +test "`$EL getbalance | jq -c .`" == '{"confirmed":"549.999","unmatured":"4950"}' + +echo "Generating bitcoin block..." +$BTC generatetoaddress 1 $MINING_ADDR > /dev/null +$BTC getblockcount > /dev/null + +echo " * wait for new block" +sudo killall -USR1 electrs # notify server to index new block +tail_log ~/electrum-debug.log | grep -m1 "verified $TXID" > /dev/null + +echo " * get_tx_status" +test "`$EL get_tx_status $TXID | jq -c .`" == '{"confirmations":1}' + +echo " * getaddresshistory" +test "`$EL getaddresshistory $NEW_ADDR | jq -c .`" == "[{\"height\":111,\"tx_hash\":\"$TXID\"}]" + +echo " * getbalance" +test "`$EL getbalance | jq -c .`" == '{"confirmed":"599.999","unmatured":"4950.001"}' + +echo "Electrum `$EL stop`" # disconnect wallet +wait $ELECTRUM_PID + +echo "=== PASSED ==="