From c4ce73c4cbe4f30a2c843bec8b028a9fd4239421 Mon Sep 17 00:00:00 2001 From: Jeff Thompson Date: Fri, 14 Jun 2024 10:38:13 +0200 Subject: [PATCH 1/2] chore: In r/demo/boards public API, change AssertOriginCall() to PrevRealm().IsUser() Signed-off-by: Jeff Thompson --- examples/gno.land/r/demo/boards/public.gno | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/examples/gno.land/r/demo/boards/public.gno b/examples/gno.land/r/demo/boards/public.gno index 1ef2e72f4c2..db545446641 100644 --- a/examples/gno.land/r/demo/boards/public.gno +++ b/examples/gno.land/r/demo/boards/public.gno @@ -17,7 +17,9 @@ func GetBoardIDFromName(name string) (BoardID, bool) { } func CreateBoard(name string) BoardID { - std.AssertOriginCall() + if !std.PrevRealm().IsUser() { + panic("invalid non-user call") + } bid := incGetBoardID() caller := std.GetOrigCaller() if usernameOf(caller) == "" { @@ -41,7 +43,9 @@ func checkAnonFee() bool { } func CreateThread(bid BoardID, title string, body string) PostID { - std.AssertOriginCall() + if !std.PrevRealm().IsUser() { + panic("invalid non-user call") + } caller := std.GetOrigCaller() if usernameOf(caller) == "" { if !checkAnonFee() { @@ -57,7 +61,9 @@ func CreateThread(bid BoardID, title string, body string) PostID { } func CreateReply(bid BoardID, threadid, postid PostID, body string) PostID { - std.AssertOriginCall() + if !std.PrevRealm().IsUser() { + panic("invalid non-user call") + } caller := std.GetOrigCaller() if usernameOf(caller) == "" { if !checkAnonFee() { @@ -85,7 +91,9 @@ func CreateReply(bid BoardID, threadid, postid PostID, body string) PostID { // If dstBoard is private, does not ping back. // If board specified by bid is private, panics. func CreateRepost(bid BoardID, postid PostID, title string, body string, dstBoardID BoardID) PostID { - std.AssertOriginCall() + if !std.PrevRealm().IsUser() { + panic("invalid non-user call") + } caller := std.GetOrigCaller() if usernameOf(caller) == "" { // TODO: allow with gDefaultAnonFee payment. @@ -113,7 +121,9 @@ func CreateRepost(bid BoardID, postid PostID, title string, body string, dstBoar } func DeletePost(bid BoardID, threadid, postid PostID, reason string) { - std.AssertOriginCall() + if !std.PrevRealm().IsUser() { + panic("invalid non-user call") + } caller := std.GetOrigCaller() board := getBoard(bid) if board == nil { @@ -143,7 +153,9 @@ func DeletePost(bid BoardID, threadid, postid PostID, reason string) { } func EditPost(bid BoardID, threadid, postid PostID, title, body string) { - std.AssertOriginCall() + if !std.PrevRealm().IsUser() { + panic("invalid non-user call") + } caller := std.GetOrigCaller() board := getBoard(bid) if board == nil { From fe4379b251ca262dfce0c823d3e5b3076e14572d Mon Sep 17 00:00:00 2001 From: Jeff Thompson Date: Mon, 17 Jun 2024 09:54:59 +0200 Subject: [PATCH 2/2] chore: In r/demo/boards public API, also allow std.IsOriginCall() Signed-off-by: Jeff Thompson --- examples/gno.land/r/demo/boards/public.gno | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/gno.land/r/demo/boards/public.gno b/examples/gno.land/r/demo/boards/public.gno index db545446641..1d26126fcb2 100644 --- a/examples/gno.land/r/demo/boards/public.gno +++ b/examples/gno.land/r/demo/boards/public.gno @@ -17,7 +17,7 @@ func GetBoardIDFromName(name string) (BoardID, bool) { } func CreateBoard(name string) BoardID { - if !std.PrevRealm().IsUser() { + if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { panic("invalid non-user call") } bid := incGetBoardID() @@ -43,7 +43,7 @@ func checkAnonFee() bool { } func CreateThread(bid BoardID, title string, body string) PostID { - if !std.PrevRealm().IsUser() { + if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { panic("invalid non-user call") } caller := std.GetOrigCaller() @@ -61,7 +61,7 @@ func CreateThread(bid BoardID, title string, body string) PostID { } func CreateReply(bid BoardID, threadid, postid PostID, body string) PostID { - if !std.PrevRealm().IsUser() { + if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { panic("invalid non-user call") } caller := std.GetOrigCaller() @@ -91,7 +91,7 @@ func CreateReply(bid BoardID, threadid, postid PostID, body string) PostID { // If dstBoard is private, does not ping back. // If board specified by bid is private, panics. func CreateRepost(bid BoardID, postid PostID, title string, body string, dstBoardID BoardID) PostID { - if !std.PrevRealm().IsUser() { + if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { panic("invalid non-user call") } caller := std.GetOrigCaller() @@ -121,7 +121,7 @@ func CreateRepost(bid BoardID, postid PostID, title string, body string, dstBoar } func DeletePost(bid BoardID, threadid, postid PostID, reason string) { - if !std.PrevRealm().IsUser() { + if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { panic("invalid non-user call") } caller := std.GetOrigCaller() @@ -153,7 +153,7 @@ func DeletePost(bid BoardID, threadid, postid PostID, reason string) { } func EditPost(bid BoardID, threadid, postid PostID, title, body string) { - if !std.PrevRealm().IsUser() { + if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { panic("invalid non-user call") } caller := std.GetOrigCaller()