Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add realm type #2441

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/reference/stdlibs/std/chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ origPkgAddr := std.GetOrigPkgAddr()
```go
func CurrentRealm() Realm
```
Returns current Realm object.
Returns current [Realm](realm.md) object.

[//]: # (todo link to realm type explanation)
#### Usage
```go
currentRealm := std.CurrentRealm()
Expand All @@ -118,7 +117,7 @@ currentRealm := std.CurrentRealm()
```go
func PrevRealm() Realm
```
Returns the previous caller realm (can be code or user realm). If caller is a
Returns the previous caller [realm](realm.md) (can be code or user realm). If caller is a
user realm, `pkgpath` will be empty.

#### Usage
Expand Down
41 changes: 41 additions & 0 deletions docs/reference/stdlibs/std/realm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
id: realm
---

# Realm
Structure representing a realm in Gno. See concept page [here](../../../concepts/realms.md).

```go
type Realm struct {
addr Address
pkgPath string
}

func (r Realm) Addr() Address {...}
func (r Realm) PkgPath() string {...}
func (r Realm) IsUser() bool {...}
```

## Addr
Returns the **Address** field of the realm it was called upon.

#### Usage
```go
realmAddr := r.Addr() // eg. g1n2j0gdyv45aem9p0qsfk5d2gqjupv5z536na3d
```
---
## PkgPath
Returns the **string** package path of the realm it was called upon.

#### Usage
```go
realmPath := r.PkgPath() // eg. gno.land/r/gnoland/blog
```
---
## IsUser
Checks if the realm it was called upon is a user realm.

#### Usage
```go
if r.IsUser() {...}
```
Loading