1package groups23import "gno.land/p/moul/addrset/v0"45// Role is a named bucket of addresses with optional metadata.6//7// A Role is always owned by a parent Group; the only way to obtain a *Role8// is Group.AddRole or Group.GetRole. See the Group doc for the realm-9// boundary rules that govern passing *Role values around.10type Role struct {11 name string12 members *addrset.Set13 meta any14}1516// newRole constructs a new empty role with the given name. Unexported: the17// only valid path to a *Role is via Group.AddRole, which registers it in18// the parent Group's role registry. A detached Role has no useful API.19func newRole(name string) *Role {20 return &Role{21 name: name,22 members: &addrset.Set{},23 }24}2526// Name returns the role's registry name.27func (r *Role) Name() string {28 return r.name29}3031// Members returns a mutable reference to the role's member set; mutations32// through the returned pointer affect the role.33//34// SECURITY: the returned *addrset.Set is mutable. Do not expose it to35// untrusted callers — use Role.Readonly().Members() for a36// cross-realm-safe view.37func (r *Role) Members() *addrset.Set {38 return r.members39}4041// Meta returns the role's metadata slot. See the package doc for the rule42// against storing mutable pointers in meta.43func (r *Role) Meta() any {44 return r.meta45}4647// SetMeta sets the role's metadata slot. Passing nil clears it.48//49// SECURITY: do NOT store a pointer whose type has a mutator method (this50// includes common /p/ types like *addrset.Set or *avl.Tree) if untrusted51// realms may hold a Readonly() view of this Group. Meta() returns the stored52// value as-is, so a foreign reader can invoke that method and borrow rule #253// commits the write under this (the allocating) realm's authority. A direct54// field write through the pointer is still blocked by the realm-ownership55// gate — the leak is specifically mutator-method dispatch. Prefer value types56// with no internal pointers. See the package doc.57func (r *Role) SetMeta(meta any) {58 r.meta = meta59}6061// Readonly returns a read-only view of the role.62func (r *Role) Readonly() *ReadonlyRole {63 return &ReadonlyRole{role: r}64}65Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.