preparescript: Fix missing btc wallet with --addcoin=bitcoin and --usebtcfastsync

doc: Fetch latest xmr chain height
This commit is contained in:
tecnovert 2022-06-18 19:28:40 +02:00
parent f787bdb203
commit d2324ad097
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
7 changed files with 94 additions and 56 deletions

View file

@ -20,10 +20,13 @@ from xmlrpc.client import (
from .util import jsonDecimal from .util import jsonDecimal
def waitForRPC(rpc_func, wallet=None, max_tries=7): def waitForRPC(rpc_func, expect_wallet=True, max_tries=7):
for i in range(max_tries + 1): for i in range(max_tries + 1):
try: try:
if expect_wallet:
rpc_func('getwalletinfo') rpc_func('getwalletinfo')
else:
rpc_func('getblockchaininfo')
return return
except Exception as ex: except Exception as ex:
if i < max_tries: if i < max_tries:

View file

@ -702,7 +702,7 @@ def modify_tor_config(settings, coin, tor_control_password=None, enable=False):
writeTorSettings(fp, coin, coin_settings, tor_control_password) writeTorSettings(fp, coin, coin_settings, tor_control_password)
def make_rpc_func(bin_dir, data_dir, chain): def make_rpc_func(bin_dir, data_dir, chain, cli_binary=cfg.PARTICL_CLI):
bin_dir = bin_dir bin_dir = bin_dir
data_dir = data_dir data_dir = data_dir
chain = chain chain = chain
@ -712,7 +712,7 @@ def make_rpc_func(bin_dir, data_dir, chain):
nonlocal data_dir nonlocal data_dir
nonlocal chain nonlocal chain
return callrpc_cli(bin_dir, data_dir, chain, cmd, cfg.PARTICL_CLI) return callrpc_cli(bin_dir, data_dir, chain, cmd, cli_binary)
return rpc_func return rpc_func
@ -761,6 +761,15 @@ def printHelp():
logger.info('\n' + 'Known coins: %s', ', '.join(known_coins.keys())) logger.info('\n' + 'Known coins: %s', ', '.join(known_coins.keys()))
def finalise_daemon(d):
logging.info('Interrupting {}'.format(d.pid))
d.send_signal(signal.SIGINT)
d.wait(timeout=120)
for fp in (d.stdout, d.stderr, d.stdin):
if fp:
fp.close()
def main(): def main():
global use_tor_proxy global use_tor_proxy
data_dir = None data_dir = None
@ -1086,6 +1095,22 @@ def main():
if not prepare_bin_only: if not prepare_bin_only:
prepareDataDir(add_coin, settings, chain, particl_wallet_mnemonic, extra_opts) prepareDataDir(add_coin, settings, chain, particl_wallet_mnemonic, extra_opts)
if use_btc_fastsync and add_coin == 'bitcoin':
# Need to create wallet file through daemon
logger.info('Creating wallet.dat for {}.'.format(add_coin.capitalize()))
bitcoin_settings = settings['chainclients']['bitcoin']
try:
btcRpc = make_rpc_func(bitcoin_settings['bindir'], bitcoin_settings['datadir'], chain, cli_binary=cfg.BITCOIN_CLI)
filename = 'bitcoind' + ('.exe' if os.name == 'nt' else '')
daemon_args = ['-noconnect', '-nodnsseed', '-nolisten']
btcd = startDaemon(bitcoin_settings['datadir'], bitcoin_settings['bindir'], filename, daemon_args)
waitForRPC(btcRpc, expect_wallet=False, max_tries=12)
btcRpc('createwallet wallet.dat')
logger.info('createwallet succeeded.')
finally:
finalise_daemon(btcd)
with open(config_path, 'w') as fp: with open(config_path, 'w') as fp:
json.dump(settings, fp, indent=4) json.dump(settings, fp, indent=4)
@ -1202,12 +1227,7 @@ def main():
del swap_client del swap_client
finally: finally:
for d in daemons: for d in daemons:
logging.info('Interrupting {}'.format(d.pid)) finalise_daemon(d)
d.send_signal(signal.SIGINT)
d.wait(timeout=120)
for fp in (d.stdout, d.stderr, d.stdin):
if fp:
fp.close()
logger.info('IMPORTANT - Save your particl wallet recovery phrase:\n{}\n'.format(particl_wallet_mnemonic)) logger.info('IMPORTANT - Save your particl wallet recovery phrase:\n{}\n'.format(particl_wallet_mnemonic))
logger.info('Done.') logger.info('Done.')

View file

@ -1,14 +1,14 @@
## Source code ## Source code
$ git clone https://github.com/tecnovert/basicswap.git git clone https://github.com/tecnovert/basicswap.git
## Run Using Docker ## Run Using Docker
Docker must be installed and started: Docker must be installed and started:
$ docker -v docker -v
Should return a line containing `Docker version`... Should return a line containing `Docker version`...
@ -20,19 +20,23 @@ It's recommended to setup docker to work without sudo:
#### Create the images: #### Create the images:
$ cd basicswap/docker cd basicswap/docker
$ docker-compose build docker-compose build
#### Prepare the datadir: #### Prepare the datadir:
Set XMR_RPC_HOST and BASE_XMR_RPC_PORT to a public XMR node or exclude to run a local node. Set XMR_RPC_HOST and BASE_XMR_RPC_PORT to a public XMR node or exclude to run a local node.
Set xmrrestoreheight to the current xmr chain height. Set xmrrestoreheight to the current xmr chain height.
CURRENT_XMR_HEIGHT=$(curl https://localmonero.co/blocks/api/get_stats | jq .height)
Adjust `--withcoins` and `--withoutcoins` as desired, eg: `--withcoins=monero,bitcoin`. By default only Particl is loaded. Adjust `--withcoins` and `--withoutcoins` as desired, eg: `--withcoins=monero,bitcoin`. By default only Particl is loaded.
$ export COINDATA_PATH=/var/data/coinswaps export COINDATA_PATH=/var/data/coinswaps
$ docker run --rm -e XMR_RPC_HOST="node.xmr.to" -e BASE_XMR_RPC_PORT=18081 -t --name swap_prepare -v $COINDATA_PATH:/coindata i_swapclient \ docker run --rm -e XMR_RPC_HOST="node.xmr.to" -e BASE_XMR_RPC_PORT=18081 -t --name swap_prepare -v $COINDATA_PATH:/coindata i_swapclient \
basicswap-prepare --datadir=/coindata --withcoins=monero --htmlhost="0.0.0.0" --xmrrestoreheight=2485205 basicswap-prepare --datadir=/coindata --withcoins=monero --htmlhost="0.0.0.0" --xmrrestoreheight=$CURRENT_XMR_HEIGHT
**Record the mnemonic from the output of the above command.** **Record the mnemonic from the output of the above command.**
@ -51,8 +55,8 @@ Valid options can be listed with: `timedatectl list-timezones`
#### Start the container: #### Start the container:
$ export COINDATA_PATH=/var/data/coinswaps export COINDATA_PATH=/var/data/coinswaps
$ docker-compose up docker-compose up
Open in browser: `http://localhost:12700` Open in browser: `http://localhost:12700`
@ -60,9 +64,9 @@ Open in browser: `http://localhost:12700`
### Add a coin ### Add a coin
$ docker-compose stop docker-compose stop
$ export COINDATA_PATH=/var/data/coinswaps export COINDATA_PATH=/var/data/coinswaps
$ docker run --rm -t --name swap_prepare -v $COINDATA_PATH:/coindata i_swapclient basicswap-prepare --datadir=/coindata --addcoin=bitcoin docker run --rm -t --name swap_prepare -v $COINDATA_PATH:/coindata i_swapclient basicswap-prepare --datadir=/coindata --addcoin=bitcoin
You can copy an existing pruned datadir (excluding bitcoin.conf and any wallets) over to `$COINDATA_PATH/bitcoin` You can copy an existing pruned datadir (excluding bitcoin.conf and any wallets) over to `$COINDATA_PATH/bitcoin`
Remove any existing wallets after copying over a pruned chain or the Bitcoin daemon won't start. Remove any existing wallets after copying over a pruned chain or the Bitcoin daemon won't start.
@ -81,14 +85,14 @@ Windows key + R -> "wsl" -> Enter
Install Git: Install Git:
$ sudo apt update sudo apt update
$ sudo apt install git sudo apt install git
Download the BasicSwap code: Download the BasicSwap code:
$ git clone https://github.com/tecnovert/basicswap.git git clone https://github.com/tecnovert/basicswap.git
$ cd basicswap/docker/ cd basicswap/docker/
It's significantly faster to set COINDATA_PATH in the linux filesystem. It's significantly faster to set COINDATA_PATH in the linux filesystem.
@ -102,61 +106,72 @@ Continue from the [Run Using Docker](#run-using-docker) section.
### Ubuntu Setup: ### Ubuntu Setup:
$ apt-get install -y wget python3-pip gnupg unzip protobuf-compiler automake libtool pkg-config apt-get install -y wget python3-pip gnupg unzip protobuf-compiler automake libtool pkg-config curl jq
### OSX Setup: ### OSX Setup:
Install Homebrew: Install Homebrew (See https://brew.sh/):
https://brew.sh/ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Command Line Tools: Command Line Tools:
$ xcode-select --install xcode-select --install
Dependencies: Dependencies:
$ brew install wget unzip python git protobuf gnupg automake libtool pkg-config brew install wget unzip python3 git protobuf gnupg automake libtool pkg-config curl jq
Install python SSL Certificates:
sudo "/Applications/Python 3.9/Install Certificates.command"
### Basicswap: ### Basicswap:
$ export SWAP_DATADIR=/Users/$USER/coinswaps export SWAP_DATADIR=/Users/$USER/coinswaps
$ mkdir -p "$SWAP_DATADIR/venv" mkdir -p "$SWAP_DATADIR/venv"
$ python3 -m venv "$SWAP_DATADIR/venv" python3 -m venv "$SWAP_DATADIR/venv"
$ . $SWAP_DATADIR/venv/bin/activate && python -V . $SWAP_DATADIR/venv/bin/activate && python -V
$ cd $SWAP_DATADIR cd $SWAP_DATADIR
$ wget -O coincurve-anonswap.zip https://github.com/tecnovert/coincurve/archive/anonswap.zip wget -O coincurve-anonswap.zip https://github.com/tecnovert/coincurve/archive/anonswap.zip
$ unzip coincurve-anonswap.zip unzip coincurve-anonswap.zip
$ cd $SWAP_DATADIR/coincurve-anonswap cd $SWAP_DATADIR/coincurve-anonswap
$ pip3 install . pip3 install .
$ cd $SWAP_DATADIR cd $SWAP_DATADIR
$ git clone https://github.com/tecnovert/basicswap.git git clone https://github.com/tecnovert/basicswap.git
$ cd $SWAP_DATADIR/basicswap cd $SWAP_DATADIR/basicswap
$ protoc -I=basicswap --python_out=basicswap basicswap/messages.proto protoc -I=basicswap --python_out=basicswap basicswap/messages.proto
$ pip3 install . pip3 install .
Prepare the datadir: Prepare the datadir:
XMR_RPC_HOST="node.xmr.to" BASE_XMR_RPC_PORT=18081 basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero --xmrrestoreheight=2245107 CURRENT_XMR_HEIGHT=$(curl https://localmonero.co/blocks/api/get_stats | jq .height)
XMR_RPC_HOST="node.xmr.to" BASE_XMR_RPC_PORT=18081 basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero --xmrrestoreheight=$CURRENT_XMR_HEIGHT
OR using a local XMR daemon: OR using a local XMR daemon:
basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero --xmrrestoreheight=2245107 basicswap-prepare --datadir=$SWAP_DATADIR --withcoins=monero --xmrrestoreheight=$CURRENT_XMR_HEIGHT
Record the mnemonic from the output of the above command. Record the mnemonic from the output of the above command.
Start the app Start Basicswap:
$ basicswap-run --datadir=$SWAP_DATADIR basicswap-run --datadir=$SWAP_DATADIR
Open in browser: `http://localhost:12700` Open in browser: `http://localhost:12700`
It may take a few minutes to start as the coin daemons are started before the http interface. It may take a few minutes to start as the coin daemons are started before the http interface.
Add a coin:
export SWAP_DATADIR=/Users/$USER/coinswaps
basicswap-prepare --usebtcfastsync --datadir=/$SWAP_DATADIR --addcoin=bitcoin
Start after installed: Start after installed:
$ export SWAP_DATADIR=/Users/$USER/coinswaps export SWAP_DATADIR=/Users/$USER/coinswaps
$ . $SWAP_DATADIR/venv/bin/activate && python -V . $SWAP_DATADIR/venv/bin/activate && python -V
$ basicswap-run --datadir=$SWAP_DATADIR basicswap-run --datadir=$SWAP_DATADIR

View file

@ -5,7 +5,7 @@ FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=bitcoin --withoutcoins=particl && \ RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=bitcoin --withoutcoins=particl && \
find /coin_bin -name *.tar.gz -delete find /coin_bin -name *.tar.gz -delete
FROM debian:buster-slim FROM debian:bullseye-slim
COPY --from=install_stage /coin_bin . COPY --from=install_stage /coin_bin .
ENV BITCOIN_DATA /data ENV BITCOIN_DATA /data

View file

@ -3,7 +3,7 @@ FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=litecoin --withoutcoin=particl && \ RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=litecoin --withoutcoin=particl && \
find /coin_bin -name *.tar.gz -delete find /coin_bin -name *.tar.gz -delete
FROM debian:buster-slim FROM debian:bullseye-slim
COPY --from=install_stage /coin_bin . COPY --from=install_stage /coin_bin .
ENV LITECOIN_DATA /data ENV LITECOIN_DATA /data

View file

@ -2,7 +2,7 @@ FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=monero --withoutcoins=particl RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=monero --withoutcoins=particl
FROM debian:buster-slim FROM debian:bullseye-slim
COPY --from=install_stage /coin_bin . COPY --from=install_stage /coin_bin .

View file

@ -3,7 +3,7 @@ FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=particl && \ RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=particl && \
find /coin_bin -name *.tar.gz -delete find /coin_bin -name *.tar.gz -delete
FROM debian:buster-slim FROM debian:bullseye-slim
COPY --from=install_stage /coin_bin . COPY --from=install_stage /coin_bin .
ENV PARTICL_DATA /data ENV PARTICL_DATA /data