Skip to content

Commit

Permalink
docs: add realm type (gnolang#2441)
Browse files Browse the repository at this point in the history
This adds the `Realm` type definition to the `std` package reference
docs and links is appropriately.

---------

Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com>
  • Loading branch information
deelawn and leohhhn authored Jun 27, 2024
1 parent 3901e7e commit f6235fd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
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() {...}
```

0 comments on commit f6235fd

Please sign in to comment.