From 58a270752669cc10e38061b14a03265654a061a8 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Tue, 11 Oct 2022 07:55:35 +0200 Subject: [PATCH 1/2] merge: Fix merge and lint issues. --- .cirrus.yml | 2 +- .travis.yml | 2 +- basicswap/basicswap.py | 25 ++++++++----------------- basicswap/http_server.py | 2 +- basicswap/interface/btc.py | 13 +++++++++++++ basicswap/js_server.py | 1 + basicswap/templates/active.html | 2 +- basicswap/templates/header.html | 4 ++-- basicswap/templates/index.html | 2 +- basicswap/ui/page_automation.py | 1 + 10 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 285c5fa..b30f755 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -8,7 +8,7 @@ lint_task: script: - flake8 --version - PYTHONWARNINGS="ignore" flake8 --ignore=E501,F841,W503 --exclude=basicswap/contrib,basicswap/interface/contrib,messages_pb2.py,.eggs,.tox,bin/install_certifi.py - - codespell --check-filenames --disable-colors --quiet-level=7 --ignore-words=tests/lint/spelling.ignore-words.txt -S .git,.eggs,.tox,pgp,*.pyc,*basicswap/contrib,*basicswap/interface/contrib,*mnemonics.py,bin/install_certifi.py + - codespell --check-filenames --disable-colors --quiet-level=7 --ignore-words=tests/lint/spelling.ignore-words.txt -S .git,.eggs,.tox,pgp,*.pyc,*basicswap/contrib,*basicswap/interface/contrib,*mnemonics.py,bin/install_certifi.py,*basicswap/static test_task: environment: diff --git a/.travis.yml b/.travis.yml index 78ceeb4..929bffb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,7 +53,7 @@ jobs: before_script: script: - PYTHONWARNINGS="ignore" flake8 --ignore=E501,F841,W503 --exclude=basicswap/contrib,basicswap/interface/contrib,messages_pb2.py,.eggs,.tox,bin/install_certifi.py - - codespell --check-filenames --disable-colors --quiet-level=7 --ignore-words=tests/lint/spelling.ignore-words.txt -S .git,.eggs,.tox,pgp,*.pyc,*basicswap/contrib,*basicswap/interface/contrib,*mnemonics.py,bin/install_certifi.py + - codespell --check-filenames --disable-colors --quiet-level=7 --ignore-words=tests/lint/spelling.ignore-words.txt -S .git,.eggs,.tox,pgp,*.pyc,*basicswap/contrib,*basicswap/interface/contrib,*mnemonics.py,bin/install_certifi.py,*basicswap/static after_success: - echo "End lint" - stage: test diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index b6fbea9..d939619 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -2415,21 +2415,9 @@ class BasicSwap(BaseApp): initiate_tx_block_time = int(self.callcoinrpc(coin_from, 'getblock', [initiate_tx_block_hash, ])['time']) if offer.lock_type == TxLockTypes.ABS_LOCK_BLOCKS: # Walk the coin_to chain back until block time matches - blockchaininfo = self.callcoinrpc(coin_to, 'getblockchaininfo') - cblock_hash = blockchaininfo['bestblockhash'] - cblock_height = blockchaininfo['blocks'] - max_tries = 1000 - for i in range(max_tries): - 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: - break - # cblock_hash and height are out of step unless loop breaks - cblock_hash = prev_block['previousblockhash'] - cblock_height = prev_block['height'] - - ensure(prev_block['time'] <= initiate_tx_block_time, 'Block not found for lock height') + block_header_at = ci_to.getBlockHeaderAt(initiate_tx_block_time, block_after=True) + cblock_hash = block_header_at['hash'] + cblock_height = block_header_at['height'] self.log.debug('Setting lock value from height of block %s %s', coin_to, cblock_hash) contract_lock_value = cblock_height + lock_value @@ -4084,7 +4072,10 @@ class BasicSwap(BaseApp): ensure(script_lock_value == expect_sequence, 'sequence mismatch') else: if offer.lock_type == TxLockTypes.ABS_LOCK_BLOCKS: - self.log.warning('TODO: validate absolute lock values') + block_header_from = ci_from.getBlockHeaderAt(bid.created_at) + chain_height_at_bid_creation = block_header_from['height'] + ensure(script_lock_value <= chain_height_at_bid_creation + offer.lock_value + atomic_swap_1.ABS_LOCK_BLOCKS_LEEWAY, 'script lock height too high') + ensure(script_lock_value >= chain_height_at_bid_creation + offer.lock_value - atomic_swap_1.ABS_LOCK_BLOCKS_LEEWAY, 'script lock height too low') else: ensure(script_lock_value <= bid.created_at + offer.lock_value + atomic_swap_1.INITIATE_TX_TIMEOUT, 'script lock time too high') ensure(script_lock_value >= bid.created_at + offer.lock_value, 'script lock time too low') @@ -5327,7 +5318,7 @@ class BasicSwap(BaseApp): 'version': self.coin_clients[coin]['core_version'], 'name': ci.coin_name(), 'blocks': blockchaininfo['blocks'], - 'synced': '{:.2f}'.format(round(100*blockchaininfo['verificationprogress'], 2)), + 'synced': '{:.2f}'.format(round(100 * blockchaininfo['verificationprogress'], 2)), } if 'known_block_count' in blockchaininfo: diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 17eb3b8..03a35aa 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -32,7 +32,6 @@ from .basicswap_util import ( from .js_server import ( js_error, js_url_to_function, - js_generatenotification, ) from .ui.util import ( getCoinName, @@ -88,6 +87,7 @@ def listExplorerActions(swap_client): ('unspent', 'List Unspent')] return actions + class HttpHandler(BaseHTTPRequestHandler): def checkForm(self, post_string, name, messages): diff --git a/basicswap/interface/btc.py b/basicswap/interface/btc.py index eea5ae9..85c06df 100644 --- a/basicswap/interface/btc.py +++ b/basicswap/interface/btc.py @@ -243,6 +243,19 @@ class BTCInterface(CoinInterface): def getBlockHeader(self, block_hash): return self.rpc_callback('getblockheader', [block_hash]) + def getBlockHeaderAt(self, time, block_after=False): + blockchaininfo = self.rpc_callback('getblockchaininfo') + last_block_header = self.rpc_callback('getblockheader', [blockchaininfo['bestblockhash']]) + + max_tries = 5000 + for i in range(max_tries): + prev_block_header = self.rpc_callback('getblock', [last_block_header['previousblockhash']]) + if prev_block_header['time'] <= time: + return last_block_header if block_after else prev_block_header + + last_block_header = prev_block_header + raise ValueError(f'Block header not found at time: {time}') + def initialiseWallet(self, key_bytes): key_wif = self.encodeKey(key_bytes) diff --git a/basicswap/js_server.py b/basicswap/js_server.py index b1d5f5f..ef50e4a 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -412,6 +412,7 @@ def js_url_to_function(url_split): }.get(url_split[2], js_index) return js_index + def js_generatenotification(self, url_split, post_string, is_json): swap_client = self.server.swap_client r = random.randint(0, 3) diff --git a/basicswap/templates/active.html b/basicswap/templates/active.html index 45ce7bf..96d7f8e 100644 --- a/basicswap/templates/active.html +++ b/basicswap/templates/active.html @@ -15,7 +15,7 @@ -
  • Swaps In Progres
  • +
  • Swaps In Progress
  • diff --git a/basicswap/templates/header.html b/basicswap/templates/header.html index 2a833c1..182d3e4 100644 --- a/basicswap/templates/header.html +++ b/basicswap/templates/header.html @@ -251,14 +251,14 @@
    Bitcoin
    -
    BTC DEPOSIT of 0.000493 BTC sucesfull.
    +
    BTC DEPOSIT of 0.000493 BTC successful.
    15 minutes ago
    Particl
    -
    PART WITHDRAW of 39.494 PART sucesfull.
    +
    PART WITHDRAW of 39.494 PART successful.
    30 minutes ago
    diff --git a/basicswap/templates/index.html b/basicswap/templates/index.html index b6d1ced..02018ba 100644 --- a/basicswap/templates/index.html +++ b/basicswap/templates/index.html @@ -20,7 +20,7 @@
    diff --git a/basicswap/ui/page_automation.py b/basicswap/ui/page_automation.py index 0a40366..6790e54 100644 --- a/basicswap/ui/page_automation.py +++ b/basicswap/ui/page_automation.py @@ -17,6 +17,7 @@ from basicswap.db import ( strConcepts, ) + def page_automation_strategies(self, url_split, post_string): server = self.server swap_client = server.swap_client From 5738cdd825a1a2c8a9a989b46c8773f6e7175302 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Tue, 11 Oct 2022 08:22:13 +0200 Subject: [PATCH 2/2] ui: Fix missing post_string on page_error --- basicswap/http_server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 03a35aa..7893656 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -132,7 +132,7 @@ class HttpHandler(BaseHTTPRequestHandler): **args_dict, ), 'UTF-8') - def page_info(self, info_str, post_string): + def page_info(self, info_str, post_string=None): template = env.get_template('info.html') swap_client = self.server.swap_client summary = swap_client.getSummary() @@ -142,7 +142,7 @@ class HttpHandler(BaseHTTPRequestHandler): 'summary': summary, }) - def page_error(self, error_str, post_string): + def page_error(self, error_str, post_string=None): template = env.get_template('error.html') swap_client = self.server.swap_client summary = swap_client.getSummary()