You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
4 years ago
|
import logging
|
||
|
from decimal import Decimal
|
||
|
from tipbot import wownero
|
||
|
from tipbot import db
|
||
|
from tipbot.helpers.decorators import wallet_rpc_required, log_event, registration_required
|
||
|
|
||
|
|
||
|
@wallet_rpc_required
|
||
|
@registration_required
|
||
|
@log_event
|
||
|
def withdraw(update, context):
|
||
|
if len(context.args) < 2:
|
||
|
update.message.reply_text('Not enough arguments passed.')
|
||
|
return False
|
||
|
|
||
|
# validate address
|
||
|
if len(context.args[0]) in [97, 108]:
|
||
|
address = context.args[0]
|
||
|
else:
|
||
|
update.message.reply_text('This does not look like a valid Wownero address. Try again.')
|
||
|
return False
|
||
|
|
||
|
# validate amount
|
||
|
try:
|
||
|
amount = Decimal(context.args[1])
|
||
|
except:
|
||
|
update.message.reply_text(f'Bad Wownero amount specified; not a valid number.')
|
||
|
return False
|
||
|
|
||
|
if amount < 1:
|
||
|
update.message.reply_text('Bad Wownero amount specified. Provide only positive integers or decimals greater than or equal to 1.')
|
||
|
return False
|
||
|
|
||
|
sender = db.User.get(telegram_id=update.message.from_user['id'])
|
||
|
sender_balances = wownero.Wallet().balances(account=sender.account_index)
|
||
|
if amount > sender_balances[1]:
|
||
|
update.message.reply_text(f'You do not have sufficient funds to send {amount} WOW. Check your /balance')
|
||
|
return False
|
||
|
|
||
|
# transfer funds to given address
|
||
|
try:
|
||
|
tx = wownero.Wallet().transfer(dest_address=address, amount=wownero.as_wownero(amount), priority=2, account=sender.account_index)
|
||
|
if 'tx_hash' in tx:
|
||
|
h = tx['tx_hash']
|
||
|
update.message.reply_text(f'Sent {amount} WOW! TX ID: [{h}](https://wownero.xmrauctions.com/transaction/{h})')
|
||
|
else:
|
||
|
update.message.reply_text('Failed to send Wownero. Ask for help.')
|
||
|
except Exception as e:
|
||
|
logging.error(f'Unable to send transfer: {e}. Debug: {update.message}')
|
||
|
update.message.reply_text('Failed to send Wownero. Ask for help.')
|