diff --git a/Comment/comment.go b/Comment/comment.go index 2e25622..99ae9de 100755 --- a/Comment/comment.go +++ b/Comment/comment.go @@ -96,7 +96,7 @@ func GetByLogin(login string) []Comment { func GetComment(commentId string) Comment { ctx := storage.GetContext() - return storage.Get(ctx, commentId).(Comment) + return std.Deserialize(storage.Get(ctx, commentId).([]byte)).(Comment) } func GetCommentInPost(commentId string, postId string) Comment { diff --git a/Comment/comment.json b/Comment/comment.json new file mode 100755 index 0000000..4557eea --- /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":33,"parameters":[{"name":"userLogin","type":"String"},{"name":"postId","type":"String"},{"name":"text","type":"String"}],"returntype":"Void","safe":false},{"name":"getByLogin","offset":560,"parameters":[{"name":"login","type":"String"}],"returntype":"Array","safe":false},{"name":"getByLoginInPost","offset":509,"parameters":[{"name":"postId","type":"String"},{"name":"login","type":"String"}],"returntype":"Array","safe":false},{"name":"getByPostId","offset":410,"parameters":[{"name":"postId","type":"String"}],"returntype":"Array","safe":false},{"name":"getComment","offset":626,"parameters":[{"name":"commentId","type":"String"}],"returntype":"Array","safe":false},{"name":"getCommentInPost","offset":663,"parameters":[{"name":"commentId","type":"String"},{"name":"postId","type":"String"}],"returntype":"Array","safe":false},{"name":"rateComment","offset":768,"parameters":[{"name":"isLike","type":"Boolean"},{"name":"postId","type":"String"},{"name":"commentId","type":"String"}],"returntype":"Void","safe":false},{"name":"updateComment","offset":802,"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 0000000..10b81cf Binary files /dev/null and b/Comment/comment.nef differ diff --git a/Post/post_contract.go b/Post/post_contract.go index ff1e048..596353e 100755 --- a/Post/post_contract.go +++ b/Post/post_contract.go @@ -3,12 +3,12 @@ package Post import ( "github.com/nspcc-dev/neo-go/pkg/interop/iterator" "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 Post struct { postName string - header string text string login string likes int @@ -40,18 +40,24 @@ func NewPost(login string, text string, postName string) { storage.Put(ctx, post.id, std.Serialize(post)) updatePostIndex(login) - lastPostIndex := storage.Get(ctx, login+lastIndex).(string) - storage.Put(ctx, login+"_p_"+lastPostIndex, post.id) + lastPostIndex := storage.Get(ctx, login+lastIndex).(int) + storage.Put(ctx, login+"_p_"+std.Itoa10(lastPostIndex), post.id) + runtime.Log("BLIN BLINSKIY POST " + post.id + "--------" + login + "_p_" + std.Itoa10(lastPostIndex)) + runtime.Log("AIDISHNIK " + storage.Get(ctx, post.id).(string)) } func GetAllPosts() []Post { posts := make([]Post, 0) ctx := storage.GetReadOnlyContext() + runtime.Log("SUUUUUDAAAAAAAAAAAAAAAAA SUKA xyu") it := storage.Find(ctx, "post", storage.ValuesOnly|storage.DeserializeValues) for iterator.Next(it) { post := iterator.Value(it).(Post) + runtime.Log("SUUUUUDAAAAAAAAAAAAAAAAA SUKA") + runtime.Log(string(std.Serialize(post))) posts = append(posts, post) } + return posts } @@ -68,11 +74,14 @@ func GetPost(postId string) Post { func GetAllPostsByUser(login string) []Post { ctx := storage.GetReadOnlyContext() - var postsByUser []Post - i := 0 + var postsByUser []Post = make([]Post, 0) + i := 1 n := getPostIndex(login) - for i < n { - post := storage.Get(ctx, login+"_p_"+std.Itoa10(i)) + runtime.Log("N NUM BLIN BLIN" + std.Itoa10(n)) + for i < n+1 { + post_key := storage.Get(ctx, login+"_p_"+std.Itoa10(i)).(string) + runtime.Log("SUKA POSTKEY " + post_key) + post := storage.Get(ctx, post_key) i++ postsByUser = append(postsByUser, std.Deserialize(post.([]byte)).(Post)) } diff --git a/Post/post_contract.json b/Post/post_contract.json new file mode 100755 index 0000000..42cb7ec --- /dev/null +++ b/Post/post_contract.json @@ -0,0 +1 @@ +{"name":"Post","abi":{"methods":[{"name":"getAllPosts","offset":249,"parameters":[],"returntype":"Array","safe":false},{"name":"getAllPostsByUser","offset":466,"parameters":[{"name":"login","type":"String"}],"returntype":"Array","safe":false},{"name":"getPost","offset":408,"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":621,"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 0000000..493628a Binary files /dev/null and b/Post/post_contract.nef differ diff --git a/User/user.go b/User/user.go index 6371303..d375812 100755 --- a/User/user.go +++ b/User/user.go @@ -21,7 +21,6 @@ const ( 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") @@ -38,7 +37,11 @@ func NewUser(name string, surname string, login string, password string, owner i saveUser(ctx, login, user) } -func GetUser(ctx storage.Context, login string) User { +func GetUser(login string) User { + return getUserTst(storage.GetReadOnlyContext(), login) +} + +func getUserTst(ctx storage.Context, login string) User { data := storage.Get(ctx, login) if data == nil { diff --git a/User/user.json b/User/user.json new file mode 100755 index 0000000..accd33d --- /dev/null +++ b/User/user.json @@ -0,0 +1 @@ +{"name":"user","abi":{"methods":[{"name":"getUser","offset":80,"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}],"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 0000000..b2cc98d Binary files /dev/null and b/User/user.nef differ