wiring up transfers and sweeps

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

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

@ -16,4 +16,4 @@ class Login(FlaskForm):
class Send(FlaskForm): class Send(FlaskForm):
address = StringField('Destination Address:', validators=[DataRequired()], render_kw={"placeholder": "Wownero address", "class": "form-control"}) 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): def start_wallet(self, user_id):
u = User.query.get(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 \ command = f"""wownero-wallet-rpc \
--non-interactive \ --non-interactive \
--rpc-bind-port {self.listen_port} \ --rpc-bind-port {self.listen_port} \

@ -84,11 +84,9 @@ class Wallet(JSONRPC):
} }
return self.make_rpc('get_transfers', data) 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 = { data = {
'account_index': account_index, 'account_index': account_index,
'subaddr_indices': [subaddress_index],
'destinations': [{'address': dest_address, 'amount': to_atomic(amount)}],
'priority': 0, 'priority': 0,
'unlock_time': 0, 'unlock_time': 0,
'get_tx_key': True, 'get_tx_key': True,
@ -97,7 +95,15 @@ class Wallet(JSONRPC):
'do_not_relay': False, 'do_not_relay': False,
'ring_size': 22 '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 return transfer

@ -103,7 +103,7 @@
<div class="container"> <div class="container">
<div class="section-heading text-center"> <div class="section-heading text-center">
<h2>Secrets</h2> <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> <hr><br>
<h3>Mnemonic Seed</h3> <h3>Mnemonic Seed</h3>
<p class="small">{{ seed }}</p> <p class="small">{{ seed }}</p>