diff --git a/basicswap/base.py b/basicswap/base.py index 5616b16..b2fb699 100644 --- a/basicswap/base.py +++ b/basicswap/base.py @@ -35,6 +35,7 @@ class BaseApp: self.chain = chain self.settings = settings self.coin_clients = {} + self.coin_interfaces = {} self.mxDB = threading.RLock() self.debug = self.settings.get('debug', False) self._network = None @@ -91,14 +92,6 @@ class BaseApp: return c raise ValueError('Unknown coin: {}'.format(coin_name)) - def getTicker(self, coin_type): - ticker = chainparams[coin_type]['ticker'] - if self.chain == 'testnet': - ticker = 't' + ticker - if self.chain == 'regtest': - ticker = 'rt' + ticker - return ticker - def encodeSegwitP2WSH(self, coin_type, p2wsh): return segwit_addr.encode(chainparams[coin_type][self.chain]['hrp'], 0, p2wsh[2:]) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 3d076a6..a32cd75 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -1430,9 +1430,9 @@ class BasicSwap(BaseApp): return est_fee def withdrawCoin(self, coin_type, value, addr_to, subfee): - self.log.info('withdrawCoin %s %s to %s %s', value, self.getTicker(coin_type), addr_to, ' subfee' if subfee else '') - ci = self.ci(coin_type) + self.log.info('withdrawCoin %s %s to %s %s', value, ci.ticker(), addr_to, ' subfee' if subfee else '') + txid = ci.withdrawCoin(value, addr_to, subfee) self.log.debug('In txn: {}'.format(txid)) return txid diff --git a/basicswap/chainparams.py b/basicswap/chainparams.py index 68f766a..33b03bf 100644 --- a/basicswap/chainparams.py +++ b/basicswap/chainparams.py @@ -205,8 +205,9 @@ chainparams = { class CoinInterface: - def __init__(self): + def __init__(self, network): self.setDefaults() + self._network = network def setDefaults(self): self._unknown_wallet_seed = True @@ -223,7 +224,12 @@ class CoinInterface: return chainparams[self.coin_type()]['name'].capitalize() def ticker(self): - return chainparams[self.coin_type()]['ticker'] + ticker = chainparams[self.coin_type()]['ticker'] + if self._network == 'testnet': + ticker = 't' + ticker + elif self._network == 'regtest': + ticker = 'rt' + ticker + return ticker def min_amount(self): return chainparams[self.coin_type()][self._network]['min_amount'] diff --git a/basicswap/explorers.py b/basicswap/explorers.py index 2b60567..bff1ab0 100644 --- a/basicswap/explorers.py +++ b/basicswap/explorers.py @@ -14,7 +14,6 @@ class Explorer(): self.coin_type = coin_type self.base_url = base_url self.log = self.swapclient.log - self.coin_settings = self.swapclient.coin_clients[self.coin_type] def readURL(self, url): self.log.debug('Explorer url: {}'.format(url)) diff --git a/basicswap/interface_btc.py b/basicswap/interface_btc.py index d366415..2a35d28 100644 --- a/basicswap/interface_btc.py +++ b/basicswap/interface_btc.py @@ -152,10 +152,9 @@ class BTCInterface(CoinInterface): return lock_value & SEQUENCE_LOCKTIME_MASK def __init__(self, coin_settings, network, swap_client=None): - super().__init__() + super().__init__(network) rpc_host = coin_settings.get('rpchost', '127.0.0.1') self.rpc_callback = make_rpc_func(coin_settings['rpcport'], coin_settings['rpcauth'], host=rpc_host) - self._network = network self.blocks_confirmed = coin_settings['blocks_confirmed'] self.setConfTarget(coin_settings['conf_target']) self._sc = swap_client diff --git a/basicswap/interface_xmr.py b/basicswap/interface_xmr.py index c47d831..271d212 100644 --- a/basicswap/interface_xmr.py +++ b/basicswap/interface_xmr.py @@ -59,12 +59,11 @@ class XMRInterface(CoinInterface): return 32 def __init__(self, coin_settings, network, swap_client=None): - super().__init__() + super().__init__(network) self.rpc_cb = make_xmr_rpc_func(coin_settings['rpcport'], host=coin_settings.get('rpchost', '127.0.0.1')) self.rpc_cb2 = make_xmr_rpc2_func(coin_settings['rpcport'], host=coin_settings.get('rpchost', '127.0.0.1')) # non-json endpoint self.rpc_wallet_cb = make_xmr_wallet_rpc_func(coin_settings['walletrpcport'], coin_settings['walletrpcauth']) - self._network = network self.blocks_confirmed = coin_settings['blocks_confirmed'] self._restore_height = coin_settings.get('restore_height', 0) self.setFeePriority(coin_settings.get('fee_priority', 0))