PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/nt/groups/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
nt / groups
Files
8 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/nt/groups/v0
gno
0.9

Files (8)

  • README.mdmarkdown
  • gnomod.tomltoml
  • doc.gnogno
  • group.gnogno
  • readonly.gnogno
  • role.gnogno
  • groups_test.gnogno
  • z_readme_filetest.gnogno
  • z_readme_filetest.gnogno
    1// End-to-end scenario from the package README: a group with a base set and2// three roles, exercising base vs aggregated semantics, dedup, role3// removal, and readonly views.4package main56import (7	"strings"

    Functions

    not supported for pure packages by the node (vm/qfuncs)

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.

    8
    9 "gno.land/p/nt/groups/v0"
    10)
    11
    12var (
    13 alice = address("alice") // base only
    14 bob = address("bob") // base + council
    15 carol = address("carol") // base + admin
    16 dave = address("dave") // council only
    17 eve = address("eve") // admin + moderator
    18 frank = address("frank") // moderator only
    19 grace = address("grace") // admin only
    20 zed = address("zed") // not a member
    21)
    22
    23func main() {
    24 // 1. A group with a base set and three named roles.
    25 g := groups.NewGroup()
    26 g.Add(alice)
    27 g.Add(bob)
    28 g.Add(carol)
    29
    30 admin, _ := g.AddRole("admin")
    31 admin.Members().Add(carol)
    32 admin.Members().Add(eve)
    33 admin.Members().Add(grace)
    34
    35 council, _ := g.AddRole("council")
    36 council.Members().Add(bob)
    37 council.Members().Add(dave)
    38
    39 moderator, _ := g.AddRole("moderator")
    40 moderator.Members().Add(eve)
    41 moderator.Members().Add(frank)
    42
    43 // 2. Has (base only) vs HasAny (base + roles).
    44 println("Has(alice):", g.Has(alice)) // base member
    45 println("Has(dave):", g.Has(dave)) // council only, not base
    46 println("HasAny(dave):", g.HasAny(dave)) // somewhere in the group
    47 println("HasAny(zed):", g.HasAny(zed)) // nowhere
    48
    49 // 3. Size (base only) vs TotalSize (deduplicated across everything).
    50 println("Size:", g.Size())
    51 println("TotalSize:", g.TotalSize())
    52
    53 // 4. Iterate walks the base set; IterateAll walks base then roles in
    54 // name order, yielding each distinct address once.
    55 print("Iterate:")
    56 g.Iterate(0, 10, func(a address) bool {
    57 print(" " + string(a))
    58 return false
    59 })
    60 println()
    61 print("IterateAll:")
    62 g.IterateAll(0, 10, func(a address) bool {
    63 print(" " + string(a))
    64 return false
    65 })
    66 println()
    67
    68 // 5. RolesContaining lists role names in lexicographic order; the
    69 // base set is not a role.
    70 println("RolesContaining(eve):", strings.Join(g.RolesContaining(eve), ","))
    71 println("RolesContaining(alice):", strings.Join(g.RolesContaining(alice), ","))
    72
    73 // 6. Removing a role discards only the role: its members survive in
    74 // the base set and in other roles.
    75 g.RemoveRole("admin")
    76 println("after RemoveRole(admin):")
    77 println("Has(carol):", g.Has(carol)) // still a base member
    78 println("HasAny(eve):", g.HasAny(eve)) // still a moderator
    79 println("HasAny(grace):", g.HasAny(grace)) // was admin only, now gone
    80 println("TotalSize:", g.TotalSize())
    81
    82 // 7. A readonly view mirrors every read and exposes no mutators; it
    83 // is the only handle meant to cross a realm boundary.
    84 rg := g.Readonly()
    85 println("readonly Size:", rg.Size())
    86 println("readonly HasAny(dave):", rg.HasAny(dave))
    87 rr, _ := rg.GetRole("moderator")
    88 println("readonly moderator members:", rr.Members().Size())
    89}
    90
    91// Output:
    92// Has(alice): true
    93// Has(dave): false
    94// HasAny(dave): true
    95// HasAny(zed): false
    96// Size: 3
    97// TotalSize: 7
    98// Iterate: alice bob carol
    99// IterateAll: alice bob carol eve grace dave frank
    100// RolesContaining(eve): admin,moderator
    101// RolesContaining(alice):
    102// after RemoveRole(admin):
    103// Has(carol): true
    104// HasAny(eve): true
    105// HasAny(grace): false
    106// TotalSize: 6
    107// readonly Size: 3
    108// readonly HasAny(dave): true
    109// readonly moderator members: 2
    110