Validate payment-acct-id and shutdown a bit more cleanly

This commit is contained in:
ghubstan 2022-03-26 19:23:37 -03:00
parent 40a0295614
commit a578ac2b33
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
3 changed files with 32 additions and 0 deletions

View File

@ -396,5 +396,23 @@ class BisqClient(object):
currency_code,
payment_details)
def get_payment_account(self, payment_account_id):
try:
response = self.payment_accts_stub.GetPaymentAccounts.with_call(
bisq_messages.GetPaymentAccountsRequest(),
metadata=[('password', self.api_password)])
payment_accounts = list(response[0].payment_accounts)
if len(payment_accounts):
payment_accounts_filter = filter(lambda account: (account.id == payment_account_id), payment_accounts)
filtered_accounts = list(payment_accounts_filter)
if len(filtered_accounts):
return filtered_accounts[0]
else:
return None
else:
return None
except grpc.RpcError as rpc_error:
print('gRPC API Exception: %s', rpc_error)
def __str__(self):
return 'host=' + self.host + ' port=' + self.port + ' api_password=' + '*****'

View File

@ -69,6 +69,14 @@ class SepaMMBot(BisqClient):
self.close_channel()
self.is_running = False
def is_valid_sepa_payment_account_id(self, sepa_payment_account_id):
account = self.get_payment_account(sepa_payment_account_id)
if account is None:
log.error('{0} is not a valid PaymentAccount.id.'.format(sepa_payment_account_id))
return False
else:
return True
def make_market(self, reference_price_margin,
target_spread,
amount_in_satoshis,

View File

@ -70,6 +70,12 @@ def start():
def start_bot():
payment_account_exists = bot.is_valid_sepa_payment_account_id(sepa_payment_account_id)
if payment_account_exists is False:
window.quit()
log.error('Shutting down UI.')
return
disable_button(start_button)
enable_button(stop_button)
reference_price_margin = Decimal(price_margin_input.get())