Skip to content

Commit

Permalink
refactor(std): replace IsOriginCall with PrevRealm().IsUser() for EOA…
Browse files Browse the repository at this point in the history
… checks
  • Loading branch information
omarsy committed Dec 22, 2024
1 parent 2e332dd commit 9c5b56b
Show file tree
Hide file tree
Showing 84 changed files with 341 additions and 381 deletions.
12 changes: 0 additions & 12 deletions docs/reference/stdlibs/std/chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ id: chain

# Chain-related

## IsOriginCall
```go
func IsOriginCall() bool
```
Checks if the caller of the function is an EOA. Returns **true** if caller is an EOA, **false** otherwise.

#### Usage
```go
if !std.IsOriginCall() {...}
```
---

## AssertOriginCall
```go
func AssertOriginCall()
Expand Down
3 changes: 3 additions & 0 deletions examples/gno.land/r/demo/banktest/z_0_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package bank1
import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/demo/banktest"
)

Expand All @@ -29,6 +30,8 @@ func main() {
// simulate a Deposit call. use Send + OrigSend to simulate -send.
banker.SendCoins(mainaddr, banktestAddr, std.Coins{{"ugnot", 100_000_000}})
std.TestSetOrigSend(std.Coins{{"ugnot", 100_000_000}}, nil)
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
res := banktest.Deposit("ugnot", 50_000_000)
println("Deposit():", res)

Expand Down
3 changes: 3 additions & 0 deletions examples/gno.land/r/demo/banktest/z_1_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package bank1
import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/demo/banktest"
)

Expand All @@ -18,6 +19,8 @@ func main() {
std.TestSetOrigPkgAddr(banktestAddr)
std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}})
std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil)
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
res := banktest.Deposit("ugnot", 101000000)
println(res)
}
Expand Down
3 changes: 3 additions & 0 deletions examples/gno.land/r/demo/banktest/z_2_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package bank1
import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/demo/banktest"
)

Expand All @@ -26,6 +27,8 @@ func main() {
std.TestSetOrigPkgAddr(banktestAddr)
std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}})
std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil)
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
res := banktest.Deposit("ugnot", 55000000)
println("Deposit():", res)

Expand Down
1 change: 0 additions & 1 deletion examples/gno.land/r/demo/banktest/z_3_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func main() {
banker := std.GetBanker(std.BankerTypeRealmSend)
send := std.Coins{{"ugnot", 123}}
banker.SendCoins(banktestAddr, mainaddr, send)

}

// Error:
Expand Down
12 changes: 6 additions & 6 deletions examples/gno.land/r/demo/boards/public.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func GetBoardIDFromName(name string) (BoardID, bool) {
}

func CreateBoard(name string) BoardID {
if !(std.IsOriginCall() || std.PrevRealm().IsUser()) {
if !std.PrevRealm().IsUser() {
panic("invalid non-user call")
}
bid := incGetBoardID()
Expand All @@ -43,7 +43,7 @@ func checkAnonFee() bool {
}

func CreateThread(bid BoardID, title string, body string) PostID {
if !(std.IsOriginCall() || std.PrevRealm().IsUser()) {
if !std.PrevRealm().IsUser() {
panic("invalid non-user call")
}
caller := std.GetOrigCaller()
Expand All @@ -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.IsOriginCall() || std.PrevRealm().IsUser()) {
if !std.PrevRealm().IsUser() {
panic("invalid non-user call")
}
caller := std.GetOrigCaller()
Expand Down Expand Up @@ -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.IsOriginCall() || std.PrevRealm().IsUser()) {
if !std.PrevRealm().IsUser() {
panic("invalid non-user call")
}
caller := std.GetOrigCaller()
Expand Down Expand Up @@ -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.IsOriginCall() || std.PrevRealm().IsUser()) {
if !std.PrevRealm().IsUser() {
panic("invalid non-user call")
}
caller := std.GetOrigCaller()
Expand Down Expand Up @@ -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.IsOriginCall() || std.PrevRealm().IsUser()) {
if !std.PrevRealm().IsUser() {
panic("invalid non-user call")
}
caller := std.GetOrigCaller()
Expand Down
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
package boards_test

import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
)

var bid boards.BoardID

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
bid = boards.CreateBoard("test_board")
boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)")
pid := boards.CreateThread(bid, "Second Post (title)", "Body of the second post. (body)")
Expand Down
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ package boards_test
// SEND: 19900000ugnot

import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)

var bid boards.BoardID

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
users.Register("", "gnouser", "my profile")
bid = boards.CreateBoard("test_board")
}
Expand Down
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_c_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ package boards_test
// SEND: 200000000ugnot

import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)

var bid boards.BoardID

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
users.Register("", "gnouser", "my profile")
boards.CreateThread(1, "First Post (title)", "Body of the first post. (body)")
}
Expand Down
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_d_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ package boards_test
// SEND: 200000000ugnot

import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)

var bid boards.BoardID

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
users.Register("", "gnouser", "my profile")
bid = boards.CreateBoard("test_board")
boards.CreateReply(bid, 0, 0, "Reply of the second post")
Expand Down
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_e_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ package boards_test
// SEND: 200000000ugnot

import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)

var bid boards.BoardID

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
users.Register("", "gnouser", "my profile")
boards.CreateReply(bid, 0, 0, "Reply of the second post")
}
Expand Down
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/boards/z_0_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ package boards_test
// SEND: 20000000ugnot

import (
"std"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)

var bid boards.BoardID

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
users.Register("", "gnouser", "my profile")

bid = boards.CreateBoard("test_board")
Expand Down
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/boards/z_10_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ package boards_test
// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)
Expand All @@ -16,13 +18,17 @@ var (
)

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
users.Register("", "gnouser", "my profile")

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

func main() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
// boardId 2 not exist
boards.DeletePost(2, pid, pid, "")
Expand Down
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/boards/z_10_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ package boards_test
// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)
Expand All @@ -16,6 +18,8 @@ var (
)

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
users.Register("", "gnouser", "my profile")

bid = boards.CreateBoard("test_board")
Expand All @@ -25,6 +29,8 @@ func init() {
func main() {
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
// pid of 2 not exist
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
boards.DeletePost(bid, 2, 2, "")
println("----------------------------------------------------")
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
Expand Down
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/boards/z_10_c_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ package boards_test
// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)
Expand All @@ -17,6 +19,8 @@ var (
)

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
users.Register("", "gnouser", "my profile")

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

func main() {
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
boards.DeletePost(bid, pid, rid, "")
println("----------------------------------------------------")
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
Expand Down
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/boards/z_10_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ package boards_test
// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)
Expand All @@ -16,13 +18,17 @@ var (
)

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
users.Register("", "gnouser", "my profile")

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

func main() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
boards.DeletePost(bid, pid, pid, "")
println("----------------------------------------------------")
Expand Down
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/boards/z_11_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ package boards_test
// SEND: 200000000ugnot

import (
"std"
"strconv"

"gno.land/p/demo/testutils"
"gno.land/r/demo/boards"
"gno.land/r/demo/users"
)
Expand All @@ -16,6 +18,8 @@ var (
)

func init() {
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
users.Register("", "gnouser", "my profile")

bid = boards.CreateBoard("test_board")
Expand All @@ -25,6 +29,8 @@ func init() {
func main() {
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
// board 2 not exist
caller := testutils.TestAddress("caller")
std.TestSetRealm(std.NewUserRealm(caller))
boards.EditPost(2, pid, pid, "Edited: First Post in (title)", "Edited: Body of the first post. (body)")
println("----------------------------------------------------")
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
Expand Down
Loading

0 comments on commit 9c5b56b

Please sign in to comment.