diff --git a/backend/backend.py b/backend/backend.py new file mode 100644 index 0000000..d8bc2d8 --- /dev/null +++ b/backend/backend.py @@ -0,0 +1,54 @@ +import http.server +import socketserver +import subprocess +from urllib.parse import urlparse, parse_qs + +class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler): + def do_GET(self): + parsed_path = urlparse(self.path) + query = parse_qs(parsed_path.query) + print(query) + + if 'command' in query and 'args' in query: + self.send_response(200) + self.send_header('Content-type', 'text/html') + self.end_headers() + self.wfile.write(bytes(f"command: {query['command']}, args: {query['args']}", "utf-8")) + else: + self.send_response(400) + self.send_header('Content-type', 'text/html') + self.end_headers() + self.wfile.write(bytes("Bad request", "utf-8")) + +PORT = 2281 +Handler = MyHttpRequestHandler + +def compile_and_deploy_contract(): + # User + user_compile_command = "neo-go contract compile -i User/user.go -c User/user.yml -m User/user.json" + subprocess.run(user_compile_command, shell=True, check=True) + + user_deploy_command = "neo-go contract deploy -i User/user.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m User/user.json" + subprocess.run(user_deploy_command, shell=True, check=True) + + # Post + post_compile_command = "neo-go contract compile -i Post/post_contract.go -c Post/post_contract.yml -m Post/post_contract.json" + subprocess.run(post_compile_command, shell=True, check=True) + + post_deploy_command = "neo-go contract deploy -i Post/post_contract.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m Post/post_contract.json" + subprocess.run(post_deploy_command, shell=True, check=True) + + # Comment + comment_compile_command = "neo-go contract compile -i Comment/comment.go -c Comment/comment.yml -m Comment/comment.json" + subprocess.run(comment_compile_command, shell=True, check=True) + + comment_deploy_command = "neo-go contract deploy -i Comment/comment.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m Comment/comment.json" + subprocess.run(comment_deploy_command, shell=True, check=True) + +if __name__ == "__main__": + compile_and_deploy_contract() + +with socketserver.TCPServer(("", PORT), Handler) as httpd: + print("Сервер запущен на порту", PORT) + httpd.serve_forever() + httpd.server_close() diff --git a/backend/edit_route.py b/backend/edit_route.py new file mode 100644 index 0000000..d3c82e0 --- /dev/null +++ b/backend/edit_route.py @@ -0,0 +1,62 @@ +import json + + +route = { + "1": { + "command": "neo-go wallet init", + "flags": { + "wallet": "wallet file name", + "account": "create new account" + } + }, + "2": { + "command": "neo-go wallet dump-keys", + "flags": { + "wallet": "wallet file name", + } + }, + "3": { + "command": "neo-go wallet nep17 balance", + "flags": { + "wallet": "wallet file name", + } + }, + "4": { + "command": "neo-go wallet nep17 transfer", + "flags": { + "wallet": "wallet file name(wallet from which transfer is made)", + "from": "hash of wallet from which transfer is made", + "to" : "hash of wallet to which transfer is made", + "amount": "gas transfer amount", + "token": "token for transfer NEO/GAS", + } + }, + "5": { + "command": "neo-go contract compile", + "flags": { + "in": "smart contract file name(*.go)", + "manifest": "contract manifest file name(*.json)", + "contract_config" : "contract config file name(*.yml)", + } + }, + "6": { + "command": "neo-go contract deploy", + "flags": { + "wallet": "wallet file name", + "in": "compiled smart contract file name(*.nef)", + "manifest" : "manifest file name(*.json)", + } + }, + "7": { + "command": "neo-go contract invokefunction", + "flags": { + "wallet": "wallet file name", + "contract_hash": "hash of contract", + "func_name": "name of invoked func", + "parameters": "list([]) of func parameters" + } + } +} + +with open("route.json", "w") as f: + f.write(json.dumps(route)) \ No newline at end of file diff --git a/backend/req_test.py b/backend/req_test.py new file mode 100644 index 0000000..e190931 --- /dev/null +++ b/backend/req_test.py @@ -0,0 +1,7 @@ +import requests + +# Отправляем GET запрос на сервер +response = requests.get('http://localhost:2281', params={"command": 0, "args": {"amount_1": 1, "amount": 1}}) + +# Выводим ответ от сервера +print('Ответ от сервера:', response.text) diff --git a/backend/route.json b/backend/route.json new file mode 100644 index 0000000..80555fa --- /dev/null +++ b/backend/route.json @@ -0,0 +1 @@ +{"1": {"command": "neo-go wallet init", "flags": {"wallet": "wallet file name", "account": "create new account"}}, "2": {"command": "neo-go wallet dump-keys", "flags": {"wallet": "wallet file name"}}, "3": {"command": "neo-go wallet nep17 balance", "flags": {"wallet": "wallet file name"}}, "4": {"command": "neo-go wallet nep17 transfer", "flags": {"wallet": "wallet file name(wallet from which transfer is made)", "from": "hash of wallet from which transfer is made", "to": "hash of wallet to which transfer is made", "amount": "gas transfer amount", "token": "token for transfer NEO/GAS"}}, "5": {"command": "neo-go contract compile", "flags": {"in": "smart contract file name(*.go)", "manifest": "contract manifest file name(*.json)", "contract_config": "contract config file name(*.yml)"}}, "6": {"command": "neo-go contract deploy", "flags": {"wallet": "wallet file name", "in": "compiled smart contract file name(*.nef)", "manifest": "manifest file name(*.json)"}}, "7": {"command": "neo-go contract invokefunction", "flags": {"wallet": "wallet file name", "contract_hash": "hash of contract", "func_name": "name of invoked func", "parameters": "list([]) of func parameters"}}} \ No newline at end of file