diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c3050a6..d797e0b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,7 +70,7 @@ jobs: run: ${{ matrix.install }} - name: Install basicswap-bash run: | - ./basicswap-install.sh --new --tor --internal --regtest + ./basicswap-install.sh --new --tor --fullnode --internal --regtest - name: Run bsx-update run: | if [ -n "${{ matrix.set-path }}" ]; then @@ -92,7 +92,7 @@ jobs: - uses: actions/checkout@v4 - name: Install basicswap-bash run: | - ./basicswap-install.sh --new --tor --internal --regtest + ./basicswap-install.sh --new --tor --fullnode --internal --regtest - name: Run bsx-update run: | bsx-update diff --git a/basicswap-install.sh b/basicswap-install.sh index 89685ad..200cfc2 100755 --- a/basicswap-install.sh +++ b/basicswap-install.sh @@ -54,7 +54,7 @@ ${PIPX_UV:-} # Enable tor echo -e "\n[1] Tor ON (requires sudo)\n[2] Tor OFF" until [[ "$tor_on" =~ ^[12]$ ]]; do - if [[ "$1 $2 $3" == *"tor"* ]]; then + if [[ "$1 $2 $3 $4" == *"tor"* ]]; then tor_on=1 else read -p 'Select an option: [1|2]: ' tor_on @@ -75,7 +75,7 @@ done ## Particl restore Seed echo -e "\n[1] New Install\n[2] Restore from Particl Seed" until [[ "$restore" =~ ^[12]$ ]]; do - if [[ "$1 $2 $3" == *"new"* ]]; then + if [[ "$1 $2 $3 $4" == *"new"* ]]; then restore=1 else read -p 'Select an option: [1|2]: ' restore @@ -112,7 +112,7 @@ if [[ $particl_mnemonic ]]; then *) until [[ "$xmrrestoreheight" =~ ^[0-9]{1,7}$ ]]; do read -p $'Enter your Monero Restore Height [example: 2548568] ' xmrrestoreheight - if [[ $xmrrestoreheight =~ ^[0-9]{7}$ ]]; then + if [[ $xmrrestoreheight =~ ^[0-9]{1,7}$ ]]; then green "Your XMR Restore height: $xmrrestoreheight" else red "Try again. Must be 1-7 digits" @@ -122,10 +122,43 @@ if [[ $particl_mnemonic ]]; then esac fi +# Electrum BTC & LTC +echo -e "\nAdd Electrum (light) wallets for the following coins:" +echo -e "\n[1] BTC \n[2] LTC (no MWEB support)\n[3] Both\n[4] Skip" +until [[ "$electrum" =~ ^[1-4]$ ]]; do + if [[ "$1 $2 $3 $4" == *"electrum"* ]]; then + electrum=3 + elif [[ "$1 $2 $3 $4" == *"fullnode"* ]]; then + electrum=4 + else + read -p 'Select an option [1-4]: ' electrum + fi + case $electrum in + 1) + use_electrum="--btc-mode=electrum --withcoins=bitcoin" + green "Using Electrum for BTC" + ;; + 2) + use_electrum="--ltc-mode=electrum --withcoins=litecoin" + green "Using Electrum for LTC" + ;; + 3) + use_electrum="--light --withcoins=bitcoin,litecoin" + green "Using Electrum for BTC and LTC wallets" + ;; + 4) + echo "Not setting up BTC and LTC" + ;; + *) + red "You must answer 1-4" + ;; + esac +done + ## Configure Monero echo -e "\n[1] Connect to a Monero node\n[2] Allow BasicSwapDEX to run a Monero node (+90GB)" until [[ "$node" =~ ^[12]$ ]]; do - if [[ "$1 $2 $3" == *"internal"* ]]; then + if [[ "$1 $2 $3 $4" == *"internal"* ]]; then node=2 else read -p 'Select an option [1|2]: ' node @@ -217,6 +250,7 @@ fi cp -r basicswap-bash bsx* $HOME/.local/bin/. ## Make venv and set variables for install +export use_electrum="${use_electrum}" export monerod_addr="${monerod_addr}" export monerod_port="${monerod_port}" export monerod_user="${monerod_user}" diff --git a/bsx/addcoin.sh b/bsx/addcoin.sh index ceaeb0f..c7ea993 100755 --- a/bsx/addcoin.sh +++ b/bsx/addcoin.sh @@ -14,14 +14,56 @@ fi local_only=(namecoin litecoin pivx bitcoincash firo) # coins with separate wallet daemons wallet_daemon_coins=(monero wownero decred) +# electrum +electrum_capable=(bitcoin litecoin) manage_daemon_false() { jq ".chainclients.${addcoin}.manage_daemon = false" \ $SWAP_DATADIR/basicswap.json > basicswap.tmp && mv basicswap.tmp $SWAP_DATADIR/basicswap.json } -## Remote node +use_electrum() { + jq '.chainclients.'${addcoin}'.connection_type = "electrum"' \ + $SWAP_DATADIR/basicswap.json > basicswap.tmp && mv basicswap.tmp $SWAP_DATADIR/basicswap.json +} + +existing_config=$(jq .chainclients."${addcoin}" $SWAP_DATADIR/basicswap.json) + +## Grab tickers detect_os_arch +if [[ "${MACOS}" ]]; then + ticker="$(get_coin_ticker "${addcoin}")" +else + ticker="${coin_map[$addcoin]}" +fi + +## Electrum +for coin in "${electrum_capable[@]}"; do + if [[ "${coin}" = "${addcoin}" ]]; then + read -p "Use Electrum for ${addcoin}? [Y/n]: " electrum + if ! [[ "${electrum}" =~ ^[nN]$ ]]; then + skip=1 + ticker=$(echo "${ticker,,}") + use_electrum="--${ticker}-mode=electrum" + if [[ "${existing_config}" = null ]]; then + read -p 'Use a custom electrum server? [y/N]: ' server + if [[ "${server}" =~ ^[yY]$ ]]; then + until [[ "$confirm_server" =~ ^[yY]$ ]]; do + read -p 'Enter server address. Syntax "
:[:]" [example: litecoin.stackwallet.com:20063]: ' server_address + green "Is this correct? ${server_address} [y/N]: " + read -p "" confirm_server + done + electrum_server_address="--${ticker}-electrum-server=${server_address}" + green "Using Electrum server @ ${server_address}" + else + echo "Using preset Electrum servers" + fi + fi + fi + fi +done + +## Remote node for coin in "${local_only[@]}"; do if [[ "${coin}" = "${addcoin}" ]]; then skip=1 @@ -31,11 +73,6 @@ done if ! [[ "${skip}" ]]; then # Set wallet name - if [[ "${MACOS}" ]]; then - ticker="$(get_coin_ticker "${addcoin}")" - else - ticker="${coin_map[$addcoin]}" - fi wallet_env="${ticker}_WALLET_NAME" wallet_name="BSX_${ticker}" @@ -89,16 +126,23 @@ fi ## Add the coin fastsync="" -if [[ ! "${remote_node}" =~ ^[yY]$ ]] && [[ "${addcoin}" = bitcoin ]]; then - read -p 'Use --usebtcfastsync for bitcoin? [Y/n] ' btcfastsync +if [[ ! -d "${SWAP_DATADIR}/bitcoin/blocks" ]] && [[ ! "${remote_node}" =~ ^[yY]$ ]] && [[ "${addcoin}" = bitcoin ]]; then + if [[ -z "${use_electrum}" ]]; then + read -p 'Use --usebtcfastsync for bitcoin? [Y/n] ' btcfastsync + else + echo "Use --usebtcfastsync for bitcoin? This will reduce sync time if you" + read -p 'decide to switch from Electrum to full node in the future. (~20gb) [Y/n] ' btcfastsync + fi if [[ "${btcfastsync}" =~ ^[nN]$ ]]; then echo "Not using btcfastsync" else - echo "Using btcfastsync" + green "Using btcfastsync" fastsync="--usebtcfastsync" fi fi -basicswap-prepare --datadir=$SWAP_DATADIR --addcoin=$addcoin ${fastsync:+$fastsync} +basicswap-prepare --datadir=$SWAP_DATADIR --addcoin=$addcoin ${use_electrum:-} ${electrum_server_address:-} ${fastsync:-} # if re-enabling coin that is using a remote daemon, disable "manage_daemon" [[ "${remote_node}" =~ ^[yY]$ ]] && [[ -z "${node_ip}" ]] && manage_daemon_false +# addcoin doesnt respect electrum flags if re-enabling +[[ "${existing_config}" != null ]] && [[ "${use_electrum}" ]] && use_electrum && manage_daemon_false diff --git a/bsx/setup.sh b/bsx/setup.sh index 9f94316..65ff8b4 100755 --- a/bsx/setup.sh +++ b/bsx/setup.sh @@ -44,7 +44,7 @@ enable_tor() { # Install bsx [[ $monerod_addr ]] && export XMR_RPC_HOST=$monerod_addr XMR_RPC_PORT=$monerod_port [[ $monerod_user ]] && export XMR_RPC_USER=$monerod_user XMR_RPC_PWD=$monerod_pass -basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$xmrrestoreheight --wowrestoreheight=600000 ${particl_mnemonic:+"--particl_mnemonic=\"$particl_mnemonic\""} ${regtest:-} || { +basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero,wownero --xmrrestoreheight=$xmrrestoreheight --wowrestoreheight=600000 ${particl_mnemonic:+"--particl_mnemonic=\"$particl_mnemonic\""} ${use_electrum:-} ${regtest:-} || { red "Installation failed. Try again" exit 1 } diff --git a/bsx/shared.sh b/bsx/shared.sh index a59499e..4aaee22 100755 --- a/bsx/shared.sh +++ b/bsx/shared.sh @@ -11,7 +11,7 @@ export BSX_LOCAL_TOR=true # sets host to 127.0.0.1 export BSX_ALLOW_ENV_OVERRIDE=true # required to change the ports # Network -[[ "${1}${2}${3}${4}" == *"regtest"* ]] && export regtest="--regtest" +[[ "${1}${2}${3}${4}${5}" == *"regtest"* ]] && export regtest="--regtest" # Colors red() { echo -e "\e[31;1m$*\e[0m"; } @@ -102,6 +102,7 @@ is_encrypted() { until [[ $pass1 ]] && [[ $pass1 = $pass2 ]]; do read -sp 'Enter your existing BasicSwap encryption password: ' pass1 read -sp $'\nRe-enter your BasicSwap encryption password: ' pass2 + echo if [[ $pass1 = $pass2 ]]; then export WALLET_ENCRYPTION_PWD=$pass1 else