ui: Display estimate of when lock refund tx will be swipeable.

This commit is contained in:
tecnovert 2021-12-19 14:15:32 +02:00
parent a802788cfd
commit 55275a6470
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
4 changed files with 48 additions and 19 deletions

View file

@ -122,7 +122,9 @@ from .basicswap_util import (
getOfferProofOfFundsHash, getOfferProofOfFundsHash,
getLastBidState, getLastBidState,
isActiveBidState) isActiveBidState)
from .protocols.xmr_swap_1 import recoverNoScriptTxnWithKey from .protocols.xmr_swap_1 import (
addLockRefundSigs,
recoverNoScriptTxnWithKey)
non_script_type_coins = (Coins.XMR, Coins.PART_ANON) non_script_type_coins = (Coins.XMR, Coins.PART_ANON)
@ -2965,7 +2967,6 @@ class BasicSwap(BaseApp):
self.logBidEvent(bid.bid_id, EventLogTypes.LOCK_TX_A_SEEN, '', session) self.logBidEvent(bid.bid_id, EventLogTypes.LOCK_TX_A_SEEN, '', session)
block_header = ci_from.getBlockHeaderFromHeight(lock_tx_chain_info['height']) block_header = ci_from.getBlockHeaderFromHeight(lock_tx_chain_info['height'])
bid.xmr_a_lock_tx.block_hash = bytes.fromhex(block_header['hash']) bid.xmr_a_lock_tx.block_hash = bytes.fromhex(block_header['hash'])
bid.xmr_a_lock_tx.block_height = block_header['height'] bid.xmr_a_lock_tx.block_height = block_header['height']
bid.xmr_a_lock_tx.block_time = block_header['time'] # Or median_time? bid.xmr_a_lock_tx.block_time = block_header['time'] # Or median_time?
@ -3065,6 +3066,21 @@ class BasicSwap(BaseApp):
bid.setState(BidStates.SWAP_COMPLETED) bid.setState(BidStates.SWAP_COMPLETED)
self.saveBidInSession(bid_id, bid, session, xmr_swap) self.saveBidInSession(bid_id, bid, session, xmr_swap)
session.commit() session.commit()
elif state == BidStates.XMR_SWAP_SCRIPT_TX_PREREFUND:
if TxTypes.XMR_SWAP_A_LOCK_REFUND in bid.txns:
refund_tx = bid.txns[TxTypes.XMR_SWAP_A_LOCK_REFUND]
if refund_tx.block_time is None:
a_lock_refund_tx_dest = ci_from.getScriptDest(xmr_swap.a_lock_refund_tx_script)
p2wsh_addr = ci_from.encode_p2wsh(a_lock_refund_tx_dest)
lock_refund_tx_chain_info = ci_from.getLockTxHeight(refund_tx.txid, p2wsh_addr, 0, bid.chain_a_height_start)
block_header = ci_from.getBlockHeaderFromHeight(lock_refund_tx_chain_info['height'])
refund_tx.block_hash = bytes.fromhex(block_header['hash'])
refund_tx.block_height = block_header['height']
refund_tx.block_time = block_header['time'] # Or median_time?
self.saveBidInSession(bid_id, bid, session, xmr_swap)
session.commit()
except Exception as ex: except Exception as ex:
raise ex raise ex
@ -4269,7 +4285,7 @@ class BasicSwap(BaseApp):
prevout_amount = ci_from.getLockTxSwapOutputValue(bid, xmr_swap) prevout_amount = ci_from.getLockTxSwapOutputValue(bid, xmr_swap)
xmr_swap.af_lock_refund_tx_sig = ci_from.signTx(kaf, xmr_swap.a_lock_refund_tx, 0, xmr_swap.a_lock_tx_script, prevout_amount) xmr_swap.af_lock_refund_tx_sig = ci_from.signTx(kaf, xmr_swap.a_lock_refund_tx, 0, xmr_swap.a_lock_tx_script, prevout_amount)
self.addLockRefundSigs(xmr_swap, ci_from) addLockRefundSigs(self, xmr_swap, ci_from)
msg_buf = XmrBidLockTxSigsMessage( msg_buf = XmrBidLockTxSigsMessage(
bid_msg_id=bid_id, bid_msg_id=bid_id,
@ -4679,7 +4695,7 @@ class BasicSwap(BaseApp):
v = ci_from.verifyTxSig(xmr_swap.a_lock_refund_spend_tx, xmr_swap.af_lock_refund_spend_tx_sig, xmr_swap.pkaf, 0, xmr_swap.a_lock_refund_tx_script, prevout_amount) v = ci_from.verifyTxSig(xmr_swap.a_lock_refund_spend_tx, xmr_swap.af_lock_refund_spend_tx_sig, xmr_swap.pkaf, 0, xmr_swap.a_lock_refund_tx_script, prevout_amount)
ensure(v, 'Invalid signature for lock refund spend txn') ensure(v, 'Invalid signature for lock refund spend txn')
self.addLockRefundSigs(xmr_swap, ci_from) addLockRefundSigs(self, xmr_swap, ci_from)
delay = random.randrange(self.min_delay_event, self.max_delay_event) delay = random.randrange(self.min_delay_event, self.max_delay_event)
self.log.info('Sending coin A lock tx for xmr bid %s in %d seconds', bid_id.hex(), delay) self.log.info('Sending coin A lock tx for xmr bid %s in %d seconds', bid_id.hex(), delay)
@ -5527,19 +5543,6 @@ class BasicSwap(BaseApp):
session.remove() session.remove()
self.mxDB.release() self.mxDB.release()
def addLockRefundSigs(self, xmr_swap, ci):
self.log.debug('Setting lock refund tx sigs')
witness_stack = [
b'',
xmr_swap.al_lock_refund_tx_sig,
xmr_swap.af_lock_refund_tx_sig,
xmr_swap.a_lock_tx_script,
]
signed_tx = ci.setTxSignature(xmr_swap.a_lock_refund_tx, witness_stack)
ensure(signed_tx, 'setTxSignature failed')
xmr_swap.a_lock_refund_tx = signed_tx
def createCoinALockRefundSwipeTx(self, ci, bid, offer, xmr_swap, xmr_offer): def createCoinALockRefundSwipeTx(self, ci, bid, offer, xmr_swap, xmr_offer):
self.log.debug('Creating %s lock refund swipe tx', ci.coin_name()) self.log.debug('Creating %s lock refund swipe tx', ci.coin_name())

View file

@ -18,6 +18,20 @@ from basicswap.basicswap_util import (
) )
def addLockRefundSigs(self, xmr_swap, ci):
self.log.debug('Setting lock refund tx sigs')
witness_stack = [
b'',
xmr_swap.al_lock_refund_tx_sig,
xmr_swap.af_lock_refund_tx_sig,
xmr_swap.a_lock_tx_script,
]
signed_tx = ci.setTxSignature(xmr_swap.a_lock_refund_tx, witness_stack)
ensure(signed_tx, 'setTxSignature failed')
xmr_swap.a_lock_refund_tx = signed_tx
def recoverNoScriptTxnWithKey(self, bid_id, encoded_key): def recoverNoScriptTxnWithKey(self, bid_id, encoded_key):
# Manually recover txn if other key is known # Manually recover txn if other key is known
session = scoped_session(self.session_factory) session = scoped_session(self.session_factory)

View file

@ -28,6 +28,9 @@
<tr><td>Received</td><td>{{ data.was_received }}</td></tr> <tr><td>Received</td><td>{{ data.was_received }}</td></tr>
{% if data.coin_a_lock_refund_tx_est_final != 'None' %} {% if data.coin_a_lock_refund_tx_est_final != 'None' %}
<tr><td>{{ data.ticker_from }} lock refund tx valid at</td><td>{{ data.coin_a_lock_refund_tx_est_final | formatts }}</td></tr> <tr><td>{{ data.ticker_from }} lock refund tx valid at</td><td>{{ data.coin_a_lock_refund_tx_est_final | formatts }}</td></tr>
{% if data.coin_a_lock_refund_swipe_tx_est_final != 'None' %}
<tr><td>{{ data.ticker_from }} lock refund tx swipeable at</td><td>{{ data.coin_a_lock_refund_swipe_tx_est_final | formatts }}</td></tr>
{% endif %}
<tr><td>{{ data.ticker_from }} chain median time</td><td>{{ data.coin_a_last_median_time | formatts }}</td></tr> <tr><td>{{ data.ticker_from }} chain median time</td><td>{{ data.coin_a_last_median_time | formatts }}</td></tr>
{% endif %} {% endif %}

View file

@ -304,13 +304,22 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b
if offer.swap_type == SwapTypes.XMR_SWAP: if offer.swap_type == SwapTypes.XMR_SWAP:
data['coin_a_lock_refund_tx_est_final'] = 'None' data['coin_a_lock_refund_tx_est_final'] = 'None'
if bid.xmr_a_lock_tx and bid.xmr_a_lock_tx.block_time: data['coin_a_lock_refund_swipe_tx_est_final'] = 'None'
if offer.lock_type == TxLockTypes.SEQUENCE_LOCK_TIME:
if offer.lock_type == TxLockTypes.SEQUENCE_LOCK_TIME:
if bid.xmr_a_lock_tx and bid.xmr_a_lock_tx.block_time:
raw_sequence = ci_from.getExpectedSequence(offer.lock_type, offer.lock_value) raw_sequence = ci_from.getExpectedSequence(offer.lock_type, offer.lock_value)
seconds_locked = ci_from.decodeSequence(raw_sequence) seconds_locked = ci_from.decodeSequence(raw_sequence)
data['coin_a_lock_refund_tx_est_final'] = bid.xmr_a_lock_tx.block_time + seconds_locked data['coin_a_lock_refund_tx_est_final'] = bid.xmr_a_lock_tx.block_time + seconds_locked
data['coin_a_last_median_time'] = swap_client.coin_clients[offer.coin_from]['chain_median_time'] data['coin_a_last_median_time'] = swap_client.coin_clients[offer.coin_from]['chain_median_time']
if TxTypes.XMR_SWAP_A_LOCK_REFUND in bid.txns:
refund_tx = bid.txns[TxTypes.XMR_SWAP_A_LOCK_REFUND]
if refund_tx.block_time is not None:
raw_sequence = ci_from.getExpectedSequence(offer.lock_type, offer.lock_value)
seconds_locked = ci_from.decodeSequence(raw_sequence)
data['coin_a_lock_refund_swipe_tx_est_final'] = refund_tx.block_time + seconds_locked
if view_tx_ind: if view_tx_ind:
data['view_tx_ind'] = view_tx_ind data['view_tx_ind'] = view_tx_ind
view_tx_id = bytes.fromhex(view_tx_ind) view_tx_id = bytes.fromhex(view_tx_ind)