Add chain name to db filename.

This commit is contained in:
tecnovert 2019-07-31 14:56:51 +02:00
parent 4f83da0f26
commit 8796433c11
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93

View file

@ -301,6 +301,23 @@ class BasicSwap():
self.data_dir = data_dir self.data_dir = data_dir
self.chain = chain self.chain = chain
self.settings = settings self.settings = settings
self.coin_clients = {}
self.mxDB = threading.RLock()
self.last_expired = 0
self.last_checked_progress = 0
self.last_checked_watched = 0
self.last_checked_expired = 0
self.debug = self.settings.get('debug', DEBUG)
self.check_progress_seconds = self.settings.get('check_progress_seconds', 60)
self.check_watched_seconds = self.settings.get('check_watched_seconds', 60)
self.check_expired_seconds = self.settings.get('check_expired_seconds', 60 * 5)
self.swaps_in_progress = dict()
if self.chain == 'regtest':
SMSG_SECONDS_IN_DAY = 600
self.prepareLogging()
self.log.info('Network: {}'.format(self.chain))
# Encode key to match network # Encode key to match network
wif_prefix = chainparams[Coins.PART][self.chain]['key_prefix'] wif_prefix = chainparams[Coins.PART][self.chain]['key_prefix']
@ -309,14 +326,8 @@ class BasicSwap():
self.network_pubkey = self.settings['network_pubkey'] self.network_pubkey = self.settings['network_pubkey']
self.network_addr = pubkeyToAddress(chainparams[Coins.PART][self.chain]['pubkey_address'], bytearray.fromhex(self.network_pubkey)) self.network_addr = pubkeyToAddress(chainparams[Coins.PART][self.chain]['pubkey_address'], bytearray.fromhex(self.network_pubkey))
self.wallet = self.settings.get('wallet', None) # TODO: Move to coin_clients self.wallet = self.settings.get('wallet', None) # TODO: Move to coin_clients
self.last_expired = 0
self.debug = self.settings.get('debug', DEBUG) self.sqlite_file = os.path.join(self.data_dir, 'db{}.sqlite'.format('' if self.chain == 'mainnet' else ('_' + self.chain)))
self.coin_clients = {}
self.prepareLogging()
self.sqlite_file = os.path.join(self.data_dir, 'db.sqlite')
db_exists = os.path.exists(self.sqlite_file) db_exists = os.path.exists(self.sqlite_file)
self.engine = sa.create_engine('sqlite:///' + self.sqlite_file) self.engine = sa.create_engine('sqlite:///' + self.sqlite_file)
if not db_exists: if not db_exists:
@ -334,7 +345,6 @@ class BasicSwap():
value=self.db_version value=self.db_version
)) ))
session.commit() session.commit()
try: try:
self._contract_count = session.query(DBKVInt).filter_by(key='contract_count').first().value self._contract_count = session.query(DBKVInt).filter_by(key='contract_count').first().value
except Exception: except Exception:
@ -348,27 +358,8 @@ class BasicSwap():
self.zmqSubscriber.connect(self.settings['zmqhost'] + ':' + str(self.settings['zmqport'])) self.zmqSubscriber.connect(self.settings['zmqhost'] + ':' + str(self.settings['zmqport']))
self.zmqSubscriber.setsockopt_string(zmq.SUBSCRIBE, 'smsg') self.zmqSubscriber.setsockopt_string(zmq.SUBSCRIBE, 'smsg')
# Defaults
self.coin_clients = {}
for c in Coins: for c in Coins:
self.coin_clients[c] = self.setDefaultConnectParams(c) self.coin_clients[c] = self.setCoinConnectParams(c)
if self.chain == 'regtest':
SMSG_SECONDS_IN_DAY = 600
self.swaps_in_progress = dict()
self.check_progress_seconds = self.settings.get('check_progress_seconds', 60)
self.check_watched_seconds = self.settings.get('check_watched_seconds', 60)
self.check_expired_seconds = self.settings.get('check_expired_seconds', 60 * 5)
self.last_checked_progress = 0
self.last_checked_watched = 0
self.last_checked_expired = 0
self.mxDB = threading.RLock()
self.bidcount = 0
def prepareLogging(self): def prepareLogging(self):
self.log = logging.getLogger(self.log_name) self.log = logging.getLogger(self.log_name)
@ -393,7 +384,7 @@ class BasicSwap():
except Exception: except Exception:
return {} return {}
def setDefaultConnectParams(self, coin): def setCoinConnectParams(self, coin):
chain_client_settings = self.getChainClientSettings(coin) chain_client_settings = self.getChainClientSettings(coin)
bindir = os.path.expanduser(chain_client_settings.get('bindir', '')) bindir = os.path.expanduser(chain_client_settings.get('bindir', ''))
@ -460,6 +451,11 @@ class BasicSwap():
core_version = self.callcoinrpc(c, 'getnetworkinfo')['version'] core_version = self.callcoinrpc(c, 'getnetworkinfo')['version']
self.log.info('%s Core version %d', chainparams[c]['name'].capitalize(), core_version) self.log.info('%s Core version %d', chainparams[c]['name'].capitalize(), core_version)
# Sanity checks
if c == Coins.PART:
if self.callcoinrpc(c, 'getstakinginfo')['enabled'] is not False:
self.log.warning('%s staking is not disabled.', chainparams[c]['name'].capitalize())
self.initialise() self.initialise()
def stopRunning(self, with_code=0): def stopRunning(self, with_code=0):