mirror of
https://github.com/basicswap/basicswap.git
synced 2024-11-17 00:07:56 +00:00
Remember coin on rpc page and check chains are synced to send offers and
bids.
This commit is contained in:
parent
31766508b4
commit
9a0f237019
4 changed files with 37 additions and 4 deletions
|
@ -541,6 +541,15 @@ class BasicSwap():
|
|||
self.log.error('Can\'t connect to %s RPC, exiting.', coin_type)
|
||||
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):
|
||||
session = scoped_session(self.session_factory)
|
||||
kv = session.query(DBKVInt).filter_by(key=str_key).first()
|
||||
|
@ -663,6 +672,7 @@ class BasicSwap():
|
|||
|
||||
self.mxDB.acquire()
|
||||
try:
|
||||
self.checkSynced(coin_from_t, coin_to_t)
|
||||
proof_addr, proof_sig = self.getProofOfFunds(coin_from_t, amount)
|
||||
# TODO: require prrof of funds on offers?
|
||||
|
||||
|
@ -976,6 +986,8 @@ class BasicSwap():
|
|||
coin_from = Coins(offer.coin_from)
|
||||
coin_to = Coins(offer.coin_to)
|
||||
|
||||
self.checkSynced(coin_from, coin_to)
|
||||
|
||||
contract_count = self.getNewContractId()
|
||||
|
||||
now = int(time.time())
|
||||
|
@ -1628,6 +1640,18 @@ class BasicSwap():
|
|||
return self.callcoinrpc(coin_type, 'getblockchaininfo')['blocks']
|
||||
|
||||
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']
|
||||
|
||||
sum_unspent = 0
|
||||
|
|
|
@ -150,6 +150,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||
swap_client = self.server.swap_client
|
||||
|
||||
result = None
|
||||
coin_type = -1
|
||||
messages = []
|
||||
form_data = self.checkForm(post_string, 'rpc', messages)
|
||||
if form_data:
|
||||
|
@ -160,7 +161,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||
|
||||
cmd = form_data[b'cmd'][0].decode('utf-8')
|
||||
try:
|
||||
result = swap_client.callcoincli(coin_type, cmd)
|
||||
result = cmd + '\n' + swap_client.callcoincli(coin_type, cmd)
|
||||
except Exception as ex:
|
||||
result = str(ex)
|
||||
|
||||
|
@ -169,6 +170,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||
title=self.server.title,
|
||||
h2=self.server.title,
|
||||
coins=listAvailableCoins(swap_client),
|
||||
coin_type=coin_type,
|
||||
result=result,
|
||||
form_id=os.urandom(8).hex(),
|
||||
), 'UTF-8')
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
<form method="post">
|
||||
<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 %}
|
||||
<option value="{{ c[0] }}">{{ c[1] }}</option>
|
||||
<option value="{{ c[0] }}"{% if coin_type==c[0] %} selected{% endif %}>{{ c[1] }}</option>
|
||||
{% endfor %}
|
||||
</select><br/>
|
||||
<input type="text" name="cmd"><br/>
|
||||
|
|
|
@ -270,12 +270,19 @@ def make_rpc_func(bin_dir, data_dir, chain):
|
|||
nonlocal bin_dir
|
||||
nonlocal data_dir
|
||||
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 rpc_func
|
||||
|
||||
|
||||
def waitForRPC(rpc_func, wallet=None):
|
||||
for i in range(5):
|
||||
for i in range(10):
|
||||
try:
|
||||
rpc_func('getwalletinfo')
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue