From 62aa1fa5d769c45e3e247cc040f7fbace8dcefc6 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Sat, 25 May 2024 11:22:12 +0200 Subject: [PATCH] Decred: Add proxy config when using tor. --- basicswap/interface/dcr/dcr.py | 7 +++++++ basicswap/templates/offer_new_1.html | 2 +- basicswap/util/integer.py | 6 +++--- bin/basicswap_prepare.py | 23 +++++++++++++++++++---- doc/tor.md | 2 +- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/basicswap/interface/dcr/dcr.py b/basicswap/interface/dcr/dcr.py index 3bf17c4..8f6dc6c 100644 --- a/basicswap/interface/dcr/dcr.py +++ b/basicswap/interface/dcr/dcr.py @@ -228,6 +228,13 @@ class DCRInterface(Secp256k1Interface): return secondsLocked | SEQUENCE_LOCKTIME_TYPE_FLAG raise ValueError('Unknown lock type') + @staticmethod + def decodeSequence(lock_value: int) -> int: + # Return the raw value + if lock_value & SEQUENCE_LOCKTIME_TYPE_FLAG: + return (lock_value & SEQUENCE_LOCKTIME_MASK) << SEQUENCE_LOCKTIME_GRANULARITY + return lock_value & SEQUENCE_LOCKTIME_MASK + @staticmethod def watch_blocks_for_scripts() -> bool: return True diff --git a/basicswap/templates/offer_new_1.html b/basicswap/templates/offer_new_1.html index e97c33e..a86b5ec 100644 --- a/basicswap/templates/offer_new_1.html +++ b/basicswap/templates/offer_new_1.html @@ -233,7 +233,7 @@
- Get Rate Inferred: + Get Rate Inferred:
diff --git a/basicswap/util/integer.py b/basicswap/util/integer.py index 75430dc..8fea309 100644 --- a/basicswap/util/integer.py +++ b/basicswap/util/integer.py @@ -11,11 +11,11 @@ def decode_compactsize(b: bytes, offset: int = 0) -> (int, int): return i, 1 offset += 1 if i == 0xfd: - return int.from_bytes(b[offset: offset + 2]), 3 + return int.from_bytes(b[offset: offset + 2], 'little'), 3 if i == 0xfe: - return int.from_bytes(b[offset: offset + 4]), 5 + return int.from_bytes(b[offset: offset + 4], 'little'), 5 # 0xff - return int.from_bytes(b[offset: offset + 8]), 9 + return int.from_bytes(b[offset: offset + 8], 'little'), 9 def encode_compactsize(i: int) -> bytes: diff --git a/bin/basicswap_prepare.py b/bin/basicswap_prepare.py index fa52aa0..cb986f1 100755 --- a/bin/basicswap_prepare.py +++ b/bin/basicswap_prepare.py @@ -835,12 +835,15 @@ def prepareCore(coin, version_data, settings, data_dir, extra_opts={}): def writeTorSettings(fp, coin, coin_settings, tor_control_password): - onionport = coin_settings['onionport'] ''' TOR_PROXY_HOST must be an ip address. BTC versions >21 and Particl with lookuptorcontrolhost=any can accept hostnames, XMR and LTC cannot ''' fp.write(f'proxy={TOR_PROXY_HOST}:{TOR_PROXY_PORT}\n') + if coin in ('decred',): + return + + onionport = coin_settings['onionport'] fp.write(f'torpassword={tor_control_password}\n') fp.write(f'torcontrol={TOR_PROXY_HOST}:{TOR_CONTROL_PORT}\n') @@ -936,6 +939,9 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic, extra_opts={}): fp.write('rpcuser={}\n'.format(core_settings['rpcuser'])) fp.write('rpcpass={}\n'.format(core_settings['rpcpassword'])) + if tor_control_password is not None: + writeTorSettings(fp, coin, core_settings, tor_control_password) + wallet_conf_path = os.path.join(data_dir, 'dcrwallet.conf') if os.path.exists(wallet_conf_path): exitWithError('{} exists'.format(wallet_conf_path)) @@ -1130,7 +1136,11 @@ def modify_tor_config(settings, coin, tor_control_password=None, enable=False, e coin_settings['trusted_daemon'] = extra_opts.get('trust_remote_node', 'auto') return - config_path = os.path.join(data_dir, coin + '.conf') + if coin == 'decred': + config_path = os.path.join(data_dir, 'dcrd.conf') + else: + config_path = os.path.join(data_dir, coin + '.conf') + if not os.path.exists(config_path): exitWithError('{} does not exist'.format(config_path)) @@ -1142,9 +1152,12 @@ def modify_tor_config(settings, coin, tor_control_password=None, enable=False, e default_onionport = PART_ONION_PORT elif coin == 'litecoin': default_onionport = LTC_ONION_PORT + elif coin in ('decred',): + pass else: exitWithError('Unknown default onion listening port for {}'.format(coin)) - coin_settings['onionport'] = default_onionport + if default_onionport > 0: + coin_settings['onionport'] = default_onionport # Backup shutil.copyfile(config_path, config_path + '.last') @@ -1599,7 +1612,7 @@ def main(): if use_tor_proxy and extra_opts.get('no_tor_proxy', False): exitWithError('Can\'t use --usetorproxy and --notorproxy together') - # Automatically enable tor for certain commands if it's set in basicswap config + # Automatically enable usetorproxy for certain commands if it's set in basicswap config if not (initwalletsonly or enable_tor or disable_tor or disable_coin) and \ not use_tor_proxy and os.path.exists(config_path): settings = load_config(config_path) @@ -1910,6 +1923,8 @@ def main(): if add_coin != '': logger.info('Adding coin: %s', add_coin) settings = load_config(config_path) + if tor_control_password is None and settings.get('use_tor', False): + extra_opts['tor_control_password'] = settings.get('tor_control_password', None) if particl_wallet_mnemonic != 'none': # Ensure Particl wallet is unencrypted or correct password is supplied diff --git a/doc/tor.md b/doc/tor.md index 7ea28cd..f61d3b3 100644 --- a/doc/tor.md +++ b/doc/tor.md @@ -22,7 +22,7 @@ Docker will create directories instead of files if these don't exist. #### For a new install Use the `--usetorproxy` argument to download the coin binaries over tor, then enable tor with `--enabletor`. -Note that some download links, notably for Litecoin, are unreachable when using tor. +Note that some download links may be unreachable when using tor. docker compose -f docker-compose_with_tor.yml run --rm swapclient \ basicswap-prepare --usetorproxy --datadir=/coindata --withcoins=monero,particl