This repository has been archived by the owner on Mar 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
server.py
58 lines (43 loc) · 1.61 KB
/
server.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
#!/usr/bin/env python
import json
from flask import Flask, request
from flask_cors import CORS
from swarm_node import send_transfer, get_tips, generate_address
from extensions.tangleid import main as extension_tangleid
from utils import IotaJSONEncoder
PORT = 8000
app = Flask(__name__)
CORS(app)
@app.route('/')
def swarm_node_info():
response = {
'status': 'SUCCESS',
'data': 'Hello I am a swarm node.'
}
return json.dumps(response)
@app.route('/', methods=['POST'])
def execute_api():
request_data = request.get_data()
print("Get request data ... %s" % (str(request_data)))
request_command = json.loads(request_data)
if request_command['command'] == "generate_address":
address_result = generate_address()
result = json.dumps(address_result, cls=IotaJSONEncoder)
elif request_command['command'] == "get_tips":
tips_result = get_tips(int(request_command['type']))
result = json.dumps(tips_result, cls=IotaJSONEncoder)
elif request_command['command'] == "send_transfer":
if 'debug' not in request_command:
debug = 0
else:
debug = int(request_command['debug'])
dict_tips = get_tips(int(request_command['tips_type']))
result = send_transfer(
request_command['tag'], request_command['message'], request_command['address'], int(
request_command['value']), dict_tips, debug)
else:
result = extension_tangleid.load(request_data)
print("Result ... %s" % (str(result)))
return result
if __name__ == "__main__":
app.run(port=PORT, threaded=True)