Prepare script can add coins to existing configurations.

2024-05-20_merge
tecnovert 5 years ago
parent dd692fe5ef
commit 222fbb492f
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 196
      bin/basicswap_prepare.py

@ -32,6 +32,13 @@ from bin.basicswap_run import startDaemon
BIN_ARCH = 'x86_64-linux-gnu.tar.gz' BIN_ARCH = 'x86_64-linux-gnu.tar.gz'
known_coins = {
'particl': '0.18.1.0',
'litecoin': '0.17.1',
'bitcoin': '0.18.0',
'namecoin': '0.18.0',
}
logger = logging.getLogger() logger = logging.getLogger()
logger.level = logging.DEBUG logger.level = logging.DEBUG
if not len(logger.handlers): if not len(logger.handlers):
@ -87,25 +94,27 @@ def prepareCore(coin, version, settings, data_dir):
release_url = 'https://github.com/particl/particl-core/releases/download/v{}/{}'.format(version, release_filename) release_url = 'https://github.com/particl/particl-core/releases/download/v{}/{}'.format(version, release_filename)
assert_filename = '{}-{}-{}-build.assert'.format(coin, os_name, version) assert_filename = '{}-{}-{}-build.assert'.format(coin, os_name, version)
assert_url = 'https://raw.githubusercontent.com/particl/gitian.sigs/master/%s-%s/%s/%s' % (version, os_name, signing_key_name, assert_filename) assert_url = 'https://raw.githubusercontent.com/particl/gitian.sigs/master/%s-%s/%s/%s' % (version, os_name, signing_key_name, assert_filename)
assert_sig_filename = assert_filename + '.sig'
assert_sig_url = assert_url + '.sig'
elif coin == 'litecoin': elif coin == 'litecoin':
signing_key_name = 'thrasher' signing_key_name = 'thrasher'
release_url = 'https://download.litecoin.org/litecoin-{}/{}/{}'.format(version, os_name, release_filename) release_url = 'https://download.litecoin.org/litecoin-{}/{}/{}'.format(version, os_name, release_filename)
assert_filename = '{}-{}-{}-build.assert'.format(coin, os_name, version.rsplit('.', 1)[0]) assert_filename = '{}-{}-{}-build.assert'.format(coin, os_name, version.rsplit('.', 1)[0])
assert_url = 'https://raw.githubusercontent.com/litecoin-project/gitian.sigs.ltc/master/%s-%s/%s/%s' % (version, os_name, signing_key_name, assert_filename) assert_url = 'https://raw.githubusercontent.com/litecoin-project/gitian.sigs.ltc/master/%s-%s/%s/%s' % (version, os_name, signing_key_name, assert_filename)
assert_sig_filename = assert_filename + '.sig'
assert_sig_url = assert_url + '.sig'
elif coin == 'bitcoin': elif coin == 'bitcoin':
signing_key_name = 'laanwj' signing_key_name = 'laanwj'
release_url = 'https://bitcoincore.org/bin/bitcoin-core-{}/{}'.format(version, release_filename) release_url = 'https://bitcoincore.org/bin/bitcoin-core-{}/{}'.format(version, release_filename)
assert_filename = '{}-{}-{}-build.assert'.format(coin, os_name, version.rsplit('.', 1)[0]) assert_filename = '{}-{}-{}-build.assert'.format(coin, os_name, version.rsplit('.', 1)[0])
assert_url = 'https://raw.githubusercontent.com/bitcoin-core/gitian.sigs/master/%s-%s/%s/%s' % (version, os_name, signing_key_name, assert_filename) assert_url = 'https://raw.githubusercontent.com/bitcoin-core/gitian.sigs/master/%s-%s/%s/%s' % (version, os_name, signing_key_name, assert_filename)
assert_sig_filename = assert_filename + '.sig' elif coin == 'namecoin':
assert_sig_url = assert_url + '.sig' signing_key_name = 'JeremyRand'
release_url = 'https://beta.namecoin.org/files/namecoin-core/namecoin-core-{}/{}'.format(version, release_filename)
assert_filename = '{}-{}-{}-build.assert'.format(coin, os_name, version.rsplit('.', 1)[0])
assert_url = 'https://raw.githubusercontent.com/namecoin/gitian.sigs/master/%s-%s/%s/%s' % (version, os_name, signing_key_name, assert_filename)
else: else:
raise ValueError('Unknown coin') raise ValueError('Unknown coin')
assert_sig_filename = assert_filename + '.sig'
assert_sig_url = assert_url + '.sig'
release_path = os.path.join(bin_dir, release_filename) release_path = os.path.join(bin_dir, release_filename)
if not os.path.exists(release_path): if not os.path.exists(release_path):
downloadFile(release_url, release_path) downloadFile(release_url, release_path)
@ -155,6 +164,44 @@ def prepareCore(coin, version, settings, data_dir):
os.chmod(out_path, stat.S_IRWXU) os.chmod(out_path, stat.S_IRWXU)
def prepareDataDir(coin, settings, data_dir, chain):
core_settings = settings['chainclients'][coin]
data_dir = core_settings['datadir']
if not os.path.exists(data_dir):
os.makedirs(data_dir)
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')
if chain == 'testnet':
fp.write('[test]\n\n')
else:
logger.warning('Unknown chain %s', chain)
fp.write('rpcport={}\n'.format(core_settings['rpcport']))
fp.write('printtoconsole=0\n')
fp.write('daemon=0\n')
if coin == 'particl':
fp.write('debugexclude=libevent\n')
fp.write('zmqpubsmsg=tcp://127.0.0.1:{}\n'.format(settings['zmqport']))
fp.write('spentindex=1')
fp.write('txindex=1')
elif coin == 'litecoin':
fp.write('prune=1000\n')
elif coin == 'bitcoin':
fp.write('prune=1000\n')
elif coin == 'namecoin':
fp.write('prune=1000\n')
else:
logger.warning('Unknown coin %s', coin)
def extractCore(coin, version, settings): def extractCore(coin, version, settings):
logger.info('extractCore %s v%s', coin, version) logger.info('extractCore %s v%s', coin, version)
@ -175,6 +222,8 @@ def printHelp():
logger.info('--particl_mnemonic= Recovery phrase to use for the Particl wallet, default is randomly generated.') logger.info('--particl_mnemonic= Recovery phrase to use for the Particl wallet, default is randomly generated.')
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('\n' + 'Known coins: %s', ', '.join(known_coins.keys()))
def make_rpc_func(bin_dir, data_dir, chain): def make_rpc_func(bin_dir, data_dir, chain):
@ -201,17 +250,21 @@ def waitForRPC(rpc_func, wallet=None):
raise ValueError('waitForRPC failed') raise ValueError('waitForRPC failed')
def exitWithError(error_msg):
sys.stderr.write('Error: {}, exiting.\n'.format(error_msg))
exit(1)
def main(): def main():
data_dir = None data_dir = None
chain = 'mainnet' chain = 'mainnet'
particl_wallet_mnemonic = None particl_wallet_mnemonic = None
known_coins = {'particl', 'litecoin', 'bitcoin'}
with_coins = {'particl', 'litecoin'} with_coins = {'particl', 'litecoin'}
add_coin = ''
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] != '-':
logger.warning('Unknown argument %s', v) exitWithError('Unknown argument {}'.format(v))
continue
s = v.split('=') s = v.split('=')
name = s[0].strip() name = s[0].strip()
@ -243,37 +296,35 @@ def main():
particl_wallet_mnemonic = s[1] particl_wallet_mnemonic = s[1]
continue continue
if name == 'withcoin': if name == 'withcoin':
if s[1] not in known_coins:
exitWithError('Unknown coin {}'.format(s[1]))
with_coins.add(s[1]) with_coins.add(s[1])
continue
if name == 'withoutcoin': if name == 'withoutcoin':
if s[1] not in known_coins:
exitWithError('Unknown coin {}'.format(s[1]))
with_coins.discard(s[1]) with_coins.discard(s[1])
continue
if name == 'addcoin':
if s[1] not in known_coins:
exitWithError('Unknown coin {}'.format(s[1]))
add_coin = s[1]
continue
logger.warning('Unknown argument %s', v) exitWithError('Unknown argument {}'.format(v))
if data_dir is None: if data_dir is None:
default_datadir = '~/.basicswap' default_datadir = '~/.basicswap'
data_dir = os.path.join(os.path.expanduser(default_datadir)) data_dir = os.path.join(os.path.expanduser(default_datadir))
logger.info('Using datadir: %s', data_dir) logger.info('Using datadir: %s', data_dir)
logger.info('Chain: %s', chain) logger.info('Chain: %s', chain)
logger.info('With coins: %s', ', '.join(with_coins)) port_offset = 300 if chain == 'testnet' else 0
if not os.path.exists(data_dir): if not os.path.exists(data_dir):
os.makedirs(data_dir) os.makedirs(data_dir)
config_path = os.path.join(data_dir, 'basicswap.json') config_path = os.path.join(data_dir, 'basicswap.json')
if os.path.exists(config_path):
sys.stderr.write('Error: {} exists, exiting.\n'.format(config_path))
exit(1)
port_offset = 300 if chain == 'testnet' else 0 chainclients = {
settings = {
'debug': True,
'zmqhost': 'tcp://127.0.0.1',
'zmqport': 20792 + port_offset,
'htmlhost': 'localhost',
'htmlport': 12700 + port_offset,
'network_key': '7sW2UEcHXvuqEjkpE5mD584zRaQYs6WXYohue4jLFZPTvMSxwvgs',
'network_pubkey': '035758c4a22d7dd59165db02a56156e790224361eb3191f02197addcb3bde903d2',
'chainclients': {
'particl': { 'particl': {
'connection_type': 'rpc', 'connection_type': 'rpc',
'manage_daemon': True, 'manage_daemon': True,
@ -299,61 +350,66 @@ def main():
'datadir': os.path.join(data_dir, 'bitcoin'), 'datadir': os.path.join(data_dir, 'bitcoin'),
'bindir': os.path.join(data_dir, 'bins', 'bitcoin'), 'bindir': os.path.join(data_dir, 'bins', 'bitcoin'),
'use_segwit': True 'use_segwit': True
}
}, },
'check_progress_seconds': 60, 'namecoin': {
'check_watched_seconds': 60, 'connection_type': 'rpc' if 'namecoin' in with_coins else 'none',
'check_expired_seconds': 60 'manage_daemon': True if 'namecoin' in with_coins else False,
'rpcport': 19798 + port_offset,
'datadir': os.path.join(data_dir, 'namecoin'),
'bindir': os.path.join(data_dir, 'bins', 'namecoin'),
'use_segwit': False,
'blocks_confirmed': 1
}
} }
with open(config_path, 'w') as fp: if add_coin != '':
json.dump(settings, fp, indent=4) logger.info('Adding coin: %s', add_coin)
if not os.path.exists(config_path):
exitWithError('{} does not exist'.format(config_path))
with open(config_path) as fs:
settings = json.load(fs)
cores = [ if add_coin in settings['chainclients']:
('particl', '0.18.1.0'), exitWithError('{} is already in the settings file'.format(add_coin))
('litecoin', '0.17.1'),
('bitcoin', '0.18.0'),
]
for c in cores:
if c[0] not in with_coins:
continue
prepareCore(c[0], c[1], settings, data_dir)
coin = c[0]
core_settings = settings['chainclients'][coin] settings['chainclients'][add_coin] = chainclients[add_coin]
data_dir = core_settings['datadir']
if not os.path.exists(data_dir): prepareCore(add_coin, known_coins[add_coin], settings, data_dir)
os.makedirs(data_dir) prepareDataDir(add_coin, settings, data_dir, chain)
core_conf_path = os.path.join(data_dir, coin + '.conf') with open(config_path, 'w') as fp:
if os.path.exists(core_conf_path): json.dump(settings, fp, indent=4)
sys.stderr.write('Error: %s exists, exiting.\n' % (core_conf_path))
exit(1)
with open(core_conf_path, 'w') as fp: logger.info('Done.')
if chain != 'mainnet': return 0
fp.write(chain + '=1\n')
if chain == 'testnet':
fp.write('[test]\n\n')
else:
logger.warning('Unknown chain %s', chain)
fp.write('rpcport={}\n'.format(core_settings['rpcport'])) logger.info('With coins: %s', ', '.join(with_coins))
fp.write('printtoconsole=0\n') if os.path.exists(config_path):
fp.write('daemon=0\n') exitWithError('{} exists'.format(config_path))
if coin == 'particl': settings = {
fp.write('debugexclude=libevent\n') 'debug': True,
fp.write('zmqpubsmsg=tcp://127.0.0.1:{}\n'.format(settings['zmqport'])) 'zmqhost': 'tcp://127.0.0.1',
fp.write('spentindex=1') 'zmqport': 20792 + port_offset,
fp.write('txindex=1') 'htmlhost': 'localhost',
elif coin == 'litecoin': 'htmlport': 12700 + port_offset,
fp.write('prune=1000\n') 'network_key': '7sW2UEcHXvuqEjkpE5mD584zRaQYs6WXYohue4jLFZPTvMSxwvgs',
elif coin == 'bitcoin': 'network_pubkey': '035758c4a22d7dd59165db02a56156e790224361eb3191f02197addcb3bde903d2',
fp.write('prune=1000\n') 'chainclients': chainclients,
else: 'check_progress_seconds': 60,
logger.warning('Unknown coin %s', coin) 'check_watched_seconds': 60,
'check_expired_seconds': 60
}
for c, v in known_coins.items():
if c not in with_coins:
continue
coin = c
prepareCore(coin, v, settings, data_dir)
prepareDataDir(coin, settings, data_dir, chain)
with open(config_path, 'w') as fp:
json.dump(settings, fp, indent=4)
logger.info('Loading Particl mnemonic') logger.info('Loading Particl mnemonic')

Loading…
Cancel
Save