realmid.gno
0.77 Kb ยท 36 lines
1package realmid
2
3import (
4 "chain/runtime"
5 "strings"
6)
7
8// Returns the identifier of the previous realm in the call chain.
9func Previous() string {
10 r := runtime.PreviousRealm()
11 if r.IsUser() {
12 return r.Address().String()
13 }
14 return r.PkgPath()
15}
16
17// Returns the identifier of the current realm.
18func Current() string {
19 r := runtime.CurrentRealm()
20 if r.IsUser() {
21 return r.Address().String()
22 }
23 return r.PkgPath()
24}
25
26// Checks if the given identifier is a package path.
27// Package paths contain dots (e.g., "gno.land/p/demo/users").
28func IsPackage(id string) bool {
29 return strings.ContainsRune(id, '.')
30}
31
32// Checks if the given identifier is a user address.
33// User addresses don't contain dots (e.g., "g1abc...def").
34func IsUser(id string) bool {
35 return !IsPackage(id)
36}