-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
49 lines (42 loc) · 1.29 KB
/
views.py
File metadata and controls
49 lines (42 loc) · 1.29 KB
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
from flask import render_template
from flask import request,jsonify
import json,os
from BitCrumbs import app
import pymysql as mdb
from transaction_graph2 import TransactionGraph
con = mdb.connect('localhost','root','password','bitcoin')
@app.route('/')
@app.route('/index')
def index():
return render_template("index.html")
@app.route('/bitcoinFlow')
def bitcoinFlow():
address = request.args.get('address', 'error', type=str)
#print address.split(',')
graph = TransactionGraph()
graph.addSourceAddress(address.split(',')[0])
result = jsonify(graph.toDict())
graph.clear()
return result
@app.route('/addresses')
def addresses():
address_query = request.args.get('q','',type=str)
command = 'SELECT DISTINCT address FROM tx_outputs '
command += 'WHERE spendHash NOT LIKE "Unspent" '
command += 'AND value > 10000 '
command += 'AND address LIKE "%s%%" LIMIT 10' % address_query
try:
with con:
cur = con.cursor()
cur.execute(command)
results = cur.fetchall()
except: # assuming this is "internal server error."
con = mdb.connect('localhost','root','password','bitcoin')
with con:
cur = con.cursor()
cur.execute(command)
results = cur.fetchall()
address_list = []
for result in results:
address_list.append({'id':result[0],'name':result[0]})
return json.dumps(address_list)