diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 05c28b4..3266043 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -1187,11 +1187,16 @@ class BasicSwap(BaseApp): if ci.isWalletLocked(): raise LockedCoinError(Coins.PART) + def isCoinActive(self, c) -> bool: + if c not in chainparams: + return False + if self.coin_clients[c]["connection_type"] == "rpc": + return True + return False + def activeCoins(self): for c in Coins: - if c not in chainparams: - continue - if self.coin_clients[c]["connection_type"] == "rpc": + if self.isCoinActive(c): yield c def getListOfWalletCoins(self): @@ -1335,9 +1340,7 @@ class BasicSwap(BaseApp): identity_stats = self.queryOne(KnownIdentity, cursor, {"address": addr}) if not identity_stats: identity_stats = KnownIdentity( - active_ind=1, - address=addr, - created_at=self.getTime() + active_ind=1, address=addr, created_at=self.getTime() ) is_offer_creator = addr == offer.addr_from if bid.state == BidStates.SWAP_COMPLETED: @@ -1347,11 +1350,13 @@ class BasicSwap(BaseApp): else: old_value = zeroIfNone(identity_stats.num_sent_bids_successful) identity_stats.num_sent_bids_successful = old_value + 1 - elif bid.state in (BidStates.BID_ERROR, - BidStates.XMR_SWAP_FAILED_REFUNDED, - BidStates.XMR_SWAP_FAILED_SWIPED, - BidStates.XMR_SWAP_FAILED, - BidStates.SWAP_TIMEDOUT): + elif bid.state in ( + BidStates.BID_ERROR, + BidStates.XMR_SWAP_FAILED_REFUNDED, + BidStates.XMR_SWAP_FAILED_SWIPED, + BidStates.XMR_SWAP_FAILED, + BidStates.SWAP_TIMEDOUT, + ): if is_offer_creator: old_value = zeroIfNone(identity_stats.num_recv_bids_failed) identity_stats.num_recv_bids_failed = old_value + 1 @@ -8771,7 +8776,7 @@ class BasicSwap(BaseApp): try: chain_height = ci_to.getChainHeight() - lock_tx_depth = (chain_height - bid.xmr_b_lock_tx.chain_height) + lock_tx_depth = chain_height - bid.xmr_b_lock_tx.chain_height if lock_tx_depth < ci_to.depth_spendable(): raise TemporaryError( f"Chain B lock tx still confirming {lock_tx_depth} / {ci_to.depth_spendable()}." @@ -10416,7 +10421,7 @@ class BasicSwap(BaseApp): for row in q: coin_id = row[0] - if self.coin_clients[coin_id]["connection_type"] != "rpc": + if self.isCoinActive(coin_id) is False: # Skip cached info if coin was disabled continue diff --git a/basicswap/js_server.py b/basicswap/js_server.py index f9a887e..6cb6001 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -250,7 +250,8 @@ def js_offers(self, url_split, post_string, is_json, sent=False) -> bytes: "is_expired": o.expire_at <= swap_client.getTime(), "is_own_offer": o.was_sent, "is_revoked": True if o.active_ind == 2 else False, - "is_public": o.addr_to == swap_client.network_addr or o.addr_to.strip() == "", + "is_public": o.addr_to == swap_client.network_addr + or o.addr_to.strip() == "", } if with_extra_info: offer_data["amount_negotiable"] = o.amount_negotiable @@ -660,17 +661,50 @@ def js_identities(self, url_split, post_string: str, is_json: bool) -> bytes: address = url_split[3] identity = swap_client.getIdentity(address) if identity: - return bytes(json.dumps({ - "label": identity.label if identity.label is not None else "", - "note": identity.note if identity.note is not None else "", - "automation_override": identity.automation_override if identity.automation_override is not None else 0, - "num_sent_bids_successful": identity.num_sent_bids_successful if identity.num_sent_bids_successful is not None else 0, - "num_recv_bids_successful": identity.num_recv_bids_successful if identity.num_recv_bids_successful is not None else 0, - "num_sent_bids_rejected": identity.num_sent_bids_rejected if identity.num_sent_bids_rejected is not None else 0, - "num_recv_bids_rejected": identity.num_recv_bids_rejected if identity.num_recv_bids_rejected is not None else 0, - "num_sent_bids_failed": identity.num_sent_bids_failed if identity.num_sent_bids_failed is not None else 0, - "num_recv_bids_failed": identity.num_recv_bids_failed if identity.num_recv_bids_failed is not None else 0 - }), "UTF-8") + return bytes( + json.dumps( + { + "label": identity.label if identity.label is not None else "", + "note": identity.note if identity.note is not None else "", + "automation_override": ( + identity.automation_override + if identity.automation_override is not None + else 0 + ), + "num_sent_bids_successful": ( + identity.num_sent_bids_successful + if identity.num_sent_bids_successful is not None + else 0 + ), + "num_recv_bids_successful": ( + identity.num_recv_bids_successful + if identity.num_recv_bids_successful is not None + else 0 + ), + "num_sent_bids_rejected": ( + identity.num_sent_bids_rejected + if identity.num_sent_bids_rejected is not None + else 0 + ), + "num_recv_bids_rejected": ( + identity.num_recv_bids_rejected + if identity.num_recv_bids_rejected is not None + else 0 + ), + "num_sent_bids_failed": ( + identity.num_sent_bids_failed + if identity.num_sent_bids_failed is not None + else 0 + ), + "num_recv_bids_failed": ( + identity.num_recv_bids_failed + if identity.num_recv_bids_failed is not None + else 0 + ), + } + ), + "UTF-8", + ) return bytes(json.dumps({}), "UTF-8") filters = {