Pass XMR restore height through json settings.

This commit is contained in:
tecnovert 2020-12-05 01:59:21 +02:00
parent 28d5848f3a
commit 669a465262
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
6 changed files with 32 additions and 21 deletions

View file

@ -29,4 +29,4 @@ VOLUME /coindata
COPY ./docker/entrypoint.sh /entrypoint.sh COPY ./docker/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD ["basicswap-run", "-datadir=/coindata/basicswap"] CMD ["basicswap-run", "-datadir=/coindata"]

View file

@ -530,6 +530,7 @@ class BasicSwap(BaseApp):
'connection_type': connection_type, 'connection_type': connection_type,
'bindir': bindir, 'bindir': bindir,
'datadir': datadir, 'datadir': datadir,
'rpchost': chain_client_settings.get('rpchost', '127.0.0.1'),
'rpcport': chain_client_settings.get('rpcport', chainparams[coin][self.chain]['rpcport']), 'rpcport': chain_client_settings.get('rpcport', chainparams[coin][self.chain]['rpcport']),
'rpcauth': rpcauth, 'rpcauth': rpcauth,
'blocks_confirmed': chain_client_settings.get('blocks_confirmed', 6), 'blocks_confirmed': chain_client_settings.get('blocks_confirmed', 6),
@ -543,6 +544,7 @@ class BasicSwap(BaseApp):
'core_version': None, 'core_version': None,
'explorers': [], 'explorers': [],
'chain_lookups': chain_client_settings.get('chain_lookups', 'local'), 'chain_lookups': chain_client_settings.get('chain_lookups', 'local'),
'restore_height': chain_client_settings.get('restore_height', 0),
} }
if self.coin_clients[coin]['connection_type'] == 'rpc': if self.coin_clients[coin]['connection_type'] == 'rpc':

View file

@ -55,13 +55,14 @@ class XMRInterface(CoinInterface):
def __init__(self, coin_settings, network): def __init__(self, coin_settings, network):
super().__init__() super().__init__()
rpc_cb = make_xmr_rpc_func(coin_settings['rpcport']) rpc_cb = make_xmr_rpc_func(coin_settings['rpcport'], host=coin_settings['rpchost'])
rpc_wallet_cb = make_xmr_wallet_rpc_func(coin_settings['walletrpcport'], coin_settings['walletrpcauth']) rpc_wallet_cb = make_xmr_wallet_rpc_func(coin_settings['walletrpcport'], coin_settings['walletrpcauth'])
self.rpc_cb = rpc_cb self.rpc_cb = rpc_cb
self.rpc_wallet_cb = rpc_wallet_cb self.rpc_wallet_cb = rpc_wallet_cb
self._network = network self._network = network
self.blocks_confirmed = coin_settings['blocks_confirmed'] self.blocks_confirmed = coin_settings['blocks_confirmed']
self._restore_height = coin_settings['restore_height']
def setWalletFilename(self, wallet_filename): def setWalletFilename(self, wallet_filename):
self._wallet_filename = wallet_filename self._wallet_filename = wallet_filename
@ -74,13 +75,6 @@ class XMRInterface(CoinInterface):
except Exception as e: except Exception as e:
pass pass
try:
if restore_height is None:
restore_height = self.getChainHeight()
except Exception as e:
logging.warning('Unable to get restore_height, set to zero. Error: {}'.format(str(e)))
restore_height = 0
Kbv = self.getPubkey(key_view) Kbv = self.getPubkey(key_view)
Kbs = self.getPubkey(key_spend) Kbs = self.getPubkey(key_spend)
address_b58 = xmr_util.encode_address(Kbv, Kbs) address_b58 = xmr_util.encode_address(Kbv, Kbs)
@ -90,7 +84,7 @@ class XMRInterface(CoinInterface):
'address': address_b58, 'address': address_b58,
'viewkey': b2h(key_view[::-1]), 'viewkey': b2h(key_view[::-1]),
'spendkey': b2h(key_spend[::-1]), 'spendkey': b2h(key_spend[::-1]),
'restore_height': restore_height, 'restore_height': self._restore_height,
} }
rv = self.rpc_wallet_cb('generate_from_keys', params) rv = self.rpc_wallet_cb('generate_from_keys', params)
logging.info('generate_from_keys %s', dumpj(rv)) logging.info('generate_from_keys %s', dumpj(rv))

View file

