Skip to content

Commit 74b10b7

Browse files
omarsythehowl
authored andcommitted
feat(stdlibs/std)!: replace IsOriginCall with PrevRealm().IsUser() for EOA checks (#3399)
Linked to #1475 --------- Co-authored-by: Morgan Bazalgette <[email protected]>
1 parent 95a18a9 commit 74b10b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+227
-103
lines changed

docs/reference/stdlibs/std/chain.md

-12
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ id: chain
44

55
# Chain-related
66

7-
## IsOriginCall
8-
```go
9-
func IsOriginCall() bool
10-
```
11-
Checks if the caller of the function is an EOA. Returns **true** if caller is an EOA, **false** otherwise.
12-
13-
#### Usage
14-
```go
15-
if !std.IsOriginCall() {...}
16-
```
17-
---
18-
197
## AssertOriginCall
208
```go
219
func AssertOriginCall()

examples/gno.land/r/demo/banktest/z_3_filetest.gno

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ func main() {
1818
banker := std.GetBanker(std.BankerTypeRealmSend)
1919
send := std.Coins{{"ugnot", 123}}
2020
banker.SendCoins(banktestAddr, mainaddr, send)
21-
2221
}
2322

2423
// Error:

examples/gno.land/r/demo/boards/public.gno

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func GetBoardIDFromName(name string) (BoardID, bool) {
1717
}
1818

1919
func CreateBoard(name string) BoardID {
20-
if !(std.IsOriginCall() || std.PrevRealm().IsUser()) {
20+
if !std.PrevRealm().IsUser() {
2121
panic("invalid non-user call")
2222
}
2323
bid := incGetBoardID()
@@ -43,7 +43,7 @@ func checkAnonFee() bool {
4343
}
4444

4545
func CreateThread(bid BoardID, title string, body string) PostID {
46-
if !(std.IsOriginCall() || std.PrevRealm().IsUser()) {
46+
if !std.PrevRealm().IsUser() {
4747
panic("invalid non-user call")
4848
}
4949
caller := std.GetOrigCaller()
@@ -61,7 +61,7 @@ func CreateThread(bid BoardID, title string, body string) PostID {
6161
}
6262

6363
func CreateReply(bid BoardID, threadid, postid PostID, body string) PostID {
64-
if !(std.IsOriginCall() || std.PrevRealm().IsUser()) {
64+
if !std.PrevRealm().IsUser() {
6565
panic("invalid non-user call")
6666
}
6767
caller := std.GetOrigCaller()
@@ -91,7 +91,7 @@ func CreateReply(bid BoardID, threadid, postid PostID, body string) PostID {
9191
// If dstBoard is private, does not ping back.
9292
// If board specified by bid is private, panics.
9393
func CreateRepost(bid BoardID, postid PostID, title string, body string, dstBoardID BoardID) PostID {
94-
if !(std.IsOriginCall() || std.PrevRealm().IsUser()) {
94+
if !std.PrevRealm().IsUser() {
9595
panic("invalid non-user call")
9696
}
9797
caller := std.GetOrigCaller()
@@ -121,7 +121,7 @@ func CreateRepost(bid BoardID, postid PostID, title string, body string, dstBoar
121121
}
122122

123123
func DeletePost(bid BoardID, threadid, postid PostID, reason string) {
124-
if !(std.IsOriginCall() || std.PrevRealm().IsUser()) {
124+
if !std.PrevRealm().IsUser() {
125125
panic("invalid non-user call")
126126
}
127127
caller := std.GetOrigCaller()
@@ -153,7 +153,7 @@ func DeletePost(bid BoardID, threadid, postid PostID, reason string) {
153153
}
154154

155155
func EditPost(bid BoardID, threadid, postid PostID, title, body string) {
156-
if !(std.IsOriginCall() || std.PrevRealm().IsUser()) {
156+
if !std.PrevRealm().IsUser() {
157157
panic("invalid non-user call")
158158
}
159159
caller := std.GetOrigCaller()

examples/gno.land/r/demo/boards/z_0_a_filetest.gno

+5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
package boards_test
33

44
import (
5+
"std"
6+
7+
"gno.land/p/demo/testutils"
58
"gno.land/r/demo/boards"
69
)
710

811
var bid boards.BoardID
912

1013
func init() {
14+
caller := testutils.TestAddress("caller")
15+
std.TestSetRealm(std.NewUserRealm(caller))
1116
bid = boards.CreateBoard("test_board")
1217
boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)")
1318
pid := boards.CreateThread(bid, "Second Post (title)", "Body of the second post. (body)")

examples/gno.land/r/demo/boards/z_0_b_filetest.gno

+5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ package boards_test
44
// SEND: 19900000ugnot
55

66
import (
7+
"std"
8+
9+
"gno.land/p/demo/testutils"
710
"gno.land/r/demo/boards"
811
"gno.land/r/demo/users"
912
)
1013

1114
var bid boards.BoardID
1215

1316
func init() {
17+
caller := testutils.TestAddress("caller")
18+
std.TestSetRealm(std.NewUserRealm(caller))
1419
users.Register("", "gnouser", "my profile")
1520
bid = boards.CreateBoard("test_board")
1621
}

examples/gno.land/r/demo/boards/z_0_c_filetest.gno

+5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ package boards_test
44
// SEND: 200000000ugnot
55

66
import (
7+
"std"
8+
9+
"gno.land/p/demo/testutils"
710
"gno.land/r/demo/boards"
811
"gno.land/r/demo/users"
912
)
1013

1114
var bid boards.BoardID
1215

1316
func init() {
17+
caller := testutils.TestAddress("caller")
18+
std.TestSetRealm(std.NewUserRealm(caller))
1419
users.Register("", "gnouser", "my profile")
1520
boards.CreateThread(1, "First Post (title)", "Body of the first post. (body)")
1621
}

examples/gno.land/r/demo/boards/z_0_d_filetest.gno

+5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ package boards_test
44
// SEND: 200000000ugnot
55

66
import (
7+
"std"
8+
9+
"gno.land/p/demo/testutils"
710
"gno.land/r/demo/boards"
811
"gno.land/r/demo/users"
912
)
1013

1114
var bid boards.BoardID
1215

1316
func init() {
17+
caller := testutils.TestAddress("caller")
18+
std.TestSetRealm(std.NewUserRealm(caller))
1419
users.Register("", "gnouser", "my profile")
1520
bid = boards.CreateBoard("test_board")
1621
boards.CreateReply(bid, 0, 0, "Reply of the second post")

examples/gno.land/r/demo/boards/z_0_e_filetest.gno

+5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ package boards_test
44
// SEND: 200000000ugnot
55

66
import (
7+
"std"
8+
9+
"gno.land/p/demo/testutils"
710
"gno.land/r/demo/boards"
811
"gno.land/r/demo/users"
912
)
1013

1114
var bid boards.BoardID
1215

1316
func init() {
17+
caller := testutils.TestAddress("caller")
18+
std.TestSetRealm(std.NewUserRealm(caller))
1419
users.Register("", "gnouser", "my profile")
1520
boards.CreateReply(bid, 0, 0, "Reply of the second post")
1621
}

examples/gno.land/r/demo/boards/z_0_filetest.gno

+5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ package boards_test
44
// SEND: 20000000ugnot
55

66
import (
7+
"std"
8+
9+
"gno.land/p/demo/testutils"
710
"gno.land/r/demo/boards"
811
"gno.land/r/demo/users"
912
)
1013

1114
var bid boards.BoardID
1215

1316
func init() {
17+
caller := testutils.TestAddress("caller")
18+
std.TestSetRealm(std.NewUserRealm(caller))
1419
users.Register("", "gnouser", "my profile")
1520

1621
bid = boards.CreateBoard("test_board")

examples/gno.land/r/demo/boards/z_10_a_filetest.gno

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ package boards_test
44
// SEND: 200000000ugnot
55

66
import (
7+
"std"
78
"strconv"
89

10+
"gno.land/p/demo/testutils"
911
"gno.land/r/demo/boards"
1012
"gno.land/r/demo/users"
1113
)
@@ -16,13 +18,17 @@ var (
1618
)
1719

1820
func init() {
21+
caller := testutils.TestAddress("caller")
22+
std.TestSetRealm(std.NewUserRealm(caller))
1923
users.Register("", "gnouser", "my profile")
2024

2125
bid = boards.CreateBoard("test_board")
2226
pid = boards.CreateThread(bid, "First Post in (title)", "Body of the first post. (body)")
2327
}
2428

2529
func main() {
30+
caller := testutils.TestAddress("caller")
31+
std.TestSetRealm(std.NewUserRealm(caller))
2632
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
2733
// boardId 2 not exist
2834
boards.DeletePost(2, pid, pid, "")

examples/gno.land/r/demo/boards/z_10_b_filetest.gno

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ package boards_test
44
// SEND: 200000000ugnot
55

66
import (
7+
"std"
78
"strconv"
89

10+
"gno.land/p/demo/testutils"
911
"gno.land/r/demo/boards"
1012
"gno.land/r/demo/users"
1113
)
@@ -16,6 +18,8 @@ var (
1618
)
1719

1820
func init() {
21+
caller := testutils.TestAddress("caller")
22+
std.TestSetRealm(std.NewUserRealm(caller))
1923
users.Register("", "gnouser", "my profile")
2024

2125
bid = boards.CreateBoard("test_board")
@@ -25,6 +29,8 @@ func init() {
2529
func main() {
2630
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
2731
// pid of 2 not exist
32+
caller := testutils.TestAddress("caller")
33+
std.TestSetRealm(std.NewUserRealm(caller))
2834
boards.DeletePost(bid, 2, 2, "")
2935
println("----------------------------------------------------")
3036
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))

examples/gno.land/r/demo/boards/z_10_c_filetest.gno

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ package boards_test
44
// SEND: 200000000ugnot
55

66
import (
7+
"std"
78
"strconv"
89

10+
"gno.land/p/demo/testutils"
911
"gno.land/r/demo/boards"
1012
"gno.land/r/demo/users"
1113
)
@@ -17,6 +19,8 @@ var (
1719
)
1820

1921
func init() {
22+
caller := testutils.TestAddress("caller")
23+
std.TestSetRealm(std.NewUserRealm(caller))
2024
users.Register("", "gnouser", "my profile")
2125

2226
bid = boards.CreateBoard("test_board")
@@ -26,6 +30,8 @@ func init() {
2630

2731
func main() {
2832
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
33+
caller := testutils.TestAddress("caller")
34+
std.TestSetRealm(std.NewUserRealm(caller))
2935
boards.DeletePost(bid, pid, rid, "")
3036
println("----------------------------------------------------")
3137
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))

examples/gno.land/r/demo/boards/z_10_filetest.gno

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ package boards_test
44
// SEND: 200000000ugnot
55

66
import (
7+
"std"
78
"strconv"
89

10+
"gno.land/p/demo/testutils"
911
"gno.land/r/demo/boards"
1012
"gno.land/r/demo/users"
1113
)
@@ -16,13 +18,17 @@ var (
1618
)
1719

1820
func init() {
21+
caller := testutils.TestAddress("caller")
22+
std.TestSetRealm(std.NewUserRealm(caller))
1923
users.Register("", "gnouser", "my profile")
2024

2125
bid = boards.CreateBoard("test_board")
2226
pid = boards.CreateThread(bid, "First Post in (title)", "Body of the first post. (body)")
2327
}
2428

2529
func main() {
30+
caller := testutils.TestAddress("caller")
31+
std.TestSetRealm(std.NewUserRealm(caller))
2632
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
2733
boards.DeletePost(bid, pid, pid, "")
2834
println("----------------------------------------------------")

examples/gno.land/r/demo/boards/z_11_a_filetest.gno

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ package boards_test
44
// SEND: 200000000ugnot
55

66
import (
7+
"std"
78
"strconv"
89

10+
"gno.land/p/demo/testutils"
911
"gno.land/r/demo/boards"
1012
"gno.land/r/demo/users"
1113
)
@@ -16,6 +18,8 @@ var (
1618
)
1719

1820
func init() {
21+
caller := testutils.TestAddress("caller")
22+
std.TestSetRealm(std.NewUserRealm(caller))
1923
users.Register("", "gnouser", "my profile")
2024

2125
bid = boards.CreateBoard("test_board")
@@ -25,6 +29,8 @@ func init() {
2529
func main() {
2630
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
2731
// board 2 not exist
32+
caller := testutils.TestAddress("caller")
33+
std.TestSetRealm(std.NewUserRealm(caller))
2834
boards.EditPost(2, pid, pid, "Edited: First Post in (title)", "Edited: Body of the first post. (body)")
2935
println("----------------------------------------------------")
3036
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))

examples/gno.land/r/demo/boards/z_11_b_filetest.gno

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ package boards_test
44
// SEND: 200000000ugnot
55

66
import (
7+
"std"
78
"strconv"
89

10+
"gno.land/p/demo/testutils"
911
"gno.land/r/demo/boards"
1012
"gno.land/r/demo/users"
1113
)
@@ -16,6 +18,8 @@ var (
1618
)
1719

1820
func init() {
21+
caller := testutils.TestAddress("caller")
22+
std.TestSetRealm(std.NewUserRealm(caller))
1923
users.Register("", "gnouser", "my profile")
2024

2125
bid = boards.CreateBoard("test_board")
@@ -25,6 +29,8 @@ func init() {
2529
func main() {
2630
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
2731
// thread 2 not exist
32+
caller := testutils.TestAddress("caller")
33+
std.TestSetRealm(std.NewUserRealm(caller))
2834
boards.EditPost(bid, 2, pid, "Edited: First Post in (title)", "Edited: Body of the first post. (body)")
2935
println("----------------------------------------------------")
3036
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))

examples/gno.land/r/demo/boards/z_11_c_filetest.gno

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ package boards_test
44
// SEND: 200000000ugnot
55

66
import (
7+
"std"
78
"strconv"
89

10+
"gno.land/p/demo/testutils"
911
"gno.land/r/demo/boards"
1012
"gno.land/r/demo/users"
1113
)
@@ -16,6 +18,8 @@ var (
1618
)
1719

1820
func init() {
21+
caller := testutils.TestAddress("caller")
22+
std.TestSetRealm(std.NewUserRealm(caller))
1923
users.Register("", "gnouser", "my profile")
2024

2125
bid = boards.CreateBoard("test_board")
@@ -25,6 +29,8 @@ func init() {
2529
func main() {
2630
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
2731
// post 2 not exist
32+
caller := testutils.TestAddress("caller")
33+
std.TestSetRealm(std.NewUserRealm(caller))
2834
boards.EditPost(bid, pid, 2, "Edited: First Post in (title)", "Edited: Body of the first post. (body)")
2935
println("----------------------------------------------------")
3036
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))

0 commit comments

Comments
 (0)