From 8d90e22772cfac6f6e773198cd74535dae4cdf30 Mon Sep 17 00:00:00 2001 From: RustamOper05 Date: Wed, 17 Jan 2024 12:31:41 +0300 Subject: [PATCH] add post validation --- Post/post_contract.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Post/post_contract.go b/Post/post_contract.go index 60b3987..4755858 100755 --- a/Post/post_contract.go +++ b/Post/post_contract.go @@ -75,8 +75,18 @@ func GetAllPostsByUser(login string) []Post { i := 1 n := getPostIndex(login) for i < n+1 { - post_key := storage.Get(ctx, login+"_p_"+std.Itoa10(i)).(string) + post_key := storage.Get(ctx, login+"_p_"+std.Itoa10(i)) + if post_key == nil { + panic("post key not found") + } + + post_key = post_key.(string) + post := storage.Get(ctx, post_key) + if post == nil { + panic("post not found") + } + i++ postsByUser = append(postsByUser, std.Deserialize(post.([]byte)).(Post)) }