@ -1,7 +1,7 @@
#!/usr/bin/env python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright (c) 2019-2020 tecnovert
# Copyright (c) 2019-2021 tecnovert
# Distributed under the MIT software license, see the accompanying
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@ -31,11 +31,14 @@ from bin.basicswap_run import startDaemon, startXmrWalletDaemon
if platform . system ( ) == ' Darwin ' :
if platform . system ( ) == ' Darwin ' :
BIN_ARCH = ' osx64.tar.gz '
BIN_ARCH = ' osx64 '
FILE_EXT = ' tar.gz '
elif platform . system ( ) == ' Windows ' :
elif platform . system ( ) == ' Windows ' :
BIN_ARCH = ' win64.zip '
BIN_ARCH = ' win64 '
FILE_EXT = ' zip '
else :
else :
BIN_ARCH = ' x86_64-linux-gnu.tar.gz '
BIN_ARCH = ' x86_64-linux-gnu '
FILE_EXT = ' tar.gz '
known_coins = {
known_coins = {
' particl ' : ' 0.19.1.2 ' ,
' particl ' : ' 0.19.1.2 ' ,
@ -67,6 +70,8 @@ LTC_RPC_HOST = os.getenv('LTC_RPC_HOST', 'localhost')
BTC_RPC_HOST = os . getenv ( ' BTC_RPC_HOST ' , ' localhost ' )
BTC_RPC_HOST = os . getenv ( ' BTC_RPC_HOST ' , ' localhost ' )
NMC_RPC_HOST = os . getenv ( ' NMC_RPC_HOST ' , ' localhost ' )
NMC_RPC_HOST = os . getenv ( ' NMC_RPC_HOST ' , ' localhost ' )
extract_core_overwrite = True
def make_reporthook ( ) :
def make_reporthook ( ) :
read = 0 # Number of bytes read so far
read = 0 # Number of bytes read so far
@ -88,6 +93,7 @@ def make_reporthook():
def downloadFile ( url , path ) :
def downloadFile ( url , path ) :
logger . info ( ' Downloading file %s ' , url )
logger . info ( ' Downloading file %s ' , url )
logger . info ( ' To %s ' , path )
opener = urllib . request . build_opener ( )
opener = urllib . request . build_opener ( )
opener . addheaders = [ ( ' User-agent ' , ' Mozilla/5.0 ' ) ]
opener . addheaders = [ ( ' User-agent ' , ' Mozilla/5.0 ' ) ]
urllib . request . install_opener ( opener )
urllib . request . install_opener ( opener )
@ -97,14 +103,26 @@ def downloadFile(url, path):
def extractCore ( coin , version , settings , bin_dir , release_path ) :
def extractCore ( coin , version , settings , bin_dir , release_path ) :
logger . info ( ' extractCore %s v %s ' , coin , version )
logger . info ( ' extractCore %s v %s ' , coin , version )
bins = [ coin + ' d ' , coin + ' -cli ' , coin + ' -tx ' ]
if coin == ' monero ' :
if coin == ' monero ' :
bins = [ ' monerod ' , ' monero-wallet-rpc ' ]
num_exist = 0
for b in bins :
out_path = os . path . join ( bin_dir , b )
if os . path . exists ( out_path ) :
num_exist + = 1
if not extract_core_overwrite and num_exist == len ( bins ) :
logger . info ( ' Skipping extract, files exist. ' )
return
with tarfile . open ( release_path ) as ft :
with tarfile . open ( release_path ) as ft :
for member in ft . getmembers ( ) :
for member in ft . getmembers ( ) :
if member . isdir ( ) :
if member . isdir ( ) :
continue
continue
out_path = os . path . join ( bin_dir , os . path . basename ( member . name ) )
bin_name = os . path . basename ( member . name )
if bin_name not in bins :
continue
out_path = os . path . join ( bin_dir , bin_name )
if ( not os . path . exists ( out_path ) ) or extract_core_overwrite :
fi = ft . extractfile ( member )
fi = ft . extractfile ( member )
with open ( out_path , ' wb ' ) as fout :
with open ( out_path , ' wb ' ) as fout :
fout . write ( fi . read ( ) )
fout . write ( fi . read ( ) )
@ -121,6 +139,7 @@ def extractCore(coin, version, settings, bin_dir, release_path):
for b in bins :
for b in bins :
b + = ' .exe '
b + = ' .exe '
out_path = os . path . join ( bin_dir , b )
out_path = os . path . join ( bin_dir , b )
if ( not os . path . exists ( out_path ) ) or extract_core_overwrite :
with open ( out_path , ' wb ' ) as fout :
with open ( out_path , ' wb ' ) as fout :
fout . write ( fz . read ( ' {} - {} /bin/ {} ' . format ( coin , version , b ) ) )
fout . write ( fz . read ( ' {} - {} /bin/ {} ' . format ( coin , version , b ) ) )
os . chmod ( out_path , stat . S_IRWXU | stat . S_IXGRP | stat . S_IXOTH )
os . chmod ( out_path , stat . S_IRWXU | stat . S_IXGRP | stat . S_IXOTH )
@ -128,6 +147,7 @@ def extractCore(coin, version, settings, bin_dir, release_path):
with tarfile . open ( release_path ) as ft :
with tarfile . open ( release_path ) as ft :
for b in bins :
for b in bins :
out_path = os . path . join ( bin_dir , b )
out_path = os . path . join ( bin_dir , b )
if not os . path . exists ( out_path ) or extract_core_overwrite :
fi = ft . extractfile ( ' {} - {} /bin/ {} ' . format ( coin , version , b ) )
fi = ft . extractfile ( ' {} - {} /bin/ {} ' . format ( coin , version , b ) )
with open ( out_path , ' wb ' ) as fout :
with open ( out_path , ' wb ' ) as fout :
fout . write ( fi . read ( ) )
fout . write ( fi . read ( ) )
@ -152,11 +172,12 @@ def prepareCore(coin, version, settings, data_dir):
os_dir_name = ' linux '
os_dir_name = ' linux '
os_name = ' linux '
os_name = ' linux '
release_filename = ' {} - {} - {} ' . format ( coin , version , BIN_ARCH )
if coin == ' monero ' :
if coin == ' monero ' :
use_file_ext = ' tar.bz2 ' if FILE_EXT == ' tar.gz ' else FILE_EXT
release_filename = ' {} - {} - {} . {} ' . format ( coin , version , BIN_ARCH , use_file_ext )
if os_name == ' osx ' :
if os_name == ' osx ' :
os_name = ' mac '
os_name = ' mac '
release_url = ' https://downloads.getmonero.org/cli/monero- {} -x64-v {} .tar.bz2 ' . format ( os_name , version )
release_url = ' https://downloads.getmonero.org/cli/monero- {} -x64-v {} . {} ' . format ( os_name , version , use_file_ext )
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 )
@ -168,7 +189,7 @@ def prepareCore(coin, version, settings, data_dir):
if not os . path . exists ( assert_path ) :
if not os . path . exists ( assert_path ) :
downloadFile ( assert_url , assert_path )
downloadFile ( assert_url , assert_path )
else :
else :
release_filename = ' {} - {} - {} ' . format ( coin , version , BIN_ARCH )
release_filename = ' {} - {} - {} . {} '. format ( coin , version , BIN_ARCH , FILE_EXT )
if coin == ' particl ' :
if coin == ' particl ' :
signing_key_name = ' tecnovert '
signing_key_name = ' tecnovert '
release_url = ' https://github.com/tecnovert/particl-core/releases/download/v {} / {} ' . format ( version , release_filename )
release_url = ' https://github.com/tecnovert/particl-core/releases/download/v {} / {} ' . format ( version , release_filename )
@ -284,16 +305,17 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic):
fp . write ( ' regtest=1 \n ' )
fp . write ( ' regtest=1 \n ' )
fp . write ( ' keep-fakechain=1 \n ' )
fp . write ( ' keep-fakechain=1 \n ' )
fp . write ( ' fixed-difficulty=1 \n ' )
fp . write ( ' fixed-difficulty=1 \n ' )
elif chain == ' testnet ' :
else :
fp . write ( ' bootstrap-daemon-address=auto \n ' )
fp . write ( ' restricted-rpc=1 \n ' )
if chain == ' testnet ' :
fp . write ( ' testnet=1 \n ' )
fp . write ( ' testnet=1 \n ' )
fp . write ( ' data-dir= {} \n ' . format ( data_dir ) )
fp . write ( ' data-dir= {} \n ' . format ( data_dir ) )
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=127.0.0.1 \n ' )
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-port= {} \n ' . format ( core_settings [ ' zmqport ' ] ) )
fp . write ( ' zmq-rpc-bind-ip=127.0.0.1 \n ' )
fp . write ( ' zmq-rpc-bind-ip=127.0.0.1 \n ' )
fp . write ( ' prune-blockchain=1 ' )
fp . write ( ' prune-blockchain=1 \n ' )
fp . write ( ' restricted-rpc=1 ' )
fp . write ( ' bootstrap-daemon-address=auto ' )
wallet_conf_path = os . path . join ( data_dir , coin + ' _wallet.conf ' )
wallet_conf_path = os . path . join ( data_dir , coin + ' _wallet.conf ' )
if os . path . exists ( wallet_conf_path ) :
if os . path . exists ( wallet_conf_path ) :
@ -346,7 +368,11 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic):
def printVersion ( ) :
def printVersion ( ) :
from basicswap import __version__
from basicswap import __version__
logger . info ( ' Basicswap version: ' , __version__ )
logger . info ( ' Basicswap version: %s ' , __version__ )
logger . info ( ' Core versions: ' )
for coin , version in known_coins . items ( ) :
logger . info ( ' \t %s : %s ' , coin , version )
def printHelp ( ) :
def printHelp ( ) :
@ -369,6 +395,7 @@ def printHelp():
logger . info ( ' --portoffset=n Raise all ports by n. ' )
logger . info ( ' --portoffset=n Raise all ports by n. ' )
logger . info ( ' --htmlhost= Interface to host on, default:localhost. ' )
logger . info ( ' --htmlhost= Interface to host on, default:localhost. ' )
logger . info ( ' --xmrrestoreheight=n Block height to restore Monero wallet from, default: {} . ' . format ( DEFAULT_XMR_RESTORE_HEIGHT ) )
logger . info ( ' --xmrrestoreheight=n Block height to restore Monero wallet from, default: {} . ' . format ( DEFAULT_XMR_RESTORE_HEIGHT ) )
logger . info ( ' --noextractover Prevent extracting cores if files exist. Speeds up tests ' )
logger . info ( ' \n ' + ' Known coins: %s ' , ' , ' . join ( known_coins . keys ( ) ) )
logger . info ( ' \n ' + ' Known coins: %s ' , ' , ' . join ( known_coins . keys ( ) ) )
@ -393,6 +420,7 @@ def exitWithError(error_msg):
def main ( ) :
def main ( ) :
global extract_core_overwrite
data_dir = None
data_dir = None
bin_dir = None
bin_dir = None
port_offset = None
port_offset = None
@ -437,6 +465,9 @@ def main():
if name == ' nocores ' :
if name == ' nocores ' :
no_cores = True
no_cores = True
continue
continue
if name == ' noextractover ' :
extract_core_overwrite = False
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 ( ' " ' ) )
@ -489,7 +520,8 @@ def main():
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 ' )
logger . info ( ' Using datadir: %s ' , data_dir )
logger . info ( ' datadir: %s ' , data_dir )
logger . info ( ' bindir: %s ' , bin_dir )
logger . info ( ' Chain: %s ' , chain )
logger . info ( ' Chain: %s ' , chain )
if port_offset is None :
if port_offset is None :