Final fix to refunds path, increase test coverage

This commit is contained in:
mainnet-pat
2024-10-30 05:37:01 +00:00
committed by tecnovert
parent b7da4f2096
commit a7c2fbba1f
3 changed files with 69 additions and 56 deletions

View File

@@ -3890,6 +3890,15 @@ class BasicSwap(BaseApp):
try:
txid = ci_from.publishTx(xmr_swap.a_lock_refund_tx)
# bch txids change
if self.isBchXmrSwap(offer):
self.log.debug('Recomputing refund spend transaction and txid after submitting lock tx spend.')
tx = ci_from.loadTx(xmr_swap.a_lock_refund_spend_tx)
tx.vin[0].prevout.hash = b2i(xmr_swap.a_lock_refund_tx_id)
xmr_swap.a_lock_refund_spend_tx = tx.serialize_without_witness()
xmr_swap.a_lock_refund_spend_tx_id = ci_from.getTxid(xmr_swap.a_lock_refund_spend_tx)
self.log.info('Submitted coin a lock refund tx for bid {}'.format(bid_id.hex()))
self.logBidEvent(bid.bid_id, EventLogTypes.LOCK_TX_A_REFUND_TX_PUBLISHED, '', session)
bid.txns[TxTypes.XMR_SWAP_A_LOCK_REFUND] = SwapTx(
@@ -4437,7 +4446,7 @@ class BasicSwap(BaseApp):
self.log.debug('Coin a lock tx spent by lock refund tx.')
# bch txids change
if self.isBchXmrSwap(offer):
self.log.debug('Recomputing refund spend transaction and txid after lock tx spend.')
self.log.debug('Recomputing refund spend transaction and txid after lock tx spent.')
xmr_swap.a_lock_refund_tx_id = spending_txid
xmr_swap.a_lock_refund_tx = bytes.fromhex(spend_txn_hex)
@@ -5823,7 +5832,7 @@ class BasicSwap(BaseApp):
lock_tx_signed = ci_from.signTxWithWallet(xmr_swap.a_lock_tx)
txid_hex = ci_from.publishTx(lock_tx_signed)
if txid_hex != b2h(xmr_swap.a_lock_tx_id):
self.log.info('Recomputing lock refund and lock spend transactions and txids after lock tx publish')
self.log.info('Recomputing refund transactions and txids after lock tx publish')
xmr_swap.a_lock_tx = lock_tx_signed
xmr_swap.a_lock_tx_id = bytes.fromhex(txid_hex)

View File

@@ -57,17 +57,15 @@ from coincurve.ecdsaotves import (
ecdsaotves_rec_enc_key,
)
def findOutput(tx, script_pk: bytes):
for i in range(len(tx.vout)):
if tx.vout[i].scriptPubKey == script_pk:
return i
return None
class BCHInterface(BTCInterface):
@staticmethod
def coin_type():
return Coins.BCH
@staticmethod
def xmr_swap_a_lock_spend_tx_vsize() -> int:
return 302
def __init__(self, coin_settings, network, swap_client=None):
super(BCHInterface, self).__init__(coin_settings, network, swap_client)
# No multiwallet support
@@ -85,6 +83,17 @@ class BCHInterface(BTCInterface):
args = [label]
return self.rpc_wallet('getnewaddress', args)
def getUnspentsByAddr(self):
unspent_addr = dict()
unspent = self.rpc_wallet('listunspent')
for u in unspent:
if u.get('spendable', False) is False:
continue
if 'address' not in u:
continue
unspent_addr[u['address']] = unspent_addr.get(u['address'], 0) + self.make_int(u['amount'], r=1)
return unspent_addr
# returns pkh
def decodeAddress(self, address: str) -> bytes:
return bytes(Address.from_string(address).payload)