-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathethereum.py
More file actions
163 lines (144 loc) · 5.79 KB
/
ethereum.py
File metadata and controls
163 lines (144 loc) · 5.79 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from flask import Flask, send_from_directory, jsonify, request
from flask_cors import CORS
from ether_ganache import Ganache
USER_LENGTH = 42
KEY_LENGTH = 64
app = Flask(__name__)
CORS(app)
@app.route('/', methods=['GET']) # Decorator
def get_node_ui():
return send_from_directory('templates', 'index.html')
@app.route('/smartcontractsabi', methods=['GET']) # Decorator
def smartcontractsabi():
return send_from_directory('templates', 'smartcontracts_abi.html')
@app.route('/smartcontractsbytecode', methods=['GET']) # Decorator
def smartcontractsbytecode():
return send_from_directory('templates', 'smartcontracts_bytecode.html')
@app.route('/smartcontractsunderstanding', methods=['GET']) # Decorator
def smartcontractsunderstanding():
return send_from_directory('templates', 'smartcontracts_understanding.html')
@app.route('/ethereum_cryptocurrency', methods=['POST'])
def ethereum_cryptocurrency():
values = request.get_json()
recipient = values['recipient']
sender = values['sender']
key = values['key']
amount = values['amount']
if not values or recipient == "" or amount == "" or sender == "" or key == "":
response = {
'message': 'No data found.'
}
return jsonify(response), 400
if len(recipient) != USER_LENGTH:
response = {
'message': 'ID should be ' + str(USER_LENGTH) + ' digits long!!!'
}
return jsonify(response), 400
if len(sender) != USER_LENGTH:
response = {
'message': 'ID should be ' + str(USER_LENGTH) + ' digits long!!!'
}
return jsonify(response), 400
if len(key) != KEY_LENGTH:
response = {
'message': 'ID should be ' + str(KEY_LENGTH) + ' digits long!!!'
}
return jsonify(response), 400
if str(amount).isdigit() is False:
response = {
'message': 'Amount must be only numbers!!!'
}
return jsonify(response), 400
ganache.ganache_send_amount(sender, recipient, key, amount)
conn, blocks = ganache.is_connected()
response = {
'message': "SENDER= " + sender + " " + "RECIPIENT= " + recipient + " " + "KEY= " + key + " " + "AMOUNT= " + str(amount),
'message2': "GANACHE ............. Connection= " + str(conn) + " ............. " + " Blocks= " + str(blocks)
}
return jsonify(response), 201
@app.route('/smartcontracts_abi_write', methods=['POST'])
def smartcontracts_abi_write():
values = request.get_json()
smartcontract_address = values['contract']
data = values['data']
if not values or smartcontract_address == "" or data == "":
response = {
'message': 'No data found.'
}
return jsonify(response), 400
if len(smartcontract_address) != USER_LENGTH:
response = {
'message': 'ID should be ' + str(USER_LENGTH) + ' digits long!!!'
}
return jsonify(response), 400
ganache.smart_contract_abi_write(smartcontract_address, data)
conn, blocks = ganache.is_connected()
response = {
'message': "smartcontract_address= " + smartcontract_address,
'message2': "GANACHE ............. Connection= " + str(conn) + " ............. " + " Blocks= " + str(blocks)
}
return jsonify(response), 201
@app.route('/smartcontracts_abi_read', methods=['POST'])
def smartcontracts_abi_read():
values = request.get_json()
smartcontract_address = values['contract']
if not values or smartcontract_address == "":
response = {
'message': 'No data found.'
}
return jsonify(response), 400
if len(smartcontract_address) != USER_LENGTH:
response = {
'message': 'ID should be ' + str(USER_LENGTH) + ' digits long!!!'
}
return jsonify(response), 400
data_read = ganache.smart_contract_abi_read(smartcontract_address)
conn, blocks = ganache.is_connected()
response = {
'message': "ETHEREUM Blockchain data= " + data_read,
'message2': "GANACHE ............. Connection= " + str(conn) + " ............. " + " Blocks= " + str(blocks)
}
return jsonify(response), 201
@app.route('/smartcontracts_abi_read_all', methods=['POST'])
def smartcontracts_abi_read_all():
values = request.get_json()
smartcontract_address = values['contract']
if not values or smartcontract_address == "":
response = {
'message': 'No data found.'
}
return jsonify(response), 400
if len(smartcontract_address) != USER_LENGTH:
response = {
'message': 'ID should be ' + str(USER_LENGTH) + ' digits long!!!'
}
return jsonify(response), 400
data_read1 = ganache.smart_contract_abi_read_all(smartcontract_address)
data_read = ''.join(data_read1)
print(data_read)
conn, blocks = ganache.is_connected()
response = {
'message': "ETHEREUM Blockchain data:............." + data_read,
'message2': "GANACHE ............. Connection= " + str(conn) + " ............. " + " Blocks= " + str(blocks)
}
return jsonify(response), 201
@app.route('/smartcontracts_bytecode', methods=['POST'])
def smartcontracts_bytecode():
values = request.get_json()
smartcontract_bytecode = values['contract']
if not values or smartcontract_bytecode == "":
response = {
'message': 'No data found.'
}
return jsonify(response), 400
data_read = ganache.smart_contract_bytecode(smartcontract_bytecode)
conn, blocks = ganache.is_connected()
response = {
'message': "ETHEREUM Blockchain data= " + data_read,
'message2': "GANACHE ............. Connection= " + str(conn) + " ............. " + " Blocks= " + str(blocks)
}
return jsonify(response), 201
#port = os.getenv('VCAP_APP_PORT', '8000')
if __name__ == '__main__':
ganache = Ganache()
app.run()