Search Apps Documentation Source Content File Folder Download Copy Actions Download

/p/samcrew/realmid

Directory ยท 3 Files
README.md Open

realm_id: Realm and User Identification Utilities

realmid provides simple functions to identify callers in the Gno ecosystem - whether they're users or packages.

Functions

 1// Get the previous caller (user address or package path)
 2func Previous() string
 3
 4// Get the current realm identifier  
 5func Current() string
 6
 7// Check if an ID is a package path (contains dots)
 8func IsPackage(id string) bool
 9
10// Check if an ID is a user address (no dots)
11func IsUser(id string) bool

Basic Usage

 1import "gno.land/p/samcrew/realmid"
 2
 3func MyFunction() {
 4    caller := realmid.Previous()
 5    
 6    if realmid.IsUser(caller) {
 7        // caller is a user address like "g1abc123..."
 8        println("Called by user:", caller)
 9    } else if realmid.isPackage(caller) {
10        // caller is a package path like "gno.land/p/demo/users"
11        println("Called by package:", caller)
12    } else {
13        println("Should not happen")
14    }
15}

Integration with basedao

1// Use realmid.Previous as the caller identifier function
2config := &basedao.Config{
3    Name:     "My DAO",
4    CallerID: realmid.Previous,
5    // ...
6}