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
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,
'bindir': bindir,
'datadir': datadir,
'rpchost': chain_client_settings.get('rpchost', '127.0.0.1'),
'rpcport': chain_client_settings.get('rpcport', chainparams[coin][self.chain]['rpcport']),
'rpcauth': rpcauth,
'blocks_confirmed': chain_client_settings.get('blocks_confirmed', 6),
@ -543,6 +544,7 @@ class BasicSwap(BaseApp):
'core_version': None,
'explorers': [],
'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':

View file

@ -55,13 +55,14 @@ class XMRInterface(CoinInterface):
def __init__(self, coin_settings, network):
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'])
self.rpc_cb = rpc_cb
self.rpc_wallet_cb = rpc_wallet_cb
self._network = network
self.blocks_confirmed = coin_settings['blocks_confirmed']
self._restore_height = coin_settings['restore_height']
def setWalletFilename(self, wallet_filename):
self._wallet_filename = wallet_filename
@ -74,13 +75,6 @@ class XMRInterface(CoinInterface):
except Exception as e:
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)
Kbs = self.getPubkey(key_spend)
address_b58 = xmr_util.encode_address(Kbv, Kbs)
@ -90,7 +84,7 @@ class XMRInterface(CoinInterface):
'address': address_b58,
'viewkey': b2h(key_view[::-1]),
'spendkey': b2h(key_spend[::-1]),
'restore_height': restore_height,
'restore_height': self._restore_height,
}
rv = self.rpc_wallet_cb('generate_from_keys', params)
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']
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:
url = 'http://127.0.0.1:{}/{}'.format(rpc_port, path)
url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, path)
request_body = {
'method': method,
'params': params,
@ -65,12 +65,14 @@ def callrpc_xmr2(rpc_port, method, params=[]):
return r
def make_xmr_rpc_func(port):
def make_xmr_rpc_func(port, host='127.0.0.1'):
port = port
host = host
def rpc_func(method, params=None, wallet=None):
nonlocal port
return callrpc_xmr_na(port, method, params)
nonlocal host
return callrpc_xmr_na(port, method, params, rpc_host=host)
return rpc_func

View file

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

View file

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