preparescript: Download BTC utxo snapshot first, allow resume.

This commit is contained in:
tecnovert
2022-12-14 00:19:38 +02:00
parent 5ce178e673
commit 80a78b4070
4 changed files with 192 additions and 46 deletions

View File

@@ -1423,11 +1423,8 @@ class BasicSwap(BaseApp):
def revokeOffer(self, offer_id, security_token=None):
self.log.info('Revoking offer %s', offer_id.hex())
session = None
self.mxDB.acquire()
session = self.openSession()
try:
session = scoped_session(self.session_factory)
offer = session.query(Offer).filter_by(offer_id=offer_id).first()
if offer.security_token is not None and offer.security_token != security_token:
@@ -1445,10 +1442,21 @@ class BasicSwap(BaseApp):
msg_id = self.sendSmsg(offer.addr_from, self.network_addr, payload_hex, offer.time_valid)
self.log.debug('Revoked offer %s in msg %s', offer_id.hex(), msg_id.hex())
finally:
if session:
session.close()
session.remove()
self.mxDB.release()
self.closeSession(session, commit=False)
def archiveOffer(self, offer_id):
self.log.info('Archiving offer %s', offer_id.hex())
session = self.openSession()
try:
offer = session.query(Offer).filter_by(offer_id=offer_id).first()
if offer.active_ind != 1:
raise ValueError('Offer is not active')
offer.active_ind = 3
finally:
self.closeSession(session)
def grindForEd25519Key(self, coin_type, evkey, key_path_base):
ci = self.ci(coin_type)

View File

@@ -396,6 +396,13 @@
<button name="revoke_offer" value="Revoke Offer" type="submit" onclick="return confirmPopup();" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-red-500 hover:text-red-600 border border-red-400 hover:border-red-500 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none"><svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ef5844" stroke-linejoin="round" ><line x1="16" y1="8" x2="8" y2="16" stroke="#ef5844"></line> <line x1="16" y1="16" x2="8" y2="8" stroke="#ef5844"></line> <circle cx="12" cy="12" r="11"></circle></g></svg> Revoke Offer </button>
</div>
{% endif %}
<!-- TODO:
{% if data.active_ind == 1 %}
<div class="w-full md:w-auto p-1.5">
<button name="archive_offer" value="Archive Offer" type="submit" onclick="return confirmPopup();" class="flex flex-wrap justify-center w-full px-4 py-2.5 font-medium text-sm text-red-500 hover:text-red-600 border border-red-400 hover:border-red-500 bg-white rounded-md shadow-button focus:ring-0 focus:outline-none"><svg class="text-gray-500 w-5 h-5 mr-2" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><g stroke-linecap="round" stroke-width="2" fill="none" stroke="#ef5844" stroke-linejoin="round" ><line x1="16" y1="8" x2="8" y2="16" stroke="#ef5844"></line> <line x1="16" y1="16" x2="8" y2="8" stroke="#ef5844"></line> <circle cx="12" cy="12" r="11"></circle></g></svg>Archive Offer</button>
</div>
{% endif %}
-->
{% endif %}
<!-- todo
<div class="w-full md:w-auto p-1.5 ml-2">

View File

@@ -449,6 +449,12 @@ def page_offer(self, url_split, post_string):
bid_rate = ci_to.format_amount(offer.rate)
if form_data:
if b'archive_offer' in form_data:
try:
swap_client.archiveOffer(offer_id)
messages.append('Offer archived')
except Exception as ex:
err_messages.append('Archive offer failed: ' + str(ex))
if b'revoke_offer' in form_data:
try:
swap_client.revokeOffer(offer_id)
@@ -525,7 +531,8 @@ def page_offer(self, url_split, post_string):
'bid_rate': bid_rate,
'debug_ui': swap_client.debug_ui,
'automation_strat_id': -1,
'is_expired': offer.expire_at <= now
'is_expired': offer.expire_at <= now,
'active_ind': offer.active_ind
}
data.update(extend_data)
@@ -622,7 +629,7 @@ def page_offers(self, url_split, post_string, sent=False):
filters['sent_from'] = sent_from
if have_data_entry(form_data, 'active'):
active_filter = get_data_entry(form_data, 'active')
ensure(active_filter in ['any', 'active', 'expired', 'revoked'], 'Invalid active filter')
ensure(active_filter in ['any', 'active', 'expired', 'revoked', 'archived'], 'Invalid active filter')
filters['active'] = active_filter
set_pagination_filters(form_data, filters)