mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
Ensure Particl mnemonic is loaded at startup.
This commit is contained in:
@@ -37,6 +37,7 @@ class BaseApp:
|
||||
self.coin_clients = {}
|
||||
self.mxDB = threading.RLock()
|
||||
self.debug = self.settings.get('debug', False)
|
||||
self._network = None
|
||||
|
||||
self.prepareLogging()
|
||||
self.log.info('Network: {}'.format(self.chain))
|
||||
|
||||
@@ -89,6 +89,7 @@ from .explorers import (
|
||||
ExplorerChainz,
|
||||
)
|
||||
import basicswap.config as cfg
|
||||
import basicswap.network as bsn
|
||||
import basicswap.protocols.atomic_swap_1 as atomic_swap_1
|
||||
|
||||
|
||||
@@ -507,6 +508,12 @@ class BasicSwap(BaseApp):
|
||||
|
||||
random.seed(secrets.randbits(128))
|
||||
|
||||
def finalise(self):
|
||||
if self._network:
|
||||
self._network.stopNetwork()
|
||||
self._network = None
|
||||
self.log.info('Finalise')
|
||||
|
||||
def setCoinConnectParams(self, coin):
|
||||
# Set anything that does not require the daemon to be running
|
||||
chain_client_settings = self.getChainClientSettings(coin)
|
||||
@@ -642,6 +649,10 @@ class BasicSwap(BaseApp):
|
||||
self.coin_clients[c]['have_spent_index'] = ci.haveSpentIndex()
|
||||
|
||||
# Sanity checks
|
||||
rv = self.callcoinrpc(c, 'extkey')
|
||||
if 'result' in rv and 'No keys to list.' in rv['result']:
|
||||
raise ValueError('No keys loaded.')
|
||||
|
||||
if self.callcoinrpc(c, 'getstakinginfo')['enabled'] is not False:
|
||||
self.log.warning('%s staking is not disabled.', ci.coin_name())
|
||||
elif c == Coins.XMR:
|
||||
@@ -649,6 +660,11 @@ class BasicSwap(BaseApp):
|
||||
|
||||
self.checkWalletSeed(c)
|
||||
|
||||
if 'p2p_host' in self.settings:
|
||||
network_key = self.getNetworkKey(1)
|
||||
self._network = bsn.Network(self.settings['p2p_host'], self.settings['p2p_port'], network_key)
|
||||
self._network.startNetwork()
|
||||
|
||||
self.initialise()
|
||||
|
||||
def stopDaemon(self, coin):
|
||||
@@ -1098,7 +1114,6 @@ class BasicSwap(BaseApp):
|
||||
raise ValueError('grindForEd25519Key failed')
|
||||
|
||||
def getWalletKey(self, coin_type, key_num, for_ed25519=False):
|
||||
account = self.callcoinrpc(Coins.PART, 'extkey', ['account'])
|
||||
evkey = self.callcoinrpc(Coins.PART, 'extkey', ['account', 'default', 'true'])['evkey']
|
||||
|
||||
key_path_base = '44445555h/1h/{}/{}'.format(int(coin_type), key_num)
|
||||
@@ -1110,7 +1125,6 @@ class BasicSwap(BaseApp):
|
||||
return self.grindForEd25519Key(coin_type, evkey, key_path_base)
|
||||
|
||||
def getPathKey(self, coin_from, coin_to, offer_created_at, contract_count, key_no, for_ed25519=False):
|
||||
account = self.callcoinrpc(Coins.PART, 'extkey', ['account'])
|
||||
evkey = self.callcoinrpc(Coins.PART, 'extkey', ['account', 'default', 'true'])['evkey']
|
||||
ci = self.ci(coin_to)
|
||||
|
||||
@@ -1124,6 +1138,14 @@ class BasicSwap(BaseApp):
|
||||
|
||||
return self.grindForEd25519Key(coin_to, evkey, key_path_base)
|
||||
|
||||
def getNetworkKey(self, key_num):
|
||||
evkey = self.callcoinrpc(Coins.PART, 'extkey', ['account', 'default', 'true'])['evkey']
|
||||
|
||||
key_path = '44445556h/1h/{}'.format(int(key_num))
|
||||
|
||||
extkey = self.callcoinrpc(Coins.PART, 'extkey', ['info', evkey, key_path])['key_info']['result']
|
||||
return decodeWif(self.callcoinrpc(Coins.PART, 'extkey', ['info', extkey])['key_info']['privkey'])
|
||||
|
||||
def getContractPubkey(self, date, contract_count):
|
||||
account = self.callcoinrpc(Coins.PART, 'extkey', ['account'])
|
||||
|
||||
|
||||
@@ -102,7 +102,11 @@ def js_bids(self, url_split, post_string):
|
||||
offer_id = bytes.fromhex(post_data[b'offer_id'][0].decode('utf-8'))
|
||||
assert(len(offer_id) == 28)
|
||||
|
||||
amount_from = inputAmount(post_data[b'amount_from'][0].decode('utf-8'))
|
||||
offer = swap_client.getOffer(offer_id)
|
||||
assert(offer), 'Offer not found.'
|
||||
|
||||
ci_from = swap_client.ci(offer.coin_from)
|
||||
amount_from = inputAmount(post_data[b'amount_from'][0].decode('utf-8'), ci_from)
|
||||
|
||||
addr_from = None
|
||||
if b'addr_from' in post_data:
|
||||
@@ -110,8 +114,7 @@ def js_bids(self, url_split, post_string):
|
||||
if addr_from == '-1':
|
||||
addr_from = None
|
||||
|
||||
offer = swap_client.getOffer(offer_id)
|
||||
if offer and offer.swap_type == SwapTypes.XMR_SWAP:
|
||||
if offer.swap_type == SwapTypes.XMR_SWAP:
|
||||
bid_id = swap_client.postXmrBid(offer_id, amount_from, addr_send_from=addr_from).hex()
|
||||
else:
|
||||
bid_id = swap_client.postBid(offer_id, amount_from, addr_send_from=addr_from).hex()
|
||||
|
||||
@@ -12,10 +12,17 @@ TODO:
|
||||
import select
|
||||
import socket
|
||||
import logging
|
||||
import threading
|
||||
|
||||
|
||||
class NetMessage:
|
||||
def __init__(self):
|
||||
self._msg_type
|
||||
|
||||
|
||||
class Peer:
|
||||
pass
|
||||
def __init__(self, address):
|
||||
self._address = address
|
||||
|
||||
|
||||
class Network:
|
||||
@@ -28,14 +35,24 @@ class Network:
|
||||
self._max_connections = 10
|
||||
self._running = True
|
||||
|
||||
self._network_thread = None
|
||||
self._mx = threading.Lock()
|
||||
|
||||
def startNetwork(self):
|
||||
pass
|
||||
|
||||
def stopNetwork(self):
|
||||
pass
|
||||
|
||||
def listen(self):
|
||||
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self._socket.bind((self._p2p_host, self._p2p_port))
|
||||
self._socket.listen(self._max_connections)
|
||||
|
||||
timeout = 1.0
|
||||
while self._running:
|
||||
readable, writable, errored = select.select([self._socket], [], [])
|
||||
readable, writable, errored = select.select([self._socket], [], [], timeout)
|
||||
for s in readable:
|
||||
client_socket, address = self._socket.accept()
|
||||
logging.info('Connection from %s', address)
|
||||
|
||||
Reference in New Issue
Block a user