From 483d77a0c6abda5eb2b51e7ce564063bf9ad3745 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Thu, 15 Feb 2024 00:00:54 +0200 Subject: [PATCH] Fix revoke ttl too low. Remove XMR fee warnings. --- basicswap/basicswap.py | 14 ++++++++------ basicswap/interface/xmr.py | 13 ++++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index ec9d35a..8ed3a8e 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -1622,7 +1622,7 @@ class BasicSwap(BaseApp): offer_bytes = msg_buf.SerializeToString() payload_hex = str.format('{:02x}', MessageTypes.OFFER) + offer_bytes.hex() - msg_valid: int = max(self.SMSG_SECONDS_IN_HOUR * 1, valid_for_seconds) + msg_valid: int = max(self.SMSG_SECONDS_IN_HOUR, valid_for_seconds) offer_id = self.sendSmsg(offer_addr, offer_addr_to, payload_hex, msg_valid) security_token = extra_options.get('security_token', None) @@ -1717,7 +1717,9 @@ class BasicSwap(BaseApp): msg_bytes = msg_buf.SerializeToString() payload_hex = str.format('{:02x}', MessageTypes.OFFER_REVOKE) + msg_bytes.hex() - msg_id = self.sendSmsg(offer.addr_from, self.network_addr, payload_hex, offer.time_valid) + + msg_valid: int = max(self.SMSG_SECONDS_IN_HOUR, offer.time_valid) + msg_id = self.sendSmsg(offer.addr_from, self.network_addr, payload_hex, msg_valid) self.log.debug('Revoked offer %s in msg %s', offer_id.hex(), msg_id.hex()) finally: self.closeSession(session, commit=False) @@ -1902,7 +1904,7 @@ class BasicSwap(BaseApp): def estimateWithdrawFee(self, coin_type, fee_rate): if coin_type == Coins.XMR: - self.log.error('TODO: estimateWithdrawFee XMR') + # Fee estimate must be manually initiated return None tx_vsize = self.ci(coin_type).getHTLCSpendTxVSize() est_fee = (fee_rate * tx_vsize) / 1000 @@ -2298,7 +2300,7 @@ class BasicSwap(BaseApp): payload_hex = str.format('{:02x}', MessageTypes.BID) + bid_bytes.hex() bid_addr = self.newSMSGAddress(use_type=AddressTypes.BID)[0] if addr_send_from is None else addr_send_from - msg_valid: int = max(self.SMSG_SECONDS_IN_HOUR * 1, valid_for_seconds) + msg_valid: int = max(self.SMSG_SECONDS_IN_HOUR, valid_for_seconds) bid_id = self.sendSmsg(bid_addr, offer.addr_from, payload_hex, msg_valid) bid = Bid( @@ -2657,7 +2659,7 @@ class BasicSwap(BaseApp): xmr_swap.contract_count = self.getNewContractId() bid_addr = self.newSMSGAddress(use_type=AddressTypes.BID)[0] if addr_send_from is None else addr_send_from - msg_valid: int = max(self.SMSG_SECONDS_IN_HOUR * 1, valid_for_seconds) + msg_valid: int = max(self.SMSG_SECONDS_IN_HOUR, valid_for_seconds) xmr_swap.bid_id = self.sendSmsg(bid_addr, offer.addr_from, payload_hex, msg_valid) bid = Bid( @@ -2743,7 +2745,7 @@ class BasicSwap(BaseApp): payload_hex = str.format('{:02x}', MessageTypes.XMR_BID_FL) + bid_bytes.hex() bid_addr = self.newSMSGAddress(use_type=AddressTypes.BID)[0] if addr_send_from is None else addr_send_from - msg_valid: int = max(self.SMSG_SECONDS_IN_HOUR * 1, valid_for_seconds) + msg_valid: int = max(self.SMSG_SECONDS_IN_HOUR, valid_for_seconds) xmr_swap.bid_id = self.sendSmsg(bid_addr, offer.addr_from, payload_hex, msg_valid) bid_msg_ids = {} diff --git a/basicswap/interface/xmr.py b/basicswap/interface/xmr.py index ab2a67e..d9c926f 100644 --- a/basicswap/interface/xmr.py +++ b/basicswap/interface/xmr.py @@ -76,7 +76,7 @@ class XMRInterface(CoinInterface): @staticmethod def xmr_swap_b_lock_spend_tx_vsize() -> int: # TODO: Estimate with ringsize - return 1507 + return 1604 def __init__(self, coin_settings, network, swap_client=None): super().__init__(network) @@ -254,8 +254,15 @@ class XMRInterface(CoinInterface): return new_address def get_fee_rate(self, conf_target: int = 2): - self._log.warning('TODO - estimate XMR fee rate?') - return 0.0, 'unused' + # fees - array of unsigned int; Represents the base fees at different priorities [slow, normal, fast, fastest]. + fee_est = self.rpc('get_fee_estimate') + if conf_target <= 1: + conf_target = 1 # normal + else: + conf_target = 0 # slow + fee_per_k_bytes = fee_est['fees'][conf_target] * 1000 + + return float(self.format_amount(fee_per_k_bytes)), 'get_fee_estimate' def getNewSecretKey(self) -> bytes: # Note: Returned bytes are in big endian order