mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 10:28:10 +01:00
basicswap-prepare tries to initialise coin wallets from Particl mnemonic
Bitcoin 0.20: 'Cannot set a new HD seed while still in Initial Block Download.' Removed in 0.21
This commit is contained in:
@@ -16,6 +16,7 @@ import json
|
||||
import mmap
|
||||
import stat
|
||||
import gnupg
|
||||
import signal
|
||||
import hashlib
|
||||
import tarfile
|
||||
import zipfile
|
||||
@@ -24,13 +25,15 @@ import platform
|
||||
import urllib.parse
|
||||
from urllib.request import urlretrieve
|
||||
|
||||
|
||||
import basicswap.config as cfg
|
||||
from basicswap.rpc import (
|
||||
callrpc_cli,
|
||||
waitForRPC,
|
||||
)
|
||||
from bin.basicswap_run import startDaemon
|
||||
from basicswap.basicswap import BasicSwap
|
||||
from basicswap.chainparams import Coins
|
||||
from bin.basicswap_run import startDaemon, startXmrWalletDaemon
|
||||
|
||||
|
||||
if platform.system() == 'Darwin':
|
||||
BIN_ARCH = 'osx64.tar.gz'
|
||||
@@ -40,7 +43,7 @@ else:
|
||||
BIN_ARCH = 'x86_64-linux-gnu.tar.gz'
|
||||
|
||||
known_coins = {
|
||||
'particl': '0.19.1.1',
|
||||
'particl': '0.19.1.2',
|
||||
'litecoin': '0.18.1',
|
||||
'bitcoin': '0.20.1',
|
||||
'namecoin': '0.18.0',
|
||||
@@ -52,6 +55,13 @@ logger.level = logging.DEBUG
|
||||
if not len(logger.handlers):
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
XMR_RPC_HOST = os.getenv('XMR_RPC_HOST', 'localhost')
|
||||
BASE_XMR_RPC_PORT = os.getenv('BASE_XMR_RPC_PORT', 29798)
|
||||
BASE_XMR_ZMQ_PORT = os.getenv('BASE_XMR_ZMQ_PORT', 29898)
|
||||
BASE_XMR_WALLET_PORT = os.getenv('BASE_XMR_WALLET_PORT', 29998)
|
||||
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')
|
||||
|
||||
|
||||
def make_reporthook():
|
||||
read = 0 # Number of bytes read so far
|
||||
@@ -95,8 +105,6 @@ def extractCore(coin, version, settings, bin_dir, release_path):
|
||||
fout.write(fi.read())
|
||||
fi.close()
|
||||
os.chmod(out_path, stat.S_IRWXU | stat.S_IXGRP | stat.S_IXOTH)
|
||||
|
||||
print('member', member)
|
||||
return
|
||||
|
||||
bins = [coin + 'd', coin + '-cli', coin + '-tx']
|
||||
@@ -257,10 +265,40 @@ def prepareDataDir(coin, settings, data_dir, chain, particl_mnemonic):
|
||||
if not os.path.exists(data_dir):
|
||||
os.makedirs(data_dir)
|
||||
|
||||
if coin == 'monero':
|
||||
core_conf_path = os.path.join(data_dir, coin + 'd.conf')
|
||||
if os.path.exists(core_conf_path):
|
||||
exitWithError('{} exists'.format(core_conf_path))
|
||||
with open(core_conf_path, 'w') as fp:
|
||||
if chain == 'regtest':
|
||||
fp.write('regtest=1\n')
|
||||
fp.write('keep-fakechain=1\n')
|
||||
fp.write('fixed-difficulty=1\n')
|
||||
elif chain == 'testnet':
|
||||
fp.write('testnet=1\n')
|
||||
fp.write('data-dir={}\n'.format(data_dir))
|
||||
fp.write('rpc-bind-port={}\n'.format(core_settings['rpcport']))
|
||||
fp.write('rpc-bind-ip=127.0.0.1\n')
|
||||
fp.write('zmq-rpc-bind-port={}\n'.format(core_settings['zmqport']))
|
||||
fp.write('zmq-rpc-bind-ip=127.0.0.1\n')
|
||||
|
||||
#fp.write('zmq-rpc-bind-port={}\n'.format(core_settings['zmqport']))
|
||||
#fp.write('zmq-rpc-bind-ip=127.0.0.1\n')
|
||||
wallet_conf_path = os.path.join(data_dir, coin + '_wallet.conf')
|
||||
if os.path.exists(wallet_conf_path):
|
||||
exitWithError('{} exists'.format(wallet_conf_path))
|
||||
with open(wallet_conf_path, 'w') as fp:
|
||||
fp.write('daemon-address={}:{}\n'.format(core_settings['rpchost'], core_settings['rpcport']))
|
||||
fp.write('no-dns=1\n')
|
||||
fp.write('rpc-bind-port={}\n'.format(core_settings['walletrpcport']))
|
||||
fp.write('wallet-dir={}\n'.format(os.path.join(data_dir, 'wallets')))
|
||||
fp.write('log-file={}\n'.format(os.path.join(data_dir, 'wallet.log')))
|
||||
fp.write('shared-ringdb-dir={}\n'.format(os.path.join(data_dir, 'shared-ringdb')))
|
||||
fp.write('rpc-login={}:{}\n'.format(core_settings['walletrpcuser'], core_settings['walletrpcpassword']))
|
||||
return
|
||||
core_conf_path = os.path.join(data_dir, coin + '.conf')
|
||||
if os.path.exists(core_conf_path):
|
||||
exitWithError('{} exists'.format(core_conf_path))
|
||||
|
||||
with open(core_conf_path, 'w') as fp:
|
||||
if chain != 'mainnet':
|
||||
fp.write(chain + '=1\n')
|
||||
@@ -490,11 +528,14 @@ def main():
|
||||
'monero': {
|
||||
'connection_type': 'rpc' if 'monero' in with_coins else 'none',
|
||||
'manage_daemon': True if 'monero' in with_coins else False,
|
||||
'rpcport': 29798 + port_offset,
|
||||
'walletrpcport': 29799 + port_offset,
|
||||
#'walletrpcuser': 'test' + str(node_id),
|
||||
#'walletrpcpassword': 'test_pass' + str(node_id),
|
||||
'walletfile': 'basicswap',
|
||||
'manage_wallet_daemon': True if 'monero' in with_coins else False,
|
||||
'rpcport': BASE_XMR_RPC_PORT + port_offset,
|
||||
'zmqport': BASE_XMR_ZMQ_PORT + port_offset,
|
||||
'walletrpcport': BASE_XMR_WALLET_PORT + port_offset,
|
||||
'rpchost': XMR_RPC_HOST,
|
||||
'walletrpcuser': XMR_WALLET_RPC_USER,
|
||||
'walletrpcpassword': XMR_WALLET_RPC_PWD,
|
||||
'walletfile': 'swap_wallet',
|
||||
'datadir': os.path.join(data_dir, 'monero'),
|
||||
'bindir': os.path.join(bin_dir, 'monero'),
|
||||
}
|
||||
@@ -597,26 +638,57 @@ def main():
|
||||
|
||||
particl_settings = settings['chainclients']['particl']
|
||||
partRpc = make_rpc_func(particl_settings['bindir'], particl_settings['datadir'], chain)
|
||||
d = startDaemon(particl_settings['datadir'], particl_settings['bindir'], cfg.PARTICLD, ['-noconnect', '-nofindpeers', '-nostaking', '-nodnsseed', '-nolisten'])
|
||||
|
||||
daemons = []
|
||||
daemons.append(startDaemon(particl_settings['datadir'], particl_settings['bindir'], cfg.PARTICLD, ['-noconnect', '-nofindpeers', '-nostaking', '-nodnsseed', '-nolisten']))
|
||||
try:
|
||||
waitForRPC(partRpc)
|
||||
|
||||
if particl_wallet_mnemonic is None:
|
||||
particl_wallet_mnemonic = partRpc('mnemonic new')['mnemonic']
|
||||
partRpc('extkeyimportmaster "{}"'.format(particl_wallet_mnemonic))
|
||||
|
||||
# Initialise wallets
|
||||
with open(os.path.join(data_dir, 'basicswap.log'), 'a') as fp:
|
||||
swap_client = BasicSwap(fp, data_dir, settings, chain)
|
||||
|
||||
swap_client.setCoinConnectParams(Coins.PART)
|
||||
swap_client.setDaemonPID(Coins.PART, daemons[-1].pid)
|
||||
swap_client.setCoinRunParams(Coins.PART)
|
||||
swap_client.createCoinInterface(Coins.PART)
|
||||
|
||||
for coin_name in with_coins:
|
||||
coin_settings = settings['chainclients'][coin_name]
|
||||
c = swap_client.getCoinIdFromName(coin_name)
|
||||
if c == Coins.PART:
|
||||
continue
|
||||
|
||||
swap_client.setCoinConnectParams(c)
|
||||
|
||||
if c == Coins.XMR:
|
||||
if not coin_settings['manage_wallet_daemon']:
|
||||
continue
|
||||
daemons.append(startXmrWalletDaemon(coin_settings['datadir'], coin_settings['bindir'], 'monero-wallet-rpc'))
|
||||
else:
|
||||
if not coin_settings['manage_daemon']:
|
||||
continue
|
||||
filename = coin_name + 'd' + ('.exe' if os.name == 'nt' else '')
|
||||
daemons.append(startDaemon(coin_settings['datadir'], coin_settings['bindir'], filename, ['-noconnect', '-nodnsseed', '-nolisten']))
|
||||
swap_client.setDaemonPID(c, daemons[-1].pid)
|
||||
swap_client.setCoinRunParams(c)
|
||||
swap_client.createCoinInterface(c)
|
||||
swap_client.waitForDaemonRPC(c)
|
||||
swap_client.initialiseWallet(c)
|
||||
finally:
|
||||
logger.info('Terminating {}'.format(d.pid))
|
||||
d.terminate()
|
||||
d.wait(timeout=120)
|
||||
if d.stdout:
|
||||
d.stdout.close()
|
||||
if d.stderr:
|
||||
d.stderr.close()
|
||||
if d.stdin:
|
||||
d.stdin.close()
|
||||
for d in daemons:
|
||||
logging.info('Interrupting {}'.format(d.pid))
|
||||
d.send_signal(signal.SIGINT)
|
||||
d.wait(timeout=120)
|
||||
for fp in (d.stdout, d.stderr, d.stdin):
|
||||
if fp:
|
||||
fp.close()
|
||||
|
||||
logger.info('IMPORTANT - Save your particl wallet recovery phrase:\n{}\n'.format(particl_wallet_mnemonic))
|
||||
|
||||
logger.info('Done.')
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import logging
|
||||
import traceback
|
||||
import subprocess
|
||||
|
||||
|
||||
import basicswap.config as cfg
|
||||
from basicswap import __version__
|
||||
from basicswap.basicswap import BasicSwap
|
||||
@@ -31,7 +30,6 @@ logger.level = logging.DEBUG
|
||||
if not len(logger.handlers):
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
ALLOW_CORS = False
|
||||
swap_client = None
|
||||
|
||||
|
||||
@@ -50,6 +48,29 @@ def startDaemon(node_dir, bin_dir, daemon_bin, opts=[]):
|
||||
return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
|
||||
def startXmrDaemon(node_dir, bin_dir, daemon_bin, opts=[]):
|
||||
daemon_bin = os.path.expanduser(os.path.join(bin_dir, daemon_bin))
|
||||
|
||||
args = [daemon_bin, '--config-file=' + os.path.join(os.path.expanduser(node_dir), 'monerod.conf')] + opts
|
||||
logging.info('Starting node {} --data-dir={}'.format(daemon_bin, node_dir))
|
||||
|
||||
return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
|
||||
def startXmrWalletDaemon(node_dir, bin_dir, wallet_bin, opts=[]):
|
||||
daemon_bin = os.path.expanduser(os.path.join(bin_dir, wallet_bin))
|
||||
|
||||
data_dir = os.path.expanduser(node_dir)
|
||||
args = [daemon_bin, '--config-file=' + os.path.join(os.path.expanduser(node_dir), 'monero_wallet.conf')] + opts
|
||||
|
||||
args += opts
|
||||
logging.info('Starting wallet daemon {} --wallet-dir={}'.format(daemon_bin, node_dir))
|
||||
|
||||
#return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=data_dir)
|
||||
wallet_stdout = open(os.path.join(data_dir, 'wallet_stdout.log'), 'w')
|
||||
wallet_stderr = open(os.path.join(data_dir, 'wallet_stderr.log'), 'w')
|
||||
return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=wallet_stdout, stderr=wallet_stderr, cwd=data_dir)
|
||||
|
||||
def runClient(fp, data_dir, chain):
|
||||
global swap_client
|
||||
settings_path = os.path.join(data_dir, cfg.CONFIG_FILENAME)
|
||||
@@ -79,6 +100,20 @@ def runClient(fp, data_dir, chain):
|
||||
try:
|
||||
# Try start daemons
|
||||
for c, v in settings['chainclients'].items():
|
||||
if c == 'monero':
|
||||
if v['manage_daemon'] is True:
|
||||
logger.info('Starting {} daemon'.format(c.capitalize()))
|
||||
daemons.append(startXmrDaemon(v['datadir'], v['bindir'], 'monerod'))
|
||||
pid = daemons[-1].pid
|
||||
logger.info('Started {} {}'.format('monerod', pid))
|
||||
|
||||
if v['manage_wallet_daemon'] is True:
|
||||
logger.info('Starting {} wallet daemon'.format(c.capitalize()))
|
||||
daemons.append(startXmrWalletDaemon(v['datadir'], v['bindir'], 'monero-wallet-rpc'))
|
||||
pid = daemons[-1].pid
|
||||
logger.info('Started {} {}'.format('monero-wallet-rpc', pid))
|
||||
|
||||
continue
|
||||
if v['manage_daemon'] is True:
|
||||
logger.info('Starting {} daemon'.format(c.capitalize()))
|
||||
|
||||
@@ -99,7 +134,7 @@ def runClient(fp, data_dir, chain):
|
||||
|
||||
if 'htmlhost' in settings:
|
||||
swap_client.log.info('Starting server at %s:%d.' % (settings['htmlhost'], settings['htmlport']))
|
||||
allow_cors = settings['allowcors'] if 'allowcors' in settings else ALLOW_CORS
|
||||
allow_cors = settings['allowcors'] if 'allowcors' in settings else cfg.DEFAULT_ALLOW_CORS
|
||||
tS1 = HttpThread(fp, settings['htmlhost'], settings['htmlport'], allow_cors, swap_client)
|
||||
threads.append(tS1)
|
||||
tS1.start()
|
||||
@@ -118,8 +153,7 @@ def runClient(fp, data_dir, chain):
|
||||
|
||||
closed_pids = []
|
||||
for d in daemons:
|
||||
int_pid = d.pid
|
||||
logging.info('Interrupting {}'.format(int_pid))
|
||||
logging.info('Interrupting {}'.format(d.pid))
|
||||
try:
|
||||
d.send_signal(signal.SIGINT)
|
||||
except Exception as e:
|
||||
@@ -127,13 +161,10 @@ def runClient(fp, data_dir, chain):
|
||||
for d in daemons:
|
||||
try:
|
||||
d.wait(timeout=120)
|
||||
if d.stdout:
|
||||
d.stdout.close()
|
||||
if d.stderr:
|
||||
d.stderr.close()
|
||||
if d.stdin:
|
||||
d.stdin.close()
|
||||
closed_pids.append(int_pid)
|
||||
for fp in (d.stdout, d.stderr, d.stdin):
|
||||
if fp:
|
||||
fp.close()
|
||||
closed_pids.append(d.pid)
|
||||
except Exception as ex:
|
||||
logger.error('Error: {}'.format(ex))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user