refactor: Move getTicker() to coin interface.
This commit is contained in:
parent
6516c6d138
commit
a5dcd9f77d
@ -35,6 +35,7 @@ class BaseApp:
|
|||||||
self.chain = chain
|
self.chain = chain
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.coin_clients = {}
|
self.coin_clients = {}
|
||||||
|
self.coin_interfaces = {}
|
||||||
self.mxDB = threading.RLock()
|
self.mxDB = threading.RLock()
|
||||||
self.debug = self.settings.get('debug', False)
|
self.debug = self.settings.get('debug', False)
|
||||||
self._network = None
|
self._network = None
|
||||||
@ -91,14 +92,6 @@ class BaseApp:
|
|||||||
return c
|
return c
|
||||||
raise ValueError('Unknown coin: {}'.format(coin_name))
|
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):
|
def encodeSegwitP2WSH(self, coin_type, p2wsh):
|
||||||
return segwit_addr.encode(chainparams[coin_type][self.chain]['hrp'], 0, p2wsh[2:])
|
return segwit_addr.encode(chainparams[coin_type][self.chain]['hrp'], 0, p2wsh[2:])
|
||||||
|
|
||||||
|
@ -1430,9 +1430,9 @@ class BasicSwap(BaseApp):
|
|||||||
return est_fee
|
return est_fee
|
||||||
|
|
||||||
def withdrawCoin(self, coin_type, value, addr_to, subfee):
|
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)
|
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)
|
txid = ci.withdrawCoin(value, addr_to, subfee)
|
||||||
self.log.debug('In txn: {}'.format(txid))
|
self.log.debug('In txn: {}'.format(txid))
|
||||||
return txid
|
return txid
|
||||||
|
@ -205,8 +205,9 @@ chainparams = {
|
|||||||
|
|
||||||
|
|
||||||
class CoinInterface:
|
class CoinInterface:
|
||||||
def __init__(self):
|
def __init__(self, network):
|
||||||
self.setDefaults()
|
self.setDefaults()
|
||||||
|
self._network = network
|
||||||
|
|
||||||
def setDefaults(self):
|
def setDefaults(self):
|
||||||
self._unknown_wallet_seed = True
|
self._unknown_wallet_seed = True
|
||||||
@ -223,7 +224,12 @@ class CoinInterface:
|
|||||||
return chainparams[self.coin_type()]['name'].capitalize()
|
return chainparams[self.coin_type()]['name'].capitalize()
|
||||||
|
|
||||||
def ticker(self):
|
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):
|
def min_amount(self):
|
||||||
return chainparams[self.coin_type()][self._network]['min_amount']
|
return chainparams[self.coin_type()][self._network]['min_amount']
|
||||||
|
@ -14,7 +14,6 @@ class Explorer():
|
|||||||
self.coin_type = coin_type
|
self.coin_type = coin_type
|
||||||
self.base_url = base_url
|
self.base_url = base_url
|
||||||
self.log = self.swapclient.log
|
self.log = self.swapclient.log
|
||||||
self.coin_settings = self.swapclient.coin_clients[self.coin_type]
|
|
||||||
|
|
||||||
def readURL(self, url):
|
def readURL(self, url):
|
||||||
self.log.debug('Explorer url: {}'.format(url))
|
self.log.debug('Explorer url: {}'.format(url))
|
||||||
|
@ -152,10 +152,9 @@ class BTCInterface(CoinInterface):
|
|||||||
return lock_value & SEQUENCE_LOCKTIME_MASK
|
return lock_value & SEQUENCE_LOCKTIME_MASK
|
||||||
|
|
||||||
def __init__(self, coin_settings, network, swap_client=None):
|
def __init__(self, coin_settings, network, swap_client=None):
|
||||||
super().__init__()
|
super().__init__(network)
|
||||||
rpc_host = coin_settings.get('rpchost', '127.0.0.1')
|
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.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.blocks_confirmed = coin_settings['blocks_confirmed']
|
||||||
self.setConfTarget(coin_settings['conf_target'])
|
self.setConfTarget(coin_settings['conf_target'])
|
||||||
self._sc = swap_client
|
self._sc = swap_client
|
||||||
|
@ -59,12 +59,11 @@ class XMRInterface(CoinInterface):
|
|||||||
return 32
|
return 32
|
||||||
|
|
||||||
def __init__(self, coin_settings, network, swap_client=None):
|
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_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_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.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.blocks_confirmed = coin_settings['blocks_confirmed']
|
||||||
self._restore_height = coin_settings.get('restore_height', 0)
|
self._restore_height = coin_settings.get('restore_height', 0)
|
||||||
self.setFeePriority(coin_settings.get('fee_priority', 0))
|
self.setFeePriority(coin_settings.get('fee_priority', 0))
|
||||||
|
Loading…
Reference in New Issue
Block a user