wiring up transfers and sweeps

mm-logging
lza_menace 4 years ago
parent bb6997e7a4
commit 000e611b14

@ -110,6 +110,13 @@ def status():
def send():
send_form = Send()
redirect_url = url_for('wallet.dashboard') + '#send'
wallet = Wallet(
proto='http',
host='127.0.0.1',
port=current_user.wallet_port,
username=current_user.id,
password=current_user.wallet_password
)
if send_form.validate_on_submit():
address = str(send_form.address.data)
user = User.query.get(current_user.id)
@ -119,43 +126,32 @@ def send():
flash('Wallet RPC interface is unavailable at this time. Try again later.')
return redirect(redirect_url)
# Check if user funds flag is locked
if current_user.funds_locked:
flash('You currently have transactions pending and transfers are locked. Try again later.')
return redirect(redirect_url)
# Quick n dirty check to see if address is WOW
if len(address) not in [97, 108]:
flash('Invalid Wownero address provided.')
return redirect(redirect_url)
# Make sure the amount provided is a number
try:
amount = to_atomic(Decimal(send_form.amount.data))
except:
flash('Invalid Wownero amount specified.')
return redirect(redirect_url)
# Make sure the amount does not exceed the balance
if amount >= user.balance:
flash('Not enough funds to transfer that much.')
return redirect(redirect_url)
# Lock user funds
user.funds_locked = True
db.session.commit()
# Queue the transaction
tx = TransferQueue(
user=user.id,
address=address,
amount=amount
)
db.session.add(tx)
db.session.commit()
# Check if we're sweeping or not
if send_form.amount.data == 'all':
tx = wallet.transfer(address, None, 'sweep_all')
else:
# Make sure the amount provided is a number
try:
amount = to_atomic(Decimal(send_form.amount.data))
except:
flash('Invalid Wownero amount specified.')
return redirect(redirect_url)
# Send transfer
tx = wallet.transfer(address, amount)
# Inform user of result and redirect
if 'message' in tx:
msg = tx['message'].capitalize()
flash(f'There was a problem sending the transaction: {msg}')
else:
flash('Successfully sent transfer.')
# Redirect back
flash('Successfully queued transfer.')
return redirect(redirect_url)
else:
for field, errors in send_form.errors.items():

@ -16,4 +16,4 @@ class Login(FlaskForm):
class Send(FlaskForm):
address = StringField('Destination Address:', validators=[DataRequired()], render_kw={"placeholder": "Wownero address", "class": "form-control"})
amount = StringField('Amount:', validators=[DataRequired()], render_kw={"placeholder": "Amount to send", "class": "form-control"})
amount = StringField('Amount:', validators=[DataRequired()], render_kw={"placeholder": "Amount to send or \"all\"", "class": "form-control"})

@ -42,7 +42,7 @@ class Docker(object):
def start_wallet(self, user_id):
u = User.query.get(user_id)
container_name = f'start_wallet_{u.id}'
container_name = f'rpc_wallet_{u.id}'
command = f"""wownero-wallet-rpc \
--non-interactive \
--rpc-bind-port {self.listen_port} \

@ -84,11 +84,9 @@ class Wallet(JSONRPC):
}
return self.make_rpc('get_transfers', data)
def transfer(self, account_index, subaddress_index, dest_address, amount):
def transfer(self, dest_address, atomic_amount, type='transfer', account_index=0):
data = {
'account_index': account_index,
'subaddr_indices': [subaddress_index],
'destinations': [{'address': dest_address, 'amount': to_atomic(amount)}],
'priority': 0,
'unlock_time': 0,
'get_tx_key': True,
@ -97,7 +95,15 @@ class Wallet(JSONRPC):
'do_not_relay': False,
'ring_size': 22
}
transfer = self.make_rpc('transfer', data)
if type == 'sweep_all':
data['address'] = dest_address
transfer = self.make_rpc('sweep_all', data)
else:
data['destinations'] = [{
'address': dest_address,
'amount': atomic_amount
}]
transfer = self.make_rpc('transfer', data)
return transfer

@ -103,7 +103,7 @@
<div class="container">
<div class="section-heading text-center">
<h2>Secrets</h2>
<p>You need to save the secrets below; write them down on a physical medium and keep it in a safe location. These can be used to restore your funds to another device in the future.</p>
<p>You need to save the secrets below; write them down on a physical medium and keep it in a safe location. These can be used to restore your funds to another device in the future when you decide to quit being a bitch and use a real wallet.</p>
<hr><br>
<h3>Mnemonic Seed</h3>
<p class="small">{{ seed }}</p>