-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebserver.py
executable file
·82 lines (60 loc) · 2.48 KB
/
webserver.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# Specter Node
# Nick Frichette 12/9/2017
import argparse
from flask import Flask
from flask import jsonify
from flask import request
from flask import render_template
from node import *
from wallet import *
app = Flask(__name__)
# ANSI escape sequences
FAIL = '\033[91m'
END = '\033[0m'
OK = '\033[92m'
@app.route('/')
def index():
return render_template("index.html")
@app.route('/', methods=['POST'])
def receive_tranactions():
transaction = request.get_json()
# We just received data from a wallet or node. We now need to
# package it into a block and add it to the blockchain. First
# We must validate it.
blockchain.add_transaction_to_pool(transaction)
return 'Confirmation'
@app.route('/getblockchain', methods=['GET'])
def getblockchain():
return jsonify(blockchain.jsonify())
def print_ascii():
print " _______ _______ _______ _______ _________ _______ _______ __________ _______"
print "( ____ \( ____ )( ____ \( ____ \\\__ __/( ____ \( ____ ) / _ _ \\ / \\"
print "| ( \/| ( )|| ( \/| ( \/ ) ( | ( \/| ( )| | |_| |_| | | BOO |"
print "| (_____ | (____)|| (__ | | | | | (__ | (____)| | | | _____/"
print "(_____ )| _____)| __) | | | | | __) | __) | __ | / /"
print " ) || ( | ( | | | | | ( | (\ ( | (__) | "
print "/\____) || ) | (____/\| (____/\ | | | (____/\| ) \ \__ | | "
print "\_______)|/ (_______/(_______/ )_( (_______/|/ \__/ |/\\/\\/\\/\\/\\| "
if __name__ == '__main__':
# Take in CLI Arguments
parser = argparse.ArgumentParser(description="Node and Web Server for Specter")
parser.add_argument('-p',
metavar='Port Number',
help="Run the Web Server on a non-standard port",
type=int,
default=5000)
args = parser.parse_args()
# Print some pretty art
print "\033[H\033[J\r",
print_ascii()
# Spawn out own node and get blockchain
node = Node()
blockchain = node.blockchain
wallet = node.wallet
if wallet is None:
print FAIL + 'No wallet detected. Let\'s generate one' + END
print OK + "Creating nodekey" + END
wallet = Wallet('nodekey')
print "Node Wallet Address: " + wallet.get_address()
app.run(host='0.0.0.0', port=args.p)