@ -28,9 +28,9 @@ def callrpc_xmr(rpc_port, auth, method, params=[], path='json_rpc'):
return r['result'] return r['result']
def callrpc_xmr_na(rpc_port, method, params=[], path='json_rpc'): def callrpc_xmr_na(rpc_port, method, params=[], rpc_host='127.0.0.1', path='json_rpc'):
try: try:
url = 'http://127.0.0.1:{}/{}'.format(rpc_port, path) url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, path)
request_body = { request_body = {
'method': method, 'method': method,
'params': params, 'params': params,
@ -65,12 +65,14 @@ def callrpc_xmr2(rpc_port, method, params=[]):
return r return r
def make_xmr_rpc_func(port): def make_xmr_rpc_func(port, host='127.0.0.1'):
port = port port = port
host = host
def rpc_func(method, params=None, wallet=None): def rpc_func(method, params=None, wallet=None):
nonlocal port nonlocal port
return callrpc_xmr_na(port, method, params) nonlocal host
return callrpc_xmr_na(port, method, params, rpc_host=host)
return rpc_func return rpc_func

View file

@ -56,12 +56,14 @@ if not len(logger.handlers):
logger.addHandler(logging.StreamHandler(sys.stdout)) logger.addHandler(logging.StreamHandler(sys.stdout))
XMR_RPC_HOST = os.getenv('XMR_RPC_HOST', 'localhost') XMR_RPC_HOST = os.getenv('XMR_RPC_HOST', 'localhost')
BASE_XMR_RPC_PORT = os.getenv('BASE_XMR_RPC_PORT', 29798) BASE_XMR_RPC_PORT = int(os.getenv('BASE_XMR_RPC_PORT', 29798))
BASE_XMR_ZMQ_PORT = os.getenv('BASE_XMR_ZMQ_PORT', 30898) BASE_XMR_ZMQ_PORT = int(os.getenv('BASE_XMR_ZMQ_PORT', 30898))
BASE_XMR_WALLET_PORT = os.getenv('BASE_XMR_WALLET_PORT', 29998) BASE_XMR_WALLET_PORT = int(os.getenv('BASE_XMR_WALLET_PORT', 29998))
XMR_WALLET_RPC_USER = os.getenv('XMR_WALLET_RPC_USER', 'xmr_wallet_user') XMR_WALLET_RPC_USER = os.getenv('XMR_WALLET_RPC_USER', 'xmr_wallet_user')
XMR_WALLET_RPC_PWD = os.getenv('XMR_WALLET_RPC_PWD', 'xmr_wallet_pwd') XMR_WALLET_RPC_PWD = os.getenv('XMR_WALLET_RPC_PWD', 'xmr_wallet_pwd')
DEFAULT_XMR_RESTORE_HEIGHT = 2245107
def make_reporthook(): def make_reporthook():
read = 0 # Number of bytes read so far read = 0 # Number of bytes read so far
@ -353,6 +355,9 @@ def printHelp():
logger.info('--disablecoin= Make coin inactive.') logger.info('--disablecoin= Make coin inactive.')
logger.info('--preparebinonly Don\'t prepare settings or datadirs.') logger.info('--preparebinonly Don\'t prepare settings or datadirs.')
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('--xmrrestoreheight=n Block height to restore Monero wallet from, default:{}.'.format(DEFAULT_XMR_RESTORE_HEIGHT))
logger.info('\n' + 'Known coins: %s', ', '.join(known_coins.keys())) logger.info('\n' + 'Known coins: %s', ', '.join(known_coins.keys()))
@ -386,6 +391,8 @@ def main():
with_coins = {'particl', 'litecoin'} with_coins = {'particl', 'litecoin'}
add_coin = '' add_coin = ''
disable_coin = '' disable_coin = ''
htmlhost = 'localhost'
xmr_restore_height = DEFAULT_XMR_RESTORE_HEIGHT
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] != '-':
@ -415,7 +422,6 @@ def main():
if name == 'preparebinonly': if name == 'preparebinonly':
prepare_bin_only = True prepare_bin_only = True
continue 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('"'))
@ -454,6 +460,12 @@ def main():
exitWithError('Unknown coin {}'.format(s[1])) exitWithError('Unknown coin {}'.format(s[1]))
disable_coin = s[1] disable_coin = s[1]
continue continue
if name == 'htmlhost':
htmlhost = s[1].strip('"')
continue
if name == 'xmrrestoreheight':
xmr_restore_height = int(s[1])
continue
exitWithError('Unknown argument {}'.format(v)) exitWithError('Unknown argument {}'.format(v))
@ -525,7 +537,7 @@ def main():
}, },
'monero': { 'monero': {
'connection_type': 'rpc' if 'monero' in with_coins else 'none', 'connection_type': 'rpc' if 'monero' in with_coins else 'none',
'manage_daemon': True if 'monero' in with_coins else False, 'manage_daemon': True if ('monero' in with_coins and XMR_RPC_HOST == 'localhost') else False,
'manage_wallet_daemon': True if 'monero' in with_coins else False, 'manage_wallet_daemon': True if 'monero' in with_coins else False,
'rpcport': BASE_XMR_RPC_PORT + port_offset, 'rpcport': BASE_XMR_RPC_PORT + port_offset,
'zmqport': BASE_XMR_ZMQ_PORT + port_offset, 'zmqport': BASE_XMR_ZMQ_PORT + port_offset,
@ -536,6 +548,7 @@ def main():
'walletfile': 'swap_wallet', 'walletfile': 'swap_wallet',
'datadir': os.path.join(data_dir, 'monero'), 'datadir': os.path.join(data_dir, 'monero'),
'bindir': os.path.join(bin_dir, 'monero'), 'bindir': os.path.join(bin_dir, 'monero'),
'restore_height': xmr_restore_height,
} }
} }
@ -603,7 +616,7 @@ def main():
'debug': True, 'debug': True,
'zmqhost': 'tcp://127.0.0.1', 'zmqhost': 'tcp://127.0.0.1',
'zmqport': 20792 + port_offset, 'zmqport': 20792 + port_offset,
'htmlhost': 'localhost', 'htmlhost': htmlhost,
'htmlport': 12700 + port_offset, 'htmlport': 12700 + port_offset,
'network_key': '7sW2UEcHXvuqEjkpE5mD584zRaQYs6WXYohue4jLFZPTvMSxwvgs', 'network_key': '7sW2UEcHXvuqEjkpE5mD584zRaQYs6WXYohue4jLFZPTvMSxwvgs',
'network_pubkey': '035758c4a22d7dd59165db02a56156e790224361eb3191f02197addcb3bde903d2', 'network_pubkey': '035758c4a22d7dd59165db02a56156e790224361eb3191f02197addcb3bde903d2',

View file

@ -1,2 +1,2 @@
HTML_PORT=127.0.0.1:12700:12700 HTML_PORT=127.0.0.1:12700:12700
COINDATA_PATH=/var/data/basicswap #COINDATA_PATH=/var/data/basicswap