fix: backend

This commit is contained in:
glebbelay 2024-01-18 18:17:43 +03:00
parent 46c6e5c2ae
commit 720eb16d72
11 changed files with 143 additions and 49 deletions

1
Comment/comment.json Executable file
View file

@ -0,0 +1 @@
{"name":"comment","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"createNewComment","offset":35,"parameters":[{"name":"userLogin","type":"String"},{"name":"postId","type":"String"},{"name":"text","type":"String"}],"returntype":"Void","safe":false},{"name":"getByLogin","offset":580,"parameters":[{"name":"login","type":"String"}],"returntype":"Array","safe":false},{"name":"getByLoginInPost","offset":529,"parameters":[{"name":"postId","type":"String"},{"name":"login","type":"String"}],"returntype":"Array","safe":false},{"name":"getByPostId","offset":430,"parameters":[{"name":"postId","type":"String"}],"returntype":"Array","safe":false},{"name":"getComment","offset":648,"parameters":[{"name":"commentId","type":"String"}],"returntype":"Array","safe":false},{"name":"rateComment","offset":709,"parameters":[{"name":"isLike","type":"Boolean"},{"name":"postId","type":"String"},{"name":"commentId","type":"String"}],"returntype":"Void","safe":false},{"name":"updateComment","offset":740,"parameters":[{"name":"comment","type":"Array"},{"name":"postId","type":"String"}],"returntype":"Void","safe":false}],"events":[{"name":"Hello world!","parameters":[{"name":"args","type":"Array"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}

BIN
Comment/comment.nef Executable file

Binary file not shown.

1
Post/post_contract.json Executable file
View file

@ -0,0 +1 @@
{"name":"Post","abi":{"methods":[{"name":"getAllPosts","offset":217,"parameters":[],"returntype":"Array","safe":false},{"name":"getAllPostsByUser","offset":358,"parameters":[{"name":"login","type":"String"}],"returntype":"Array","safe":false},{"name":"getPost","offset":300,"parameters":[{"name":"postId","type":"String"}],"returntype":"Array","safe":false},{"name":"newPost","offset":0,"parameters":[{"name":"login","type":"String"},{"name":"text","type":"String"},{"name":"postName","type":"String"}],"returntype":"Void","safe":false},{"name":"ratePost","offset":514,"parameters":[{"name":"isLike","type":"Boolean"},{"name":"postId","type":"String"}],"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}

BIN
Post/post_contract.nef Executable file

Binary file not shown.

9
User/user.go Executable file → Normal file
View file

@ -2,6 +2,7 @@ package Users
import (
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
@ -35,12 +36,18 @@ func NewUser(name string, surname string, login string, password string, owner i
}
saveUser(ctx, login, user)
}
func GetUser(login string) User {
return getUserTst(storage.GetReadOnlyContext(), login)
}
func RateForGas(commentId string, contractHash interop.Hash160, login string) {
ctx := storage.GetContext()
contract.Call(contractHash, "rate", contract.ReadOnly, commentId, storage.Get(ctx, login+"_hash"))
}
func getUserTst(ctx storage.Context, login string) User {
data := storage.Get(ctx, login)
@ -54,6 +61,6 @@ func getUserTst(ctx storage.Context, login string) User {
func saveUser(ctx storage.Context, userLogin string, user User) {
runtime.Log("User " + userLogin + " was created")
storage.Put(ctx, userLogin+lastIndex, -1)
storage.Put(ctx, userLogin+"_hash", user.ownerHash)
storage.Put(ctx, userLogin, std.Serialize(user))
}

1
User/user.json Executable file
View file

@ -0,0 +1 @@
{"name":"user","abi":{"methods":[{"name":"getUser","offset":83,"parameters":[{"name":"login","type":"String"}],"returntype":"Array","safe":false},{"name":"newUser","offset":0,"parameters":[{"name":"name","type":"String"},{"name":"surname","type":"String"},{"name":"login","type":"String"},{"name":"password","type":"String"},{"name":"owner","type":"Hash160"}],"returntype":"Void","safe":false},{"name":"rateForGas","offset":96,"parameters":[{"name":"commentId","type":"String"},{"name":"contractHash","type":"Hash160"},{"name":"login","type":"String"}],"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[],"supportedstandards":[],"trusts":[],"extra":null}

BIN
User/user.nef Executable file

Binary file not shown.

0
User/user.yml Executable file → Normal file
View file

View file

@ -7,6 +7,9 @@ import json
import re
node_wallet = "/usr/local/frostfs-aio/morph/node-wallet.json"
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
@ -32,8 +35,10 @@ class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
if "command_type" in query and "command_id" in query:
self.send_response(200)
self.send_header("Content-type", "text/html")
self.send_header("Access-Control-Allow-Origin", "*")
self.end_headers()
params = query.get("args", None)
parsed_params = " " + ' '.join(params) if params else ""
@ -58,6 +63,8 @@ class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
command = f"neo-go contract testinvokefunction -r http://localhost:30333 {hash_for_req} {method}{parsed_params}"
print(command)
proc = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out_list = []
@ -77,6 +84,7 @@ class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
answer_dict = json.loads(answer)["stack"][0]["value"]
answer_list = []
print(answer_dict)
for obj_i in answer_dict:
obj = obj_i["value"]
obj_fiedls = []
@ -92,7 +100,7 @@ class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
answer_list.append(obj_fiedls)
self.wfile.write(bytes(f"answer: {obj_fiedls}", "utf-8"))
self.wfile.write(bytes(f"{answer_list}", "utf-8"))
# elif command_type == "post":
@ -103,7 +111,7 @@ class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
# command = commands_route[command_code]
# else:
# user_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {user_path}/user.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m {user_path}/user.json --force"
# user_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {user_path}/user.nef -w {node_wallet} -r http://localhost:30333 -m {user_path}/user.json --force"
# proc = subprocess.Popen(user_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
else:
@ -122,7 +130,7 @@ def compile_and_deploy_contract(
user_compile_command = f"sshpass -p {password} neo-go contract compile -i {user_path}/user.go -c {user_path}/user.yml -m {user_path}/user.json"
subprocess.run(user_compile_command, shell=True, check=False)
user_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {user_path}/user.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m {user_path}/user.json --force"
user_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {user_path}/user.nef -w {node_wallet} -r http://localhost:30333 -m {user_path}/user.json --force"
proc = subprocess.Popen(user_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
user_out_list = []
@ -136,7 +144,7 @@ def compile_and_deploy_contract(
post_compile_command = f"sshpass -p {password} neo-go contract compile -i {post_path}/post_contract.go -c {post_path}/post_contract.yml -m {post_path}/post_contract.json"
subprocess.run(post_compile_command, shell=True, check=False)
post_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {post_path}/post_contract.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m {post_path}/post_contract.json --force"
post_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {post_path}/post_contract.nef -w {node_wallet} -r http://localhost:30333 -m {post_path}/post_contract.json --force"
proc = subprocess.Popen(post_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
post_out_list = []
@ -150,7 +158,7 @@ def compile_and_deploy_contract(
comment_compile_command = f"sshpass -p {password} neo-go contract compile -i {comment_path}/comment.go -c {comment_path}/comment.yml -m {comment_path}/comment.json"
subprocess.run(comment_compile_command, shell=True, check=False)
comment_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {comment_path}/comment.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m {comment_path}/comment.json --force"
comment_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {comment_path}/comment.nef -w {node_wallet} -r http://localhost:30333 -m {comment_path}/comment.json --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_out_list = []
@ -165,33 +173,33 @@ def compile_and_deploy_contract(
print(user_hash, post_hash, comment_hash)
########################################
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {user_hash} newUser hui228336 hui228336 hui228336 1 Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn"
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {user_hash} newUser hui228336 hui228336 hui228336 1 Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {user_hash} newUser hui1488 hui1488 hui1488 1 Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn"
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {user_hash} newUser hui1488 hui1488 hui1488 1 Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {post_hash} newPost hui228336 hui hui"
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {post_hash} newPost hui228336 hui hui --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {post_hash} newPost hui228336 hui22 hui22"
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {post_hash} newPost hui228336 hui22 hui22 --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {comment_hash} createNewComment hui228336 post_1 some_text"
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {comment_hash} createNewComment hui228336 post_1 some_text --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {comment_hash} createNewComment hui1488 post_1 some_text"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
# comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {comment_hash} createNewComment hui1488 post_1 some_text"
# proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {comment_hash} createNewComment hui1488 post_1 some_text"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
# comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {comment_hash} createNewComment hui1488 post_1 some_text"
# proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
########################################
return user_hash, post_hash, comment_hash
if __name__ == "__main__":
PORT = 2281
PORT = 2282
Handler = MyHttpRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:

View file

@ -2,7 +2,7 @@ import requests
# Отправляем GET запрос на сервер
response = requests.get(
'http://localhost:2281',
'http://localhost:2282',
params={
"command_type": "get",
"method": "getAllPosts",

76
backend/start.py Normal file
View file

@ -0,0 +1,76 @@
import subprocess
user_path = "../User"
post_path = "../Post"
comment_path = "../Comment"
password = "one"
user_compile_command = f"sshpass -p {password} neo-go contract compile -i {user_path}/user.go -c {user_path}/user.yml -m {user_path}/user.json"
subprocess.run(user_compile_command, shell=True, check=False)
user_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {user_path}/user.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m {user_path}/user.json --force"
proc = subprocess.Popen(user_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
user_out_list = []
while True:
line = proc.stdout.readline()
if not line:
break
user_out_list.append(line.rstrip())
user_hash = str(user_out_list[-1], encoding='utf-8').replace("Contract: ", "")
post_compile_command = f"sshpass -p {password} neo-go contract compile -i {post_path}/post_contract.go -c {post_path}/post_contract.yml -m {post_path}/post_contract.json"
subprocess.run(post_compile_command, shell=True, check=False)
post_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {post_path}/post_contract.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m {post_path}/post_contract.json --force"
proc = subprocess.Popen(post_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
post_out_list = []
while True:
line = proc.stdout.readline()
if not line:
break
post_out_list.append(line.rstrip())
post_hash = str(post_out_list[-1], encoding='utf-8').replace("Contract: ", "")
comment_compile_command = f"sshpass -p {password} neo-go contract compile -i {comment_path}/comment.go -c {comment_path}/comment.yml -m {comment_path}/comment.json"
subprocess.run(comment_compile_command, shell=True, check=False)
comment_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {comment_path}/comment.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m {comment_path}/comment.json --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_out_list = []
while True:
line = proc.stdout.readline()
if not line:
break
comment_out_list.append(line.rstrip())
comment_hash = str(comment_out_list[-1], encoding='utf-8').replace("Contract: ", "")
print(user_hash, post_hash, comment_hash)
########################################
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {user_hash} newUser hui228336 hui228336 hui228336 1 Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn--force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {user_hash} newUser hui1488 hui1488 hui1488 1 Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn--force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {post_hash} newPost hui228336 hui hui --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {post_hash} newPost hui228336 hui22 hui22 --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {comment_hash} createNewComment hui228336 post_1 some_text --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {comment_hash} createNewComment hui1488 post_1 some_text --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 {comment_hash} createNewComment hui1488 post_1 some_text --force"
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
########################################