Gestion erreurs lors d'une transaction
This commit is contained in:
parent
6964bcd702
commit
eaba0f2a54
34
run.py
34
run.py
@ -19,7 +19,7 @@ logging.basicConfig(level=logging.ERROR,
|
|||||||
class NoAccountError(Exception):
|
class NoAccountError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class BalanceError(Exception):
|
class NotEnoughDoge(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class AccountExisting(Exception):
|
class AccountExisting(Exception):
|
||||||
@ -62,22 +62,18 @@ def transaction(sender, receiver, amount):
|
|||||||
address_receiver = get_address(receiver)
|
address_receiver = get_address(receiver)
|
||||||
return block_io.withdraw_from_labels(amounts=amount, from_labels=sender, to_labels=receiver, priority="low")
|
return block_io.withdraw_from_labels(amounts=amount, from_labels=sender, to_labels=receiver, priority="low")
|
||||||
else:
|
else:
|
||||||
return "Pas assez de doge"
|
raise NotEnoughDoge
|
||||||
except NoAccountError as e:
|
except NoAccountError:
|
||||||
return "Merci de vous créer un compte @" + str(e)
|
raise
|
||||||
except BlockIoAPIError:
|
|
||||||
return "Erreur d'API"
|
|
||||||
|
|
||||||
def address_transaction(account, address, amount):
|
def address_transaction(account, address, amount):
|
||||||
try:
|
try:
|
||||||
if get_balance(account)[0] > amount:
|
if get_balance(account)[0] > amount:
|
||||||
return block_io.withdraw_from_labels(amounts=amount, from_labels=account, to_addresses=address, priority="low")
|
return block_io.withdraw_from_labels(amounts=amount, from_labels=account, to_addresses=address, priority="low")
|
||||||
else:
|
else:
|
||||||
return "Pas assez de doge"
|
return NotEnoughDoge
|
||||||
except NoAccountError as e:
|
except NoAccountError:
|
||||||
return "Merci de vous créer un compte @" + str(e)
|
raise
|
||||||
except BlockIoAPIError:
|
|
||||||
return "Erreur d'API"
|
|
||||||
|
|
||||||
# Telegram functions
|
# Telegram functions
|
||||||
|
|
||||||
@ -89,14 +85,16 @@ def dogetip(bot, update, args):
|
|||||||
unit = args[1]
|
unit = args[1]
|
||||||
destinataire = args[2][1:]
|
destinataire = args[2][1:]
|
||||||
|
|
||||||
if unit == "doge":
|
|
||||||
response = transaction(update.message.from_user.username, destinataire, montant)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
txid = response['data']['txid']
|
if unit == "doge":
|
||||||
except TypeError:
|
response = transaction(update.message.from_user.username, destinataire, montant)
|
||||||
message = response
|
except NotEnoughDoge:
|
||||||
|
message = "Pas assez de doge @" + update.message.from_user.username
|
||||||
|
except NoAccountError as e:
|
||||||
|
message = "Vous n'avez pas de compte @" + e + '\n\n' \
|
||||||
|
+ "Utilisez /register pour démarrer"
|
||||||
else:
|
else:
|
||||||
|
txid = response['data']['txid']
|
||||||
message = '🚀 Transaction effectuée 🚀\n\n' \
|
message = '🚀 Transaction effectuée 🚀\n\n' \
|
||||||
+ str(montant) + ' ' + NETWORK + '\n' \
|
+ str(montant) + ' ' + NETWORK + '\n' \
|
||||||
+ '@' + update.message.from_user.username + ' → @' + destinataire + '\n\n' \
|
+ '@' + update.message.from_user.username + ' → @' + destinataire + '\n\n' \
|
||||||
@ -117,7 +115,7 @@ def infos(bot, update):
|
|||||||
address = get_address(update.message.from_user.username)
|
address = get_address(update.message.from_user.username)
|
||||||
balance, unconfirmed_balance = get_balance(update.message.from_user.username)
|
balance, unconfirmed_balance = get_balance(update.message.from_user.username)
|
||||||
except NoAccountError as e:
|
except NoAccountError as e:
|
||||||
bot.send_message(chat_id=update.message.chat_id, text="Merci de vous créer un compte @" + str(e))
|
bot.send_message(chat_id=update.message.chat_id, text="Vous n'avez pas de compte @" + e + '\n\n' + "Utilisez /register pour démarrer")
|
||||||
else:
|
else:
|
||||||
bot.send_message(chat_id=update.message.chat_id, text=address + "\n\n" + str(balance) + " " + NETWORK + "\n" + str(unconfirmed_balance) + " " + NETWORK + " unconfirmed")
|
bot.send_message(chat_id=update.message.chat_id, text=address + "\n\n" + str(balance) + " " + NETWORK + "\n" + str(unconfirmed_balance) + " " + NETWORK + " unconfirmed")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user