Fix manual spendchainblocktx through GUI
Some checks failed
lint / build (3.12) (push) Has been cancelled

This commit is contained in:
tecnovert 2024-10-25 21:28:20 +02:00
parent 3cab753398
commit e23216df07
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
3 changed files with 25 additions and 13 deletions

View file

@ -3945,7 +3945,11 @@ class BasicSwap(BaseApp):
if bid.xmr_b_lock_tx and bid.xmr_b_lock_tx.chain_height is not None and bid.xmr_b_lock_tx.chain_height > 0:
chain_height = ci_to.getChainHeight()
if chain_height - bid.xmr_b_lock_tx.chain_height >= ci_to.blocks_confirmed:
if bid.debug_ind == DebugTypes.BID_STOP_AFTER_COIN_B_LOCK:
self.log.debug('Adaptor-sig bid %s: Stalling bid for testing: %d.', bid_id.hex(), bid.debug_ind)
bid.setState(BidStates.BID_STALLED_FOR_TEST)
self.logBidEvent(bid.bid_id, EventLogTypes.DEBUG_TWEAK_APPLIED, 'ind {}'.format(bid.debug_ind), session)
elif chain_height - bid.xmr_b_lock_tx.chain_height >= ci_to.blocks_confirmed:
self.logBidEvent(bid.bid_id, EventLogTypes.LOCK_TX_B_CONFIRMED, '', session)
bid.xmr_b_lock_tx.setState(TxStates.TX_CONFIRMED)
bid.setState(BidStates.XMR_SWAP_NOSCRIPT_COIN_LOCKED)
@ -5789,7 +5793,10 @@ class BasicSwap(BaseApp):
xmr_swap.b_lock_tx_id = b_lock_tx_id
bid.xmr_b_lock_tx.setState(TxStates.TX_SENT)
self.logBidEvent(bid.bid_id, EventLogTypes.LOCK_TX_B_PUBLISHED, '', session)
if bid.debug_ind == DebugTypes.BID_STOP_AFTER_COIN_B_LOCK:
self.log.debug('Adaptor-sig bid %s: Stalling bid for testing: %d.', bid_id.hex(), bid.debug_ind)
bid.setState(BidStates.BID_STALLED_FOR_TEST)
self.logBidEvent(bid.bid_id, EventLogTypes.DEBUG_TWEAK_APPLIED, 'ind {}'.format(bid.debug_ind), session)
self.saveBidInSession(bid_id, bid, session, xmr_swap, save_in_progress=offer)
def sendXmrBidLockRelease(self, bid_id: bytes, session) -> None:
@ -6233,6 +6240,10 @@ class BasicSwap(BaseApp):
ensure(bid, 'Bid not found: {}.'.format(bid_id.hex()))
ensure(xmr_swap, 'Adaptor-sig swap not found: {}.'.format(bid_id.hex()))
if BidStates(bid.state) == BidStates.BID_STALLED_FOR_TEST:
self.log.debug('Bid stalled %s', bid_id.hex())
return
offer, xmr_offer = self.getXmrOffer(bid.offer_id, sent=False)
ensure(offer, 'Offer not found: {}.'.format(bid.offer_id.hex()))
ensure(xmr_offer, 'Adaptor-sig offer not found: {}.'.format(bid.offer_id.hex()))
@ -6655,7 +6666,7 @@ class BasicSwap(BaseApp):
has_changed = True
if data.get('kbs_other', None) is not None:
return xmr_swap_1.recoverNoScriptTxnWithKey(self, bid_id, data['kbs_other'])
return xmr_swap_1.recoverNoScriptTxnWithKey(self, bid_id, data['kbs_other'], session)
if has_changed:
activate_bid = False

View file

@ -204,6 +204,7 @@ class DebugTypes(IntEnum):
DUPLICATE_ACTIONS = auto()
DONT_CONFIRM_PTX = auto()
OFFER_LOCK_2_VALUE_INC = auto()
BID_STOP_AFTER_COIN_B_LOCK = auto()
class NotificationTypes(IntEnum):

View file

@ -40,15 +40,15 @@ def addLockRefundSigs(self, xmr_swap, ci):
xmr_swap.a_lock_refund_tx = signed_tx
def recoverNoScriptTxnWithKey(self, bid_id: bytes, encoded_key):
def recoverNoScriptTxnWithKey(self, bid_id: bytes, encoded_key, session=None):
self.log.info('Manually recovering %s', bid_id.hex())
# Manually recover txn if other key is known
session = self.openSession()
try:
bid, xmr_swap = self.getXmrBidFromSession(session, bid_id)
use_session = self.openSession(session)
bid, xmr_swap = self.getXmrBidFromSession(use_session, bid_id)
ensure(bid, 'Bid not found: {}.'.format(bid_id.hex()))
ensure(xmr_swap, 'Adaptor-sig swap not found: {}.'.format(bid_id.hex()))
offer, xmr_offer = self.getXmrOfferFromSession(session, bid.offer_id, sent=False)
offer, xmr_offer = self.getXmrOfferFromSession(use_session, bid.offer_id, sent=False)
ensure(offer, 'Offer not found: {}.'.format(bid.offer_id.hex()))
ensure(xmr_offer, 'Adaptor-sig offer not found: {}.'.format(bid.offer_id.hex()))
ci_to = self.ci(offer.coin_to)
@ -71,20 +71,20 @@ def recoverNoScriptTxnWithKey(self, bid_id: bytes, encoded_key):
vkbs = ci_to.sumKeys(kbsl, kbsf)
if offer.coin_to == Coins.XMR:
address_to = self.getCachedMainWalletAddress(ci_to)
address_to = self.getCachedMainWalletAddress(ci_to, use_session)
else:
address_to = self.getCachedStealthAddressForCoin(offer.coin_to)
address_to = self.getCachedStealthAddressForCoin(offer.coin_to, use_session)
amount = bid.amount_to
lock_tx_vout = bid.getLockTXBVout()
txid = ci_to.spendBLockTx(xmr_swap.b_lock_tx_id, address_to, xmr_swap.vkbv, vkbs, amount, xmr_offer.b_fee_rate, bid.chain_b_height_start, spend_actual_balance=True, lock_tx_vout=lock_tx_vout)
self.log.debug('Submitted lock B spend txn %s to %s chain for bid %s', txid.hex(), ci_to.coin_name(), bid_id.hex())
self.logBidEvent(bid.bid_id, EventLogTypes.LOCK_TX_B_SPEND_TX_PUBLISHED, txid.hex(), session)
session.commit()
self.logBidEvent(bid.bid_id, EventLogTypes.LOCK_TX_B_SPEND_TX_PUBLISHED, txid.hex(), use_session)
use_session.commit()
return txid
finally:
self.closeSession(session, commit=False)
if session is None:
self.closeSession(use_session, commit=False)
def getChainBSplitKey(swap_client, bid, xmr_swap, offer):