Fail with more descriptive error when processing message involving inactive coin.

This commit is contained in:
tecnovert 2022-10-12 22:37:35 +02:00
parent 3ed6781c9f
commit c7bbdc7022
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
3 changed files with 24 additions and 4 deletions

View file

@ -1,3 +1,3 @@
name = "basicswap"
__version__ = "0.11.37"
__version__ = "0.11.38"

View file

@ -39,6 +39,7 @@ from . import __version__
from .rpc_xmr import make_xmr_rpc2_func
from .util import (
TemporaryError,
InactiveCoin,
AutomationConstraint,
format_amount,
format_timestamp,
@ -473,11 +474,21 @@ class BasicSwap(BaseApp):
raise ValueError('Failed to select a working XMR daemon url.')
def ci(self, coin): # Coin interface
use_coinid = coin
interface_ind = 'interface'
if coin == Coins.PART_ANON:
return self.coin_clients[Coins.PART]['interface_anon']
use_coinid = Coins.PART
interface_ind = 'interface_anon'
if coin == Coins.PART_BLIND:
return self.coin_clients[Coins.PART]['interface_blind']
return self.coin_clients[coin]['interface']
use_coinid = Coins.PART
interface_ind = 'interface_blind'
if use_coinid not in self.coin_clients:
raise ValueError('Unknown coinid {}'.format(int(coin)))
if interface_ind not in self.coin_clients[use_coinid]:
raise InactiveCoin(int(coin))
return self.coin_clients[use_coinid][interface_ind]
def createInterface(self, coin):
if coin == Coins.PART:
@ -4996,6 +5007,8 @@ class BasicSwap(BaseApp):
if msg_type == MessageTypes.OFFER_REVOKE:
self.processOfferRevoke(msg)
except InactiveCoin as ex:
self.log.info('Ignoring message involving inactive coin {}, type {}'.format(Coins(ex.coinid).name, MessageTypes(msg_type).name))
except Exception as ex:
self.log.error('processMsg %s', str(ex))
if self.debug:

View file

@ -25,6 +25,13 @@ class AutomationConstraint(ValueError):
pass
class InactiveCoin(Exception):
def __init__(self, coinid):
self.coinid = coinid
def __str__(self):
return str(self.coinid)
def ensure(v, err_string):
if not v:
raise ValueError(err_string)