Remember coin on rpc page and check chains are synced to send offers and

bids.
2024-05-20_merge
tecnovert 5 years ago
parent 31766508b4
commit 9a0f237019
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 24
      basicswap/basicswap.py
  2. 4
      basicswap/http_server.py
  3. 4
      basicswap/templates/rpc.html
  4. 9
      bin/basicswap_prepare.py

@ -541,6 +541,15 @@ class BasicSwap():
self.log.error('Can\'t connect to %s RPC, exiting.', coin_type) self.log.error('Can\'t connect to %s RPC, exiting.', coin_type)
self.stopRunning(1) # systemd will try restart if fail_code != 0 self.stopRunning(1) # systemd will try restart if fail_code != 0
def checkSynced(self, coin_from, coin_to):
check_coins = [coin_from, coin_to]
for c in check_coins:
if self.coin_clients[c]['connection_type'] != 'rpc':
continue
synced = round(self.callcoinrpc(c, 'getblockchaininfo')['verificationprogress'], 3)
if synced < 1.0:
raise ValueError('{} chain is still syncing, currently at {}.'.format(synced))
def setIntKV(self, str_key, int_val): def setIntKV(self, str_key, int_val):
session = scoped_session(self.session_factory) session = scoped_session(self.session_factory)
kv = session.query(DBKVInt).filter_by(key=str_key).first() kv = session.query(DBKVInt).filter_by(key=str_key).first()
@ -663,6 +672,7 @@ class BasicSwap():
self.mxDB.acquire() self.mxDB.acquire()
try: try:
self.checkSynced(coin_from_t, coin_to_t)
proof_addr, proof_sig = self.getProofOfFunds(coin_from_t, amount) proof_addr, proof_sig = self.getProofOfFunds(coin_from_t, amount)
# TODO: require prrof of funds on offers? # TODO: require prrof of funds on offers?
@ -976,6 +986,8 @@ class BasicSwap():
coin_from = Coins(offer.coin_from) coin_from = Coins(offer.coin_from)
coin_to = Coins(offer.coin_to) coin_to = Coins(offer.coin_to)
self.checkSynced(coin_from, coin_to)
contract_count = self.getNewContractId() contract_count = self.getNewContractId()
now = int(time.time()) now = int(time.time())
@ -1628,6 +1640,18 @@ class BasicSwap():
return self.callcoinrpc(coin_type, 'getblockchaininfo')['blocks'] return self.callcoinrpc(coin_type, 'getblockchaininfo')['blocks']
def lookupUnspentByAddress(self, coin_type, address, sum_output=False, assert_amount=None, assert_txid=None): def lookupUnspentByAddress(self, coin_type, address, sum_output=False, assert_amount=None, assert_txid=None):
# TODO: Lookup from explorers
if assert_txid != None:
try:
ro = self.callcoinrpc(coin_type, 'getmempoolentry', [assert_txid])
self.log.debug('Tx %s found in mempool, fee %s', assert_txid, ro['fee'])
# TODO: Save info
return None
except Exception:
pass
num_blocks = self.callcoinrpc(coin_type, 'getblockchaininfo')['blocks'] num_blocks = self.callcoinrpc(coin_type, 'getblockchaininfo')['blocks']
sum_unspent = 0 sum_unspent = 0

@ -150,6 +150,7 @@ class HttpHandler(BaseHTTPRequestHandler):
swap_client = self.server.swap_client swap_client = self.server.swap_client
result = None result = None
coin_type = -1
messages = [] messages = []
form_data = self.checkForm(post_string, 'rpc', messages) form_data = self.checkForm(post_string, 'rpc', messages)
if form_data: if form_data:
@ -160,7 +161,7 @@ class HttpHandler(BaseHTTPRequestHandler):
cmd = form_data[b'cmd'][0].decode('utf-8') cmd = form_data[b'cmd'][0].decode('utf-8')
try: try:
result = swap_client.callcoincli(coin_type, cmd) result = cmd + '\n' + swap_client.callcoincli(coin_type, cmd)
except Exception as ex: except Exception as ex:
result = str(ex) result = str(ex)
@ -169,6 +170,7 @@ class HttpHandler(BaseHTTPRequestHandler):
title=self.server.title, title=self.server.title,
h2=self.server.title, h2=self.server.title,
coins=listAvailableCoins(swap_client), coins=listAvailableCoins(swap_client),
coin_type=coin_type,
result=result, result=result,
form_id=os.urandom(8).hex(), form_id=os.urandom(8).hex(),
), 'UTF-8') ), 'UTF-8')

@ -7,9 +7,9 @@
<form method="post"> <form method="post">
<p> <p>
<select name="coin_type"><option value="-1">-- Select Coin --</option> <select name="coin_type"><option value="-1"{% if coin_type==-1 %} selected{% endif %}>-- Select Coin --</option>
{% for c in coins %} {% for c in coins %}
<option value="{{ c[0] }}">{{ c[1] }}</option> <option value="{{ c[0] }}"{% if coin_type==c[0] %} selected{% endif %}>{{ c[1] }}</option>
{% endfor %} {% endfor %}
</select><br/> </select><br/>
<input type="text" name="cmd"><br/> <input type="text" name="cmd"><br/>

@ -270,12 +270,19 @@ def make_rpc_func(bin_dir, data_dir, chain):
nonlocal bin_dir nonlocal bin_dir
nonlocal data_dir nonlocal data_dir
nonlocal chain nonlocal chain
# Debug ci
try:
os.system('cat ' + os.path.join(data_dir, 'debug.log'))
except Exception as ex:
logger.error(ex)
return callrpc_cli(bin_dir, data_dir, chain, cmd, cfg.PARTICL_CLI) return callrpc_cli(bin_dir, data_dir, chain, cmd, cfg.PARTICL_CLI)
return rpc_func return rpc_func
def waitForRPC(rpc_func, wallet=None): def waitForRPC(rpc_func, wallet=None):
for i in range(5): for i in range(10):
try: try:
rpc_func('getwalletinfo') rpc_func('getwalletinfo')
return return

Loading…
Cancel
Save