Decred: Add proxy config when using tor.

master^2
tecnovert 7 months ago
parent 73b4b2a46b
commit 62aa1fa5d7
  1. 7
      basicswap/interface/dcr/dcr.py
  2. 2
      basicswap/templates/offer_new_1.html
  3. 6
      basicswap/util/integer.py
  4. 23
      bin/basicswap_prepare.py
  5. 2
      doc/tor.md

@ -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

@ -233,7 +233,7 @@
<input class="pl-10 hover:border-blue-500 pl-10 bg-gray-50 text-gray-900 appearance-none pr-10 dark:bg-gray-500 dark:text-white border border-gray-300 dark:border-gray-400 dark:text-gray-50 dark:placeholder-white text-sm rounded-lg outline-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 focus:ring-0" type="text" id="rate" name="rate" value="{{ data.rate }}" onchange="set_rate('rate');">
</div>
<div class="text-sm mt-2">
<a href="" id="get_rate_inferred_button" class="mt-2 dark:text-white bold text-coolGray-800">Get Rate Inferred:<span id="rate_inferred_display"></span></a>
<a href="" id="get_rate_inferred_button" class="mt-2 dark:text-white bold text-coolGray-800">Get Rate Inferred:</a><span class="dark:text-white" id="rate_inferred_display"></span>
</div>
<div class="flex form-check form-check-inline mt-5">
<div class="flex items-center h-5"> <input class="form-check-input hover:border-blue-500 w-5 h-5 form-check-input text-blue-600 bg-gray-50 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-1 dark:bg-gray-500 dark:border-gray-400" type="checkbox" id="rate_lock" name="rate_lock" value="rl" checked=checked> </div>

@ -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:

@ -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

@ -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

Loading…
Cancel
Save