From 3db0a8c1d248f8590bd7fb6a44ccb8e3b6b7ad45 Mon Sep 17 00:00:00 2001 From: deelawn Date: Tue, 25 Jun 2024 15:30:47 -0700 Subject: [PATCH 1/3] add realm type --- docs/reference/stdlibs/std/chain.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index f3dddaba938..706820fe70e 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -4,6 +4,19 @@ id: chain # Chain-related +## Realm +This is the type returned by [std.CurrentRealm](#currentrealm) and [std.PrevRealm](#prevrealm). +```go +type Realm struct { + addr Address + pkgPath string +} + +func (r Realm) Addr() Address +func (r Realm) PkgPath() string +func (r Realm) IsUser() bool +``` + ## IsOriginCall ```go func IsOriginCall() bool @@ -105,9 +118,8 @@ origPkgAddr := std.GetOrigPkgAddr() ```go func CurrentRealm() Realm ``` -Returns current Realm object. +Returns current [Realm](#realm) object. -[//]: # (todo link to realm type explanation) #### Usage ```go currentRealm := std.CurrentRealm() @@ -118,7 +130,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) (can be code or user realm). If caller is a user realm, `pkgpath` will be empty. #### Usage From a0220caa60f5aff21e9f96830686a54b3e456fb7 Mon Sep 17 00:00:00 2001 From: deelawn Date: Tue, 25 Jun 2024 15:32:36 -0700 Subject: [PATCH 2/3] phrasing --- docs/reference/stdlibs/std/chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index 706820fe70e..c0e99cf9d20 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -5,7 +5,7 @@ id: chain # Chain-related ## Realm -This is the type returned by [std.CurrentRealm](#currentrealm) and [std.PrevRealm](#prevrealm). +Returned by [std.CurrentRealm](#currentrealm) and [std.PrevRealm](#prevrealm). ```go type Realm struct { addr Address From ed94e2cb72dffc3f832e30bef330a7ec9d85edd6 Mon Sep 17 00:00:00 2001 From: deelawn Date: Thu, 27 Jun 2024 09:49:41 -0700 Subject: [PATCH 3/3] updated with new realm page --- docs/reference/stdlibs/std/chain.md | 17 ++---------- docs/reference/stdlibs/std/realm.md | 41 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 docs/reference/stdlibs/std/realm.md diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index c0e99cf9d20..f8d3cba13bb 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -4,19 +4,6 @@ id: chain # Chain-related -## Realm -Returned by [std.CurrentRealm](#currentrealm) and [std.PrevRealm](#prevrealm). -```go -type Realm struct { - addr Address - pkgPath string -} - -func (r Realm) Addr() Address -func (r Realm) PkgPath() string -func (r Realm) IsUser() bool -``` - ## IsOriginCall ```go func IsOriginCall() bool @@ -118,7 +105,7 @@ origPkgAddr := std.GetOrigPkgAddr() ```go func CurrentRealm() Realm ``` -Returns current [Realm](#realm) object. +Returns current [Realm](realm.md) object. #### Usage ```go @@ -130,7 +117,7 @@ currentRealm := std.CurrentRealm() ```go func PrevRealm() Realm ``` -Returns the previous caller [realm](#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 diff --git a/docs/reference/stdlibs/std/realm.md b/docs/reference/stdlibs/std/realm.md new file mode 100644 index 00000000000..aee63585e37 --- /dev/null +++ b/docs/reference/stdlibs/std/realm.md @@ -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() {...} +``` \ No newline at end of file