-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroutes.py
62 lines (53 loc) · 2.15 KB
/
routes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from flask import render_template, request, redirect, url_for, abort
from server import app
from src.blockchain import *
from src.smartContract import *
from src.wallet import *
from src.User import *
blockchain = Blockchain()
smartContract = Contract(30000,[0.2,0.5,1])
walletObj = Wallet()
idObj = User()
recentDonations = []
@app.route('/')
def index():
return render_template('index.html')
@app.route('/luminary')
def founderIndex():
return render_template('project.html', role='founder', id=idObj,blockchain=blockchain, recentDonations=recentDonations[::-1], contract=smartContract)
@app.route('/project/addTransaction', methods=['GET', 'POST'])
def addTransaction():
if request.method == 'POST':
# add to blockchain function
category = request.form['category']
amount = request.form['amount']
sender = "John"
receiver = request.form['receiver']
transactionObj = Transaction(category, amount, sender, receiver)
print(transactionObj)
walletObj.spendMoney(int(amount), blockchain, transactionObj)
return render_template('addTransaction.html', wallet = walletObj)
@app.route('/project')
def project():
return render_template('project.html', id=idObj, role='user',blockchain=blockchain, recentDonations=recentDonations[::-1], contract=smartContract)
@app.route('/project/<id>/contribute', methods=['GET', 'POST'])
def projectContribute(id):
if request.method == "POST":
money = request.form['money']
print(f'Contributed ${money}')
smartContract.addMoney(int(money), walletObj)
print(smartContract.currentMoney)
print(walletObj.money)
recentDonations.append(money)
idObj.createTransaction(int(money))
return redirect(url_for('project'))
return render_template('contribute.html')
@app.route('/project/<id>/withdraw', methods=['GET', 'POST'])
def projectWithdraw(id):
smartContract.withdrawMoney(int(id), idObj)
print(smartContract.currentMoney)
return redirect(url_for('project'))
@app.route('/transactions')
def transactions():
# get blockchain
return render_template('transactions.html', blockchain=blockchain)