From bd938990664be52c6b12107dd370ac9d26986f38 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Thu, 25 Jul 2019 14:06:58 +0200 Subject: [PATCH] Add preparebinonly option to basicswap-prepare, Download, verify and extract coin cores only. --- .travis.yml | 2 +- Dockerfile | 2 +- basicswap/basicswap.py | 6 +++--- basicswap/http_server.py | 2 ++ bin/basicswap_prepare.py | 19 ++++++++++++++++--- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index e98ca0d..6fefd50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,6 +40,6 @@ jobs: before_script: script: - PYTHONWARNINGS="ignore" flake8 --ignore=E501,F841 --exclude=key.py,messages_pb2.py,.eggs - - codespell --check-filenames --disable-colors --quiet-level=7 -S .git,.eggs + - codespell --check-filenames --disable-colors --quiet-level=7 -S .git,.eggs,gitianpubkeys after_success: - echo "End lint" diff --git a/Dockerfile b/Dockerfile index 5b4f9d0..9505d4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN wget -O bs.zip https://github.com/tecnovert/basicswap/archive/master.zip; \ pip3 install .; # Download binaries, these will be part of the docker image -RUN basicswap-prepare -datadir=/opt --particl_mnemonic=none +RUN basicswap-prepare -datadir=/opt -preparebinonly RUN useradd -ms /bin/bash user; \ mkdir /coindata && chown user /coindata diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 19d0b90..d6c42c6 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -1306,8 +1306,8 @@ class BasicSwap(): else: # Lock from the height or time of the block containing the initiate txn coin_from = Coins(offer.coin_from) - initiate_tx_block_hash = self.callcoinrpc(coin_from, 'getblockhash', [bid.initiate_txn_height,]) - initiate_tx_block_time = int(self.callcoinrpc(coin_from, 'getblock', [initiate_tx_block_hash,])['time']) + initiate_tx_block_hash = self.callcoinrpc(coin_from, 'getblockhash', [bid.initiate_txn_height, ]) + initiate_tx_block_time = int(self.callcoinrpc(coin_from, 'getblock', [initiate_tx_block_hash, ])['time']) if offer.lock_type == ABS_LOCK_BLOCKS: # Walk the coin_to chain back until block time matches blockchaininfo = self.callcoinrpc(coin_to, 'getblockchaininfo') @@ -1316,7 +1316,7 @@ class BasicSwap(): max_tries = 1000 for i in range(max_tries): self.log.debug('wtf %d', i) - prev_block = self.callcoinrpc(coin_to, 'getblock', [cblock_hash,]) + prev_block = self.callcoinrpc(coin_to, 'getblock', [cblock_hash, ]) self.log.debug('prev_block %s', str(prev_block)) if prev_block['time'] <= initiate_tx_block_time: diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 089d432..e08ceeb 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -29,6 +29,8 @@ from .basicswap import ( getBidState, getTxState, getLockName, + SEQUENCE_LOCK_TIME, + ABS_LOCK_TIME, ) diff --git a/bin/basicswap_prepare.py b/bin/basicswap_prepare.py index 6740d0b..12fe46d 100644 --- a/bin/basicswap_prepare.py +++ b/bin/basicswap_prepare.py @@ -235,11 +235,13 @@ def printHelp(): logger.info('--mainnet Run in mainnet mode.') logger.info('--testnet Run in testnet mode.') logger.info('--regtest Run in regtest mode.') - logger.info('--particl_mnemonic= Recovery phrase to use for the Particl wallet, default is randomly generated,\n' - + ' "none" to set autogenerate account mode.') + logger.info('--particl_mnemonic= Recovery phrase to use for the Particl wallet, default is randomly generated,\n' + + ' "none" to set autogenerate account mode.') logger.info('--withcoin= Prepare system to run daemon for coin.') logger.info('--withoutcoin= Do not prepare system to run daemon for coin.') logger.info('--addcoin= Add coin to existing setup.') + logger.info('--preparebinonly Don\'t prepare settings or datadirs.') + logger.info('\n' + 'Known coins: %s', ', '.join(known_coins.keys())) @@ -276,6 +278,7 @@ def main(): data_dir = None chain = 'mainnet' particl_wallet_mnemonic = None + prepare_bin_only = False with_coins = {'particl', 'litecoin'} add_coin = '' @@ -304,6 +307,9 @@ def main(): if name == 'regtest': chain = 'regtest' continue + if name == 'preparebinonly': + prepare_bin_only = True + continue if len(s) == 2: if name == 'datadir': @@ -424,12 +430,19 @@ def main(): continue coin = c prepareCore(coin, v, settings, data_dir) + + if prepare_bin_only: + logger.info('Done.') + return 0 + + for c, v in known_coins.items(): + if c not in with_coins: + continue prepareDataDir(coin, settings, data_dir, chain, particl_wallet_mnemonic) with open(config_path, 'w') as fp: json.dump(settings, fp, indent=4) - if particl_wallet_mnemonic == 'none': logger.info('Done.') return 0