|
|
@ -87,7 +87,7 @@ XMR_WALLET_RPC_USER = os.getenv('XMR_WALLET_RPC_USER', 'xmr_wallet_user') |
|
|
|
XMR_WALLET_RPC_PWD = os.getenv('XMR_WALLET_RPC_PWD', 'xmr_wallet_pwd') |
|
|
|
XMR_WALLET_RPC_PWD = os.getenv('XMR_WALLET_RPC_PWD', 'xmr_wallet_pwd') |
|
|
|
XMR_SITE_COMMIT = 'abcf12c4ccac3e48bb4ff178f18bb8a95d94b029' # Lock hashes.txt to monero version |
|
|
|
XMR_SITE_COMMIT = 'abcf12c4ccac3e48bb4ff178f18bb8a95d94b029' # Lock hashes.txt to monero version |
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_XMR_RESTORE_HEIGHT = 2245107 |
|
|
|
DEFAULT_XMR_RESTORE_HEIGHT = int(os.getenv('DEFAULT_XMR_RESTORE_HEIGHT', 2245107)) |
|
|
|
|
|
|
|
|
|
|
|
UI_HTML_PORT = int(os.getenv('UI_HTML_PORT', 12700)) |
|
|
|
UI_HTML_PORT = int(os.getenv('UI_HTML_PORT', 12700)) |
|
|
|
PART_ZMQ_PORT = int(os.getenv('PART_ZMQ_PORT', 20792)) |
|
|
|
PART_ZMQ_PORT = int(os.getenv('PART_ZMQ_PORT', 20792)) |
|
|
@ -125,6 +125,7 @@ TEST_ONION_LINK = toBool(os.getenv('TEST_ONION_LINK', 'false')) |
|
|
|
BITCOIN_FASTSYNC_URL = os.getenv('BITCOIN_FASTSYNC_URL', 'http://utxosets.blob.core.windows.net/public/') |
|
|
|
BITCOIN_FASTSYNC_URL = os.getenv('BITCOIN_FASTSYNC_URL', 'http://utxosets.blob.core.windows.net/public/') |
|
|
|
BITCOIN_FASTSYNC_FILE = os.getenv('BITCOIN_FASTSYNC_FILE', 'utxo-snapshot-bitcoin-mainnet-720179.tar') |
|
|
|
BITCOIN_FASTSYNC_FILE = os.getenv('BITCOIN_FASTSYNC_FILE', 'utxo-snapshot-bitcoin-mainnet-720179.tar') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use_tor_proxy = False |
|
|
|
use_tor_proxy = False |
|
|
|
|
|
|
|
|
|
|
|
default_socket = socket.socket |
|
|
|
default_socket = socket.socket |
|
|
@ -461,7 +462,11 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic, extra_opts={}): |
|
|
|
fp.write('restricted-rpc=1\n') |
|
|
|
fp.write('restricted-rpc=1\n') |
|
|
|
if chain == 'testnet': |
|
|
|
if chain == 'testnet': |
|
|
|
fp.write('testnet=1\n') |
|
|
|
fp.write('testnet=1\n') |
|
|
|
fp.write('data-dir={}\n'.format(data_dir)) |
|
|
|
config_datadir = data_dir |
|
|
|
|
|
|
|
if core_settings['manage_daemon'] is False: |
|
|
|
|
|
|
|
# Assume conf file is for isolated coin docker setup |
|
|
|
|
|
|
|
config_datadir = '/data' |
|
|
|
|
|
|
|
fp.write(f'data-dir={config_datadir}\n') |
|
|
|
fp.write('rpc-bind-port={}\n'.format(core_settings['rpcport'])) |
|
|
|
fp.write('rpc-bind-port={}\n'.format(core_settings['rpcport'])) |
|
|
|
fp.write('rpc-bind-ip={}\n'.format(COINS_RPCBIND_IP)) |
|
|
|
fp.write('rpc-bind-ip={}\n'.format(COINS_RPCBIND_IP)) |
|
|
|
fp.write('zmq-rpc-bind-port={}\n'.format(core_settings['zmqport'])) |
|
|
|
fp.write('zmq-rpc-bind-port={}\n'.format(core_settings['zmqport'])) |
|
|
@ -487,9 +492,13 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic, extra_opts={}): |
|
|
|
fp.write('no-dns=1\n') |
|
|
|
fp.write('no-dns=1\n') |
|
|
|
fp.write('rpc-bind-port={}\n'.format(core_settings['walletrpcport'])) |
|
|
|
fp.write('rpc-bind-port={}\n'.format(core_settings['walletrpcport'])) |
|
|
|
fp.write('rpc-bind-ip={}\n'.format(COINS_RPCBIND_IP)) |
|
|
|
fp.write('rpc-bind-ip={}\n'.format(COINS_RPCBIND_IP)) |
|
|
|
fp.write('wallet-dir={}\n'.format(os.path.join(data_dir, 'wallets'))) |
|
|
|
config_datadir = os.path.join(data_dir, 'wallets') |
|
|
|
fp.write('log-file={}\n'.format(os.path.join(data_dir, 'wallet.log'))) |
|
|
|
if core_settings['manage_wallet_daemon'] is False: |
|
|
|
fp.write('shared-ringdb-dir={}\n'.format(os.path.join(data_dir, 'shared-ringdb'))) |
|
|
|
# Assume conf file is for isolated coin docker setup |
|
|
|
|
|
|
|
config_datadir = '/data' |
|
|
|
|
|
|
|
fp.write(f'wallet-dir={config_datadir}\n') |
|
|
|
|
|
|
|
fp.write('log-file={}\n'.format(os.path.join(config_datadir, 'wallet.log'))) |
|
|
|
|
|
|
|
fp.write('shared-ringdb-dir={}\n'.format(os.path.join(config_datadir, 'shared-ringdb'))) |
|
|
|
fp.write('rpc-login={}:{}\n'.format(core_settings['walletrpcuser'], core_settings['walletrpcpassword'])) |
|
|
|
fp.write('rpc-login={}:{}\n'.format(core_settings['walletrpcuser'], core_settings['walletrpcpassword'])) |
|
|
|
|
|
|
|
|
|
|
|
if tor_control_password is not None: |
|
|
|
if tor_control_password is not None: |
|
|
@ -532,7 +541,7 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic, extra_opts={}): |
|
|
|
fp.write('staking=0\n') |
|
|
|
fp.write('staking=0\n') |
|
|
|
if PART_RPC_USER != '': |
|
|
|
if PART_RPC_USER != '': |
|
|
|
fp.write('rpcauth={}:{}${}\n'.format(PART_RPC_USER, salt, password_to_hmac(salt, PART_RPC_PWD))) |
|
|
|
fp.write('rpcauth={}:{}${}\n'.format(PART_RPC_USER, salt, password_to_hmac(salt, PART_RPC_PWD))) |
|
|
|
if particl_mnemonic == 'none': |
|
|
|
if particl_mnemonic == 'auto': |
|
|
|
fp.write('createdefaultmasterkey=1') |
|
|
|
fp.write('createdefaultmasterkey=1') |
|
|
|
elif coin == 'litecoin': |
|
|
|
elif coin == 'litecoin': |
|
|
|
fp.write('prune=4000\n') |
|
|
|
fp.write('prune=4000\n') |
|
|
@ -710,13 +719,14 @@ def printHelp(): |
|
|
|
logger.info('Usage: basicswap-prepare ') |
|
|
|
logger.info('Usage: basicswap-prepare ') |
|
|
|
logger.info('\n--help, -h Print help.') |
|
|
|
logger.info('\n--help, -h Print help.') |
|
|
|
logger.info('--version, -v Print version.') |
|
|
|
logger.info('--version, -v Print version.') |
|
|
|
logger.info('--datadir=PATH Path to basicswap data directory, default:{}.'.format(cfg.DEFAULT_DATADIR)) |
|
|
|
logger.info('--datadir=PATH Path to basicswap data directory, default:{}.'.format(cfg.BASICSWAP_DATADIR)) |
|
|
|
logger.info('--bindir=PATH Path to cores directory, default:datadir/bin.') |
|
|
|
logger.info('--bindir=PATH Path to cores directory, default:datadir/bin.') |
|
|
|
logger.info('--mainnet Run in mainnet mode.') |
|
|
|
logger.info('--mainnet Run in mainnet mode.') |
|
|
|
logger.info('--testnet Run in testnet mode.') |
|
|
|
logger.info('--testnet Run in testnet mode.') |
|
|
|
logger.info('--regtest Run in regtest 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' |
|
|
|
logger.info('--particl_mnemonic= Recovery phrase to use for the Particl wallet, default is randomly generated,\n' |
|
|
|
+ ' "none" to set autogenerate account mode.') |
|
|
|
+ ' "auto" to create a wallet automatically - No mnemonic.' |
|
|
|
|
|
|
|
+ ' "none" to disable wallet initialisation.') |
|
|
|
logger.info('--withcoin= Prepare system to run daemon for coin.') |
|
|
|
logger.info('--withcoin= Prepare system to run daemon for coin.') |
|
|
|
logger.info('--withoutcoin= Do not 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('--addcoin= Add coin to existing setup.') |
|
|
@ -733,6 +743,7 @@ def printHelp(): |
|
|
|
logger.info('--disabletor Setup Basicswap instance to not use TOR.') |
|
|
|
logger.info('--disabletor Setup Basicswap instance to not use TOR.') |
|
|
|
logger.info('--usebtcfastsync Initialise the BTC chain with a snapshot from btcpayserver FastSync.\n' |
|
|
|
logger.info('--usebtcfastsync Initialise the BTC chain with a snapshot from btcpayserver FastSync.\n' |
|
|
|
+ ' See https://github.com/btcpayserver/btcpayserver-docker/blob/master/contrib/FastSync/README.md') |
|
|
|
+ ' See https://github.com/btcpayserver/btcpayserver-docker/blob/master/contrib/FastSync/README.md') |
|
|
|
|
|
|
|
logger.info('--initwalletsonly Setup coin wallets only.') |
|
|
|
|
|
|
|
|
|
|
|
logger.info('\n' + 'Known coins: %s', ', '.join(known_coins.keys())) |
|
|
|
logger.info('\n' + 'Known coins: %s', ', '.join(known_coins.keys())) |
|
|
|
|
|
|
|
|
|
|
@ -764,7 +775,6 @@ def initialise_wallets(particl_wallet_mnemonic, with_coins, data_dir, settings, |
|
|
|
for coin_name in start_daemons: |
|
|
|
for coin_name in start_daemons: |
|
|
|
coin_settings = settings['chainclients'][coin_name] |
|
|
|
coin_settings = settings['chainclients'][coin_name] |
|
|
|
c = swap_client.getCoinIdFromName(coin_name) |
|
|
|
c = swap_client.getCoinIdFromName(coin_name) |
|
|
|
swap_client.setCoinConnectParams(c) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if c == Coins.XMR: |
|
|
|
if c == Coins.XMR: |
|
|
|
if coin_settings['manage_wallet_daemon']: |
|
|
|
if coin_settings['manage_wallet_daemon']: |
|
|
@ -804,7 +814,18 @@ def initialise_wallets(particl_wallet_mnemonic, with_coins, data_dir, settings, |
|
|
|
finally: |
|
|
|
finally: |
|
|
|
for d in daemons: |
|
|
|
for d in daemons: |
|
|
|
finalise_daemon(d) |
|
|
|
finalise_daemon(d) |
|
|
|
return particl_wallet_mnemonic |
|
|
|
|
|
|
|
|
|
|
|
if particl_wallet_mnemonic is not None: |
|
|
|
|
|
|
|
if particl_wallet_mnemonic: |
|
|
|
|
|
|
|
# Print directly to stdout for tests |
|
|
|
|
|
|
|
print('IMPORTANT - Save your particl wallet recovery phrase:\n{}\n'.format(particl_wallet_mnemonic)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_config(config_path): |
|
|
|
|
|
|
|
if not os.path.exists(config_path): |
|
|
|
|
|
|
|
exitWithError('{} does not exist'.format(config_path)) |
|
|
|
|
|
|
|
with open(config_path) as fs: |
|
|
|
|
|
|
|
return json.load(fs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
def main(): |
|
|
@ -814,19 +835,20 @@ def main(): |
|
|
|
port_offset = None |
|
|
|
port_offset = None |
|
|
|
chain = 'mainnet' |
|
|
|
chain = 'mainnet' |
|
|
|
particl_wallet_mnemonic = None |
|
|
|
particl_wallet_mnemonic = None |
|
|
|
prepare_bin_only = False |
|
|
|
|
|
|
|
no_cores = False |
|
|
|
|
|
|
|
use_containers = False |
|
|
|
|
|
|
|
with_coins = {'particl', } |
|
|
|
with_coins = {'particl', } |
|
|
|
add_coin = '' |
|
|
|
add_coin = '' |
|
|
|
disable_coin = '' |
|
|
|
disable_coin = '' |
|
|
|
htmlhost = '127.0.0.1' |
|
|
|
htmlhost = '127.0.0.1' |
|
|
|
xmr_restore_height = DEFAULT_XMR_RESTORE_HEIGHT |
|
|
|
xmr_restore_height = DEFAULT_XMR_RESTORE_HEIGHT |
|
|
|
|
|
|
|
prepare_bin_only = False |
|
|
|
|
|
|
|
no_cores = False |
|
|
|
|
|
|
|
use_containers = False |
|
|
|
enable_tor = False |
|
|
|
enable_tor = False |
|
|
|
disable_tor = False |
|
|
|
disable_tor = False |
|
|
|
tor_control_password = None |
|
|
|
tor_control_password = None |
|
|
|
use_btc_fastsync = False |
|
|
|
use_btc_fastsync = False |
|
|
|
extract_core_overwrite = True |
|
|
|
extract_core_overwrite = True |
|
|
|
|
|
|
|
initwalletsonly = False |
|
|
|
|
|
|
|
|
|
|
|
for v in sys.argv[1:]: |
|
|
|
for v in sys.argv[1:]: |
|
|
|
if len(v) < 2 or v[0] != '-': |
|
|
|
if len(v) < 2 or v[0] != '-': |
|
|
@ -877,6 +899,9 @@ def main(): |
|
|
|
if name == 'usebtcfastsync': |
|
|
|
if name == 'usebtcfastsync': |
|
|
|
use_btc_fastsync = True |
|
|
|
use_btc_fastsync = True |
|
|
|
continue |
|
|
|
continue |
|
|
|
|
|
|
|
if name == 'initwalletsonly': |
|
|
|
|
|
|
|
initwalletsonly = True |
|
|
|
|
|
|
|
continue |
|
|
|
if len(s) == 2: |
|
|
|
if len(s) == 2: |
|
|
|
if name == 'datadir': |
|
|
|
if name == 'datadir': |
|
|
|
data_dir = os.path.expanduser(s[1].strip('"')) |
|
|
|
data_dir = os.path.expanduser(s[1].strip('"')) |
|
|
@ -933,7 +958,7 @@ def main(): |
|
|
|
testOnionLink() |
|
|
|
testOnionLink() |
|
|
|
|
|
|
|
|
|
|
|
if data_dir is None: |
|
|
|
if data_dir is None: |
|
|
|
data_dir = os.path.join(os.path.expanduser(cfg.DEFAULT_DATADIR)) |
|
|
|
data_dir = os.path.join(os.path.expanduser(cfg.BASICSWAP_DATADIR)) |
|
|
|
if bin_dir is None: |
|
|
|
if bin_dir is None: |
|
|
|
bin_dir = os.path.join(data_dir, 'bin') |
|
|
|
bin_dir = os.path.join(data_dir, 'bin') |
|
|
|
|
|
|
|
|
|
|
@ -1037,13 +1062,20 @@ def main(): |
|
|
|
|
|
|
|
|
|
|
|
chainclients['monero']['walletsdir'] = os.getenv('XMR_WALLETS_DIR', chainclients['monero']['datadir']) |
|
|
|
chainclients['monero']['walletsdir'] = os.getenv('XMR_WALLETS_DIR', chainclients['monero']['datadir']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if initwalletsonly: |
|
|
|
|
|
|
|
logger.info('Initialising wallets') |
|
|
|
|
|
|
|
settings = load_config(config_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init_coins = settings['chainclients'].keys() |
|
|
|
|
|
|
|
logger.info('Active coins: %s', ', '.join(init_coins)) |
|
|
|
|
|
|
|
initialise_wallets(particl_wallet_mnemonic, init_coins, data_dir, settings, chain, use_tor_proxy) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print('Done.') |
|
|
|
|
|
|
|
return 0 |
|
|
|
|
|
|
|
|
|
|
|
if enable_tor: |
|
|
|
if enable_tor: |
|
|
|
logger.info('Enabling TOR') |
|
|
|
logger.info('Enabling TOR') |
|
|
|
|
|
|
|
settings = load_config(config_path) |
|
|
|
if not os.path.exists(config_path): |
|
|
|
|
|
|
|
exitWithError('{} does not exist'.format(config_path)) |
|
|
|
|
|
|
|
with open(config_path) as fs: |
|
|
|
|
|
|
|
settings = json.load(fs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tor_control_password = settings.get('tor_control_password', None) |
|
|
|
tor_control_password = settings.get('tor_control_password', None) |
|
|
|
if tor_control_password is None: |
|
|
|
if tor_control_password is None: |
|
|
@ -1063,12 +1095,7 @@ def main(): |
|
|
|
|
|
|
|
|
|
|
|
if disable_tor: |
|
|
|
if disable_tor: |
|
|
|
logger.info('Disabling TOR') |
|
|
|
logger.info('Disabling TOR') |
|
|
|
|
|
|
|
settings = load_config(config_path) |
|
|
|
if not os.path.exists(config_path): |
|
|
|
|
|
|
|
exitWithError('{} does not exist'.format(config_path)) |
|
|
|
|
|
|
|
with open(config_path) as fs: |
|
|
|
|
|
|
|
settings = json.load(fs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
settings['use_tor'] = False |
|
|
|
settings['use_tor'] = False |
|
|
|
for coin in settings['chainclients']: |
|
|
|
for coin in settings['chainclients']: |
|
|
|
modify_tor_config(settings, coin, tor_control_password=None, enable=False) |
|
|
|
modify_tor_config(settings, coin, tor_control_password=None, enable=False) |
|
|
@ -1081,10 +1108,7 @@ def main(): |
|
|
|
|
|
|
|
|
|
|
|
if disable_coin != '': |
|
|
|
if disable_coin != '': |
|
|
|
logger.info('Disabling coin: %s', disable_coin) |
|
|
|
logger.info('Disabling coin: %s', disable_coin) |
|
|
|
if not os.path.exists(config_path): |
|
|
|
settings = load_config(config_path) |
|
|
|
exitWithError('{} does not exist'.format(config_path)) |
|
|
|
|
|
|
|
with open(config_path) as fs: |
|
|
|
|
|
|
|
settings = json.load(fs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if disable_coin not in settings['chainclients']: |
|
|
|
if disable_coin not in settings['chainclients']: |
|
|
|
exitWithError('{} has not been prepared'.format(disable_coin)) |
|
|
|
exitWithError('{} has not been prepared'.format(disable_coin)) |
|
|
@ -1107,10 +1131,7 @@ def main(): |
|
|
|
|
|
|
|
|
|
|
|
if add_coin != '': |
|
|
|
if add_coin != '': |
|
|
|
logger.info('Adding coin: %s', add_coin) |
|
|
|
logger.info('Adding coin: %s', add_coin) |
|
|
|
if not os.path.exists(config_path): |
|
|
|
settings = load_config(config_path) |
|
|
|
exitWithError('{} does not exist'.format(config_path)) |
|
|
|
|
|
|
|
with open(config_path) as fs: |
|
|
|
|
|
|
|
settings = json.load(fs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if add_coin in settings['chainclients']: |
|
|
|
if add_coin in settings['chainclients']: |
|
|
|
coin_settings = settings['chainclients'][add_coin] |
|
|
|
coin_settings = settings['chainclients'][add_coin] |
|
|
@ -1132,6 +1153,8 @@ 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 particl_wallet_mnemonic not in ('none', 'auto'): |
|
|
|
initialise_wallets(None, [add_coin, ], data_dir, settings, chain, use_tor_proxy) |
|
|
|
initialise_wallets(None, [add_coin, ], data_dir, settings, chain, use_tor_proxy) |
|
|
|
|
|
|
|
|
|
|
|
with open(config_path, 'w') as fp: |
|
|
|
with open(config_path, 'w') as fp: |
|
|
@ -1153,7 +1176,7 @@ def main(): |
|
|
|
|
|
|
|
|
|
|
|
settings = { |
|
|
|
settings = { |
|
|
|
'debug': True, |
|
|
|
'debug': True, |
|
|
|
'zmqhost': 'tcp://127.0.0.1', |
|
|
|
'zmqhost': f'tcp://{PART_RPC_HOST}', |
|
|
|
'zmqport': PART_ZMQ_PORT + port_offset, |
|
|
|
'zmqport': PART_ZMQ_PORT + port_offset, |
|
|
|
'htmlhost': htmlhost, |
|
|
|
'htmlhost': htmlhost, |
|
|
|
'htmlport': UI_HTML_PORT + port_offset, |
|
|
|
'htmlport': UI_HTML_PORT + port_offset, |
|
|
@ -1185,14 +1208,11 @@ def main(): |
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
if particl_wallet_mnemonic == 'none': |
|
|
|
if particl_wallet_mnemonic in ('none', 'auto'): |
|
|
|
logger.info('Done.') |
|
|
|
logger.info('Done.') |
|
|
|
return 0 |
|
|
|
return 0 |
|
|
|
|
|
|
|
|
|
|
|
particl_wallet_mnemonic = initialise_wallets(particl_wallet_mnemonic, with_coins, data_dir, settings, chain, use_tor_proxy) |
|
|
|
initialise_wallets(particl_wallet_mnemonic, with_coins, data_dir, settings, chain, use_tor_proxy) |
|
|
|
if particl_wallet_mnemonic: |
|
|
|
|
|
|
|
# Print directly to stdout for tests |
|
|
|
|
|
|
|
print('IMPORTANT - Save your particl wallet recovery phrase:\n{}\n'.format(particl_wallet_mnemonic)) |
|
|
|
|
|
|
|
print('Done.') |
|
|
|
print('Done.') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|