From 720eb16d72206c2d5d02bf609ff9895a79e91c9e Mon Sep 17 00:00:00 2001 From: glebbelay Date: Thu, 18 Jan 2024 18:17:43 +0300 Subject: [PATCH 1/7] fix: backend --- Comment/comment.json | 1 + Comment/comment.nef | Bin 0 -> 1062 bytes Post/post_contract.json | 1 + Post/post_contract.nef | Bin 0 -> 922 bytes User/user.go | 73 +++++++++++++++++++++----------------- User/user.json | 1 + User/user.nef | Bin 0 -> 416 bytes User/user.yml | 0 backend/backend.py | 38 ++++++++++++-------- backend/req_test.py | 2 +- backend/start.py | 76 ++++++++++++++++++++++++++++++++++++++++ 11 files changed, 143 insertions(+), 49 deletions(-) create mode 100755 Comment/comment.json create mode 100755 Comment/comment.nef create mode 100755 Post/post_contract.json create mode 100755 Post/post_contract.nef mode change 100755 => 100644 User/user.go create mode 100755 User/user.json create mode 100755 User/user.nef mode change 100755 => 100644 User/user.yml create mode 100644 backend/start.py diff --git a/Comment/comment.json b/Comment/comment.json new file mode 100755 index 0000000..6702245 --- /dev/null +++ b/Comment/comment.json @@ -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} \ No newline at end of file diff --git a/Comment/comment.nef b/Comment/comment.nef new file mode 100755 index 0000000000000000000000000000000000000000..69f47ae335fdf128c09139c364d678609468c61f GIT binary patch literal 1062 zcmah{&rj1(9BxgZse{`sxnG0 zp=4@oB9$JSNNR?hOkYec73HZ*w6SFvkOWe9ek#<}Jr3X>fyGFxKB<=+07`+c8;o)wW6l>nrRFp=xKo;P|Vm*x}Ar4P=^g}2q%Iq8vD#!j?(e^--_5wVV9}Oa+V^*CXc^)UZO%)=3%SV(qcLgx7gX) z3xg-F&w7T^@7Zfy9}I$4>bjfQ$>nmetqR|(?JCn@kjUVIu$_AT$WR2A{_1k)6yf{L z^`W3F6%ep2r|G(ucnf$b)Ny9{jcD5$VETiXkE_Ux-@%nBPQyU;u4Vyi7I=xIR@3X6 z#nIrD=O&JU)1C`9#rgVcdoE4!QcuuvJG1e-)zVo*!7fI6wi4kS`;0pS6_52S)?4Eu j7F6b6DXx*&hB!xDe%#`kmZX{#M z+4I>Q&p&sc<`B-xAaKO7!13Fb>_>%}JS-sPGQp1b4R*{b%5t2;@pg`yewO3sko~e= zHyweVa|C!t>ftx=K#HYCIAh8m0OA+PN71xjZ#9Kx9x!NwJ2R6smZn0Z4@n1>JS zlDzy9g|z(AycDZUubT!yLk!HB7@$TwgtJ3+0-aPSSX5!U3z!6ov$6%}ZB?%aGNB=n z1qzAMj9iH6B{?_L#Ce3kre~*CDj;mgfjKiH2conr51T`><`iW@eUOLYrt^i$jsO4u z&vXc9W`d-EN>c@(Kw*U%N2c((IZAAqBIo900;9GlBUAKT79?uGVE|4qxT6;oDl7tp tz+eC;8ibY#lf#ABv}Fp;gPYC(aSN`5h-o%dgUPW%Og#vLdn#WY0suPBQ^WuO literal 0 HcmV?d00001 diff --git a/User/user.go b/User/user.go old mode 100755 new mode 100644 index d375812..e7a526c --- a/User/user.go +++ b/User/user.go @@ -1,59 +1,66 @@ package Users import ( - "github.com/nspcc-dev/neo-go/pkg/interop" - "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" + "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" ) type User struct { - name string - surname string - login string - password string - ownerHash interop.Hash160 + name string + surname string + login string + password string + ownerHash interop.Hash160 } const ( - lastIndex = "_lastIndex" + lastIndex = "_lastIndex" ) func NewUser(name string, surname string, login string, password string, owner interop.Hash160) { - ctx := storage.GetContext() - existing_login := storage.Get(ctx, login) - if existing_login != nil { - panic("this login is taken by someone else") - } + ctx := storage.GetContext() + existing_login := storage.Get(ctx, login) + if existing_login != nil { + panic("this login is taken by someone else") + } - user := User{ - name: name, - surname: surname, - login: login, - password: password, - ownerHash: owner, - } + user := User{ + name: name, + surname: surname, + login: login, + password: password, + ownerHash: owner, + } + + saveUser(ctx, login, user) - saveUser(ctx, login, user) } func GetUser(login string) User { - return getUserTst(storage.GetReadOnlyContext(), login) + 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) + data := storage.Get(ctx, login) - if data == nil { - panic("User does not exist") - } + if data == nil { + panic("User does not exist") + } - return std.Deserialize(data.([]byte)).(User) + return std.Deserialize(data.([]byte)).(User) } func saveUser(ctx storage.Context, userLogin string, user User) { - runtime.Log("User " + userLogin + " was created") + runtime.Log("User " + userLogin + " was created") - storage.Put(ctx, userLogin+lastIndex, -1) - storage.Put(ctx, userLogin, std.Serialize(user)) -} + storage.Put(ctx, userLogin+"_hash", user.ownerHash) + storage.Put(ctx, userLogin, std.Serialize(user)) +} \ No newline at end of file diff --git a/User/user.json b/User/user.json new file mode 100755 index 0000000..a3ba7fb --- /dev/null +++ b/User/user.json @@ -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} \ No newline at end of file diff --git a/User/user.nef b/User/user.nef new file mode 100755 index 0000000000000000000000000000000000000000..a91a3735535fade3e2caa7b5c36568118f239637 GIT binary patch literal 416 zcmeZsbu-RO&DTxO*EP^HG%(RK)Ga7V)ip8GO;1U+v`8|xOk^Mom=3(RJon(qOVwkC z7GzaEbm6^`e{KzTN@{UxQD$OJW>qR910w@AHJm6a7#RL?F@`ghtLQz3pIWStmtUfgT9H{?VwK@_ z(?Esgwt+bVgV#+*Aj=V`k(q}TthTb7hex42u~;FwC>3aSO1I Date: Fri, 19 Jan 2024 00:37:48 +0300 Subject: [PATCH 2/7] fix backend --- backend/backend.py | 268 ++++++++++++++++++++++---------------------- backend/req_test.py | 6 +- 2 files changed, 140 insertions(+), 134 deletions(-) diff --git a/backend/backend.py b/backend/backend.py index f41654e..771487c 100644 --- a/backend/backend.py +++ b/backend/backend.py @@ -7,125 +7,13 @@ import json import re -node_wallet = "/usr/local/frostfs-aio/morph/node-wallet.json" - - -class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler): - def do_GET(self): - - with open("./route.json", "r") as f: - route_dict = json.load(f) - - with open("suka_logs.log", "w") as f: - f.write("starting...") - - user_hash, post_hash, comment_hash = compile_and_deploy_contract( - "../User", - "../Post", - "../Comment", - "one" - ) - - with open("suka_logs.log", "a") as f: - f.write(f"user_hash: {user_hash}\npost_hash: {post_hash}\ncomment_hash: {comment_hash}") - - parsed_path = urlparse(self.path) - query = parse_qs(parsed_path.query) - - 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 "" - - command_type = query["command_type"][0] - contract_name = query["contract"][0] - method = query["method"][0] - - with open("suka_logs.log", "a") as f: - f.write("reading params...\n") - - if command_type == "get": - hash_for_req = None - if contract_name == "post": - hash_for_req = post_hash - elif contract_name == "user": - hash_for_req = user_hash - elif contract_name == "comment": - hash_for_req = comment_hash - - with open("suka_logs.log", "a") as f: - f.write(f"params: {[command_type, contract_name, method, parsed_params]}\n") - - 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 = [] - while True: - if proc.stdout is None: - break - - line = proc.stdout.readline() - - if not line: - break - out_list.append(line.rstrip()) - - answer = " ".join(map(lambda x: x.decode("utf-8"), out_list)) - answer = re.sub(r"[\n\t\s]*", "", answer) - - 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 = [] - for field in obj: - if field["type"] in ["ByteString", "Buffer"]: - encoded_string = field["value"] - result_string = base64.b64decode(encoded_string) - result_string = result_string.decode('utf-8') - obj_fiedls.append(result_string) - elif field["type"] == "Integer": - encoded_string = field["value"] - obj_fiedls.append(encoded_string) - - answer_list.append(obj_fiedls) - - self.wfile.write(bytes(f"{answer_list}", "utf-8")) - - - # elif command_type == "post": - # command = commands_route["7"]["command"] + f"-r http://localhost:30333 {contract_name} {method} {' '.join(params[5:])}" - - - # if command_type == "post": - # command = commands_route[command_code] - # else: - - # 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: - self.send_response(400) - self.send_header("Content-type", "text/html") - self.end_headers() - self.wfile.write(bytes("Bad request", "utf-8")) - - def compile_and_deploy_contract( user_path: str, post_path: str, comment_path: str, password: str, + node_wallet: str, + run_start_funcs: bool=False ) -> dict[str, str]: 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" @@ -172,34 +60,152 @@ def compile_and_deploy_contract( print(user_hash, post_hash, comment_hash) - ######################################## - 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) + if run_start_funcs: + comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {user_hash} newUser user_test1 user_test1 user_test1 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 {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 {node_wallet} -r http://localhost:30333 {user_hash} newUser user_test2 user_test2 user_test2 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 {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 {node_wallet} -r http://localhost:30333 {post_hash} newPost user_test1 test test --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 {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 {node_wallet} -r http://localhost:30333 {post_hash} newPost user_test2 test test --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 {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 {node_wallet} -r http://localhost:30333 {comment_hash} createNewComment user_test1 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 {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 {node_wallet} -r http://localhost:30333 {comment_hash} createNewComment user_test1 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 {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 {node_wallet} -r http://localhost:30333 {comment_hash} createNewComment user_test2 post_1 some_text --force" + proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) return user_hash, post_hash, comment_hash +user_hash, post_hash, comment_hash = compile_and_deploy_contract( + "../User", + "../Post", + "../Comment", + "one", + "/home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json", + False +) + + +class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler): + def do_GET(self): + + with open("./route.json", "r") as f: + route_dict = json.load(f) + + with open("logs.log", "w") as f: + f.write("starting...") + + with open("logs.log", "a") as f: + f.write(f"user_hash: {user_hash}\npost_hash: {post_hash}\ncomment_hash: {comment_hash}") + + parsed_path = urlparse(self.path) + query = parse_qs(parsed_path.query) + + 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 "" + + command_type = query["command_type"][0] + contract_name = query["contract"][0] + method = query["method"][0] + + with open("logs.log", "a") as f: + f.write("reading params...\n") + + if command_type == "get": + hash_for_req = None + if contract_name == "post": + hash_for_req = post_hash + elif contract_name == "user": + hash_for_req = user_hash + elif contract_name == "comment": + hash_for_req = comment_hash + + with open("logs.log", "a") as f: + f.write(f"params: {[command_type, contract_name, method, parsed_params]}\n") + + 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 = [] + while True: + if proc.stdout is None: + break + + line = proc.stdout.readline() + + if not line: + break + out_list.append(line.rstrip()) + + answer = " ".join(map(lambda x: x.decode("utf-8"), out_list)) + answer = re.sub(r"[\n\t\s]*", "", answer) + + print(json.loads(answer)["stack"][0]) + + if json.loads(answer)["stack"][0]["type"] == "Struct": + answer_dict = json.loads(answer)["stack"][0]["value"] + obj_fiedls = [] + for field in answer_dict: + if field["type"] in ["ByteString", "Buffer"]: + encoded_string = field["value"] + result_string = base64.b64decode(encoded_string) + try: + result_string = result_string.decode('utf-8') + except: + pass + obj_fiedls.append(result_string) + elif field["type"] == "Integer": + encoded_string = field["value"] + obj_fiedls.append(encoded_string) + + self.wfile.write(bytes(f"{obj_fiedls}", "utf-8")) + else: + answer_dict = json.loads(answer)["stack"][0]["value"] + answer_list = [] + for obj_i in answer_dict: + obj = obj_i["value"] + obj_fiedls = [] + for field in obj: + if field["type"] in ["ByteString", "Buffer"]: + encoded_string = field["value"] + result_string = base64.b64decode(encoded_string) + result_string = result_string.decode('utf-8') + obj_fiedls.append(result_string) + elif field["type"] == "Integer": + encoded_string = field["value"] + obj_fiedls.append(encoded_string) + + answer_list.append(obj_fiedls) + + self.wfile.write(bytes(f"{answer_list}", "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")) + + if __name__ == "__main__": - PORT = 2282 + PORT = 2281 Handler = MyHttpRequestHandler with socketserver.TCPServer(("", PORT), Handler) as httpd: diff --git a/backend/req_test.py b/backend/req_test.py index c54332a..218632c 100644 --- a/backend/req_test.py +++ b/backend/req_test.py @@ -2,13 +2,13 @@ import requests # Отправляем GET запрос на сервер response = requests.get( - 'http://localhost:2282', + 'http://localhost:2281', params={ "command_type": "get", - "method": "getAllPosts", + "method": "getPost", "command_id": "8", "contract": "post", - "args": []}) + "args": ["post_1"]}) # Выводим ответ от сервера print('Ответ от сервера:', response.text) From d09455e06f66747e3f9de462b9477fdd70469e1c Mon Sep 17 00:00:00 2001 From: RustamOper05 Date: Fri, 19 Jan 2024 00:42:25 +0300 Subject: [PATCH 3/7] delete compiled files --- User/user.json | 1 - User/user.nef | Bin 416 -> 0 bytes 2 files changed, 1 deletion(-) delete mode 100755 User/user.json delete mode 100755 User/user.nef diff --git a/User/user.json b/User/user.json deleted file mode 100755 index a3ba7fb..0000000 --- a/User/user.json +++ /dev/null @@ -1 +0,0 @@ -{"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} \ No newline at end of file diff --git a/User/user.nef b/User/user.nef deleted file mode 100755 index a91a3735535fade3e2caa7b5c36568118f239637..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 416 zcmeZsbu-RO&DTxO*EP^HG%(RK)Ga7V)ip8GO;1U+v`8|xOk^Mom=3(RJon(qOVwkC z7GzaEbm6^`e{KzTN@{UxQD$OJW>qR910w@AHJm6a7#RL?F@`ghtLQz3pIWStmtUfgT9H{?VwK@_ z(?Esgwt+bVgV#+*Aj=V`k(q}TthTb7hex42u~;FwC>3aSO1I Date: Fri, 19 Jan 2024 00:46:31 +0300 Subject: [PATCH 4/7] delete compiled files --- Comment/comment.json | 1 - Comment/comment.nef | Bin 1062 -> 0 bytes Post/post_contract.json | 1 - Post/post_contract.nef | Bin 922 -> 0 bytes 4 files changed, 2 deletions(-) delete mode 100755 Comment/comment.json delete mode 100755 Comment/comment.nef delete mode 100755 Post/post_contract.json delete mode 100755 Post/post_contract.nef diff --git a/Comment/comment.json b/Comment/comment.json deleted file mode 100755 index 6702245..0000000 --- a/Comment/comment.json +++ /dev/null @@ -1 +0,0 @@ -{"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} \ No newline at end of file diff --git a/Comment/comment.nef b/Comment/comment.nef deleted file mode 100755 index 69f47ae335fdf128c09139c364d678609468c61f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1062 zcmah{&rj1(9BxgZse{`sxnG0 zp=4@oB9$JSNNR?hOkYec73HZ*w6SFvkOWe9ek#<}Jr3X>fyGFxKB<=+07`+c8;o)wW6l>nrRFp=xKo;P|Vm*x}Ar4P=^g}2q%Iq8vD#!j?(e^--_5wVV9}Oa+V^*CXc^)UZO%)=3%SV(qcLgx7gX) z3xg-F&w7T^@7Zfy9}I$4>bjfQ$>nmetqR|(?JCn@kjUVIu$_AT$WR2A{_1k)6yf{L z^`W3F6%ep2r|G(ucnf$b)Ny9{jcD5$VETiXkE_Ux-@%nBPQyU;u4Vyi7I=xIR@3X6 z#nIrD=O&JU)1C`9#rgVcdoE4!QcuuvJG1e-)zVo*!7fI6wi4kS`;0pS6_52S)?4Eu j7F6b6DXx*&hB!xDe%#`kmZX{#M z+4I>Q&p&sc<`B-xAaKO7!13Fb>_>%}JS-sPGQp1b4R*{b%5t2;@pg`yewO3sko~e= zHyweVa|C!t>ftx=K#HYCIAh8m0OA+PN71xjZ#9Kx9x!NwJ2R6smZn0Z4@n1>JS zlDzy9g|z(AycDZUubT!yLk!HB7@$TwgtJ3+0-aPSSX5!U3z!6ov$6%}ZB?%aGNB=n z1qzAMj9iH6B{?_L#Ce3kre~*CDj;mgfjKiH2conr51T`><`iW@eUOLYrt^i$jsO4u z&vXc9W`d-EN>c@(Kw*U%N2c((IZAAqBIo900;9GlBUAKT79?uGVE|4qxT6;oDl7tp tz+eC;8ibY#lf#ABv}Fp;gPYC(aSN`5h-o%dgUPW%Og#vLdn#WY0suPBQ^WuO From d5126a94e4fb48ecf206b2036aff82272811891b Mon Sep 17 00:00:00 2001 From: RustamOper05 Date: Fri, 19 Jan 2024 00:52:15 +0300 Subject: [PATCH 5/7] fix spaces --- Comment/comment.json | 1 + Comment/comment.nef | Bin 0 -> 1062 bytes Post/post_contract.json | 1 + Post/post_contract.nef | Bin 0 -> 922 bytes User/user.go | 72 ++++++++++++++++++++-------------------- User/user.json | 1 + User/user.nef | Bin 0 -> 416 bytes 7 files changed, 39 insertions(+), 36 deletions(-) create mode 100755 Comment/comment.json create mode 100755 Comment/comment.nef create mode 100755 Post/post_contract.json create mode 100755 Post/post_contract.nef create mode 100755 User/user.json create mode 100755 User/user.nef diff --git a/Comment/comment.json b/Comment/comment.json new file mode 100755 index 0000000..6702245 --- /dev/null +++ b/Comment/comment.json @@ -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} \ No newline at end of file diff --git a/Comment/comment.nef b/Comment/comment.nef new file mode 100755 index 0000000000000000000000000000000000000000..a9ba586cf7cdd7792873566ee01fd1a0ee1d5033 GIT binary patch literal 1062 zcmah{PiWIn98Q|frfVjdf2M~GyE4Nr-P+kw-Nl4ig$!k5Lhv9ZwsCn`o0p_no9yf@ zHxCXq2f?dX!HaAR^{_+g!9$D46o!95@gR89`nsfZ&W^oP!uR`q@B6;@UCUoSr%Eun z2$QLabSg8EPHKjfoXRB^Gnuq>>%1sphn?fHX=>AxlaeJ?w6Zi&gq2Awy#D=y_kR1! z*;gBn6#K)afhP2xghdkq9K*4mATXhL5E!jW1`x|&MLK9AR+9di!LVO5gn);*hd&oR zO{NBbT9T{+5?7H_lfqLA+{cTj@2~I=3C=q;kV<4lEW|^xH`z;Samm_-iWPWWxCk zzS5|vxe!*5$bYwN2S$9RN(Un4G9(Yt!?#9}snL2AM%{X}hcp=V87zt@6blZFc9hlo zW!PU1L=VpRLB@-QB$`rbI$n0DNIcm&ac6%Jj^$9K48Vp`Ou0k_@8&#$>4Fc6WnmMGIV+EX8$*gG> zL&_&SH*rKh>ACU-Ki_y`&t(W!=nFb-XV-tX+d6G1$i-OSW+I%YpE9R_;?bT(d#g;u k0?Pbr#WfOJ0Og2kyqlTr1Rb^zV9IDbcxd+JjpvX50IMW}4gdfE literal 0 HcmV?d00001 diff --git a/Post/post_contract.json b/Post/post_contract.json new file mode 100755 index 0000000..0fd6400 --- /dev/null +++ b/Post/post_contract.json @@ -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} \ No newline at end of file diff --git a/Post/post_contract.nef b/Post/post_contract.nef new file mode 100755 index 0000000000000000000000000000000000000000..8da50f8ea539d4c69d2c0bd7ed431c6583a82c40 GIT binary patch literal 922 zcmeZsbu-RO&DTxO*EP^HG%(RK)Ga7V)ipBLO*b(yOii*#Ok^Mom=Ce%#`kmZX{#M z+4I>Q&p&sc<`B-xAaKO7!13Fb>_>%}JS-sPGQp1b4R*{b%5t2;@pg`yewO3sko~e= zHyweVa|C!t>ftx=K#HYCIAh8m0OA+PN71xjZ#9Kx9x!NwJ2R6smZn0Z4@n1>JS zlDzy9g|z(AycDZUubT!yLk!HB7@$TwgtJ3+0-aPSSX5!U3z!6ov$6%}ZB?%aGNB=n z1qzAMj9iH6B{?_L#Ce3kre~*CDj;mgfjKiH2conr51T`><`iW@eUOLYrt^i$jsO4u z&vXc9W`d-EN>c@(Kw*U%N2c((IZAAqBIo900;9GlBUAKT79?uGVE|4qxT6;oDl7tp tz+eC;8ibY#lf#ABv}Fp;gPYC(aSN`5h-o%dgUPW%Og#vLza*{E0005cQ!M}h literal 0 HcmV?d00001 diff --git a/User/user.go b/User/user.go index e7a526c..0a45368 100644 --- a/User/user.go +++ b/User/user.go @@ -1,66 +1,66 @@ 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" + "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" ) type User struct { - name string - surname string - login string - password string - ownerHash interop.Hash160 + name string + surname string + login string + password string + ownerHash interop.Hash160 } const ( - lastIndex = "_lastIndex" + lastIndex = "_lastIndex" ) func NewUser(name string, surname string, login string, password string, owner interop.Hash160) { - ctx := storage.GetContext() - existing_login := storage.Get(ctx, login) - if existing_login != nil { - panic("this login is taken by someone else") - } + ctx := storage.GetContext() + existing_login := storage.Get(ctx, login) + if existing_login != nil { + panic("this login is taken by someone else") + } - user := User{ - name: name, - surname: surname, - login: login, - password: password, - ownerHash: owner, - } + user := User{ + name: name, + surname: surname, + login: login, + password: password, + ownerHash: owner, + } - saveUser(ctx, login, user) + saveUser(ctx, login, user) } func GetUser(login string) User { - return getUserTst(storage.GetReadOnlyContext(), login) + 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")) + 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) + data := storage.Get(ctx, login) - if data == nil { - panic("User does not exist") - } + if data == nil { + panic("User does not exist") + } - return std.Deserialize(data.([]byte)).(User) + return std.Deserialize(data.([]byte)).(User) } func saveUser(ctx storage.Context, userLogin string, user User) { - runtime.Log("User " + userLogin + " was created") + runtime.Log("User " + userLogin + " was created") - storage.Put(ctx, userLogin+"_hash", user.ownerHash) - storage.Put(ctx, userLogin, std.Serialize(user)) -} \ No newline at end of file + storage.Put(ctx, userLogin+"_hash", user.ownerHash) + storage.Put(ctx, userLogin, std.Serialize(user)) +} diff --git a/User/user.json b/User/user.json new file mode 100755 index 0000000..a3ba7fb --- /dev/null +++ b/User/user.json @@ -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} \ No newline at end of file diff --git a/User/user.nef b/User/user.nef new file mode 100755 index 0000000000000000000000000000000000000000..f91fce873585eae3255cf54cce9232465a67a40f GIT binary patch literal 416 zcmeZsbu-RO&DTxO*EP^HG%(RK)Ga7V)ipBLO*b(yOii*#Ok^Mom=3(RJon(qOVwkC z7GzaEbm6^`e{KzTN@{UxQD$OJW>qR910w@AHJm6a7#RL?F@`ghtLQz3pIWStmtUfgT9H{?VwK@_ z(?Esgwt+bVgV#+*Aj=V`k(q}TthTb7hex42u~;FwC>3aSO1IOV literal 0 HcmV?d00001 From ecc94cace6639ef90f4fd64bfd100503c8c5a3a3 Mon Sep 17 00:00:00 2001 From: RustamOper05 Date: Fri, 19 Jan 2024 00:53:02 +0300 Subject: [PATCH 6/7] fix spaces --- Comment/comment.json | 1 - Comment/comment.nef | Bin 1062 -> 0 bytes Post/post_contract.json | 1 - Post/post_contract.nef | Bin 922 -> 0 bytes User/user.json | 1 - User/user.nef | Bin 416 -> 0 bytes 6 files changed, 3 deletions(-) delete mode 100755 Comment/comment.json delete mode 100755 Comment/comment.nef delete mode 100755 Post/post_contract.json delete mode 100755 Post/post_contract.nef delete mode 100755 User/user.json delete mode 100755 User/user.nef diff --git a/Comment/comment.json b/Comment/comment.json deleted file mode 100755 index 6702245..0000000 --- a/Comment/comment.json +++ /dev/null @@ -1 +0,0 @@ -{"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} \ No newline at end of file diff --git a/Comment/comment.nef b/Comment/comment.nef deleted file mode 100755 index a9ba586cf7cdd7792873566ee01fd1a0ee1d5033..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1062 zcmah{PiWIn98Q|frfVjdf2M~GyE4Nr-P+kw-Nl4ig$!k5Lhv9ZwsCn`o0p_no9yf@ zHxCXq2f?dX!HaAR^{_+g!9$D46o!95@gR89`nsfZ&W^oP!uR`q@B6;@UCUoSr%Eun z2$QLabSg8EPHKjfoXRB^Gnuq>>%1sphn?fHX=>AxlaeJ?w6Zi&gq2Awy#D=y_kR1! z*;gBn6#K)afhP2xghdkq9K*4mATXhL5E!jW1`x|&MLK9AR+9di!LVO5gn);*hd&oR zO{NBbT9T{+5?7H_lfqLA+{cTj@2~I=3C=q;kV<4lEW|^xH`z;Samm_-iWPWWxCk zzS5|vxe!*5$bYwN2S$9RN(Un4G9(Yt!?#9}snL2AM%{X}hcp=V87zt@6blZFc9hlo zW!PU1L=VpRLB@-QB$`rbI$n0DNIcm&ac6%Jj^$9K48Vp`Ou0k_@8&#$>4Fc6WnmMGIV+EX8$*gG> zL&_&SH*rKh>ACU-Ki_y`&t(W!=nFb-XV-tX+d6G1$i-OSW+I%YpE9R_;?bT(d#g;u k0?Pbr#WfOJ0Og2kyqlTr1Rb^zV9IDbcxd+JjpvX50IMW}4gdfE diff --git a/Post/post_contract.json b/Post/post_contract.json deleted file mode 100755 index 0fd6400..0000000 --- a/Post/post_contract.json +++ /dev/null @@ -1 +0,0 @@ -{"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} \ No newline at end of file diff --git a/Post/post_contract.nef b/Post/post_contract.nef deleted file mode 100755 index 8da50f8ea539d4c69d2c0bd7ed431c6583a82c40..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 922 zcmeZsbu-RO&DTxO*EP^HG%(RK)Ga7V)ipBLO*b(yOii*#Ok^Mom=Ce%#`kmZX{#M z+4I>Q&p&sc<`B-xAaKO7!13Fb>_>%}JS-sPGQp1b4R*{b%5t2;@pg`yewO3sko~e= zHyweVa|C!t>ftx=K#HYCIAh8m0OA+PN71xjZ#9Kx9x!NwJ2R6smZn0Z4@n1>JS zlDzy9g|z(AycDZUubT!yLk!HB7@$TwgtJ3+0-aPSSX5!U3z!6ov$6%}ZB?%aGNB=n z1qzAMj9iH6B{?_L#Ce3kre~*CDj;mgfjKiH2conr51T`><`iW@eUOLYrt^i$jsO4u z&vXc9W`d-EN>c@(Kw*U%N2c((IZAAqBIo900;9GlBUAKT79?uGVE|4qxT6;oDl7tp tz+eC;8ibY#lf#ABv}Fp;gPYC(aSN`5h-o%dgUPW%Og#vLza*{E0005cQ!M}h diff --git a/User/user.json b/User/user.json deleted file mode 100755 index a3ba7fb..0000000 --- a/User/user.json +++ /dev/null @@ -1 +0,0 @@ -{"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} \ No newline at end of file diff --git a/User/user.nef b/User/user.nef deleted file mode 100755 index f91fce873585eae3255cf54cce9232465a67a40f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 416 zcmeZsbu-RO&DTxO*EP^HG%(RK)Ga7V)ipBLO*b(yOii*#Ok^Mom=3(RJon(qOVwkC z7GzaEbm6^`e{KzTN@{UxQD$OJW>qR910w@AHJm6a7#RL?F@`ghtLQz3pIWStmtUfgT9H{?VwK@_ z(?Esgwt+bVgV#+*Aj=V`k(q}TthTb7hex42u~;FwC>3aSO1IOV From 78d398b0be1e7e56a490c6c1acd255069bf4cd69 Mon Sep 17 00:00:00 2001 From: RustamOper05 Date: Fri, 19 Jan 2024 00:58:18 +0300 Subject: [PATCH 7/7] fix confl --- backend/backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/backend.py b/backend/backend.py index 771487c..972013e 100644 --- a/backend/backend.py +++ b/backend/backend.py @@ -91,7 +91,7 @@ user_hash, post_hash, comment_hash = compile_and_deploy_contract( "../Comment", "one", "/home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json", - False + True )