Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v1 source pure

Package membership is the Remix Lab membership block: an address-based member set with owner/reviewer/member roles, i...

Overview

Package membership is the Remix Lab membership block: an address-based member set with owner/reviewer/member roles, invitation or open joining, and bounded listing.

A host realm constructs a *Set, keeps it in an unexported variable and authenticates every mutation before calling it. The Set enforces its own invariants (limits, last-owner protection, join rules) but not who may administer it: that is the host's policy decision. Never export the *Set or return it from a realm function; any holder of the pointer can call its mutating methods with the host's storage authority.

Membership is address-based. One address is not one human.

Constants 2

const HardMaxMembers

1const HardMaxMembers = 1000
source

HardMaxMembers bounds MaxMembers regardless of configuration.

Functions 1

func New

1func New(cfg Config, owner address) *Set
source

New creates a set whose first member is owner. It panics on invalid configuration or owner, since a host realm calls it from init.

Types 3

type Config

struct
1type Config struct {
2	JoinMode   JoinMode
3	MaxMembers int // includes owners and reviewers
4}
source

Config is the block configuration, fixed at construction.

Methods on Config

func Validate

method on Config
1func (c Config) Validate() error
source

Validate checks configuration bounds.

type JoinMode

ident
1type JoinMode int
source

JoinMode controls how a non-member becomes a member through Join.

Methods on JoinMode

func String

method on JoinMode
1func (m JoinMode) String() string
source

type Set

struct
1type Set struct {
2	cfg     Config
3	members *avl.Tree // address string -> core.Role
4	invites *avl.Tree // address string -> core.Role (role granted on Join)
5	owners  int
6}
source

Set is a membership set. The zero value is not usable; call New.

Methods on Set

func Add

method on Set
1func (s *Set) Add(addr address, role core.Role) error
source

Add directly adds addr with role. The host must have authorized the actor.

func Config

method on Set
1func (s *Set) Config() Config
source

Config returns the set's configuration.

func Invite

method on Set
1func (s *Set) Invite(addr address, role core.Role) error
source

Invite records a pending invitation granting role on Join. Only valid in invitation mode. Pending invitations count against MaxMembers so that accepting every invitation can never exceed the limit.

func InviteRole

method on Set
1func (s *Set) InviteRole(addr address) (core.Role, bool)
source

InviteRole returns the role a pending invitation for addr grants.

func Invites

method on Set
1func (s *Set) Invites(offset, limit int) []core.MemberView
source

Invites returns up to limit pending invitations starting at offset, ordered by address, with the role each one grants.

func IsInvited

method on Set
1func (s *Set) IsInvited(addr address) bool
source

IsInvited reports whether addr holds a pending invitation.

func IsMember

method on Set
1func (s *Set) IsMember(addr address) bool
source

IsMember reports whether addr holds any role.

func Join

method on Set
1func (s *Set) Join(actor address) error
source

Join adds actor as a member. actor must be the authenticated caller.

func Leave

method on Set
1func (s *Set) Leave(actor address) error
source

Leave removes actor. actor must be the authenticated caller. The last owner cannot leave.

func List

method on Set
1func (s *Set) List(offset, limit int) []core.MemberView
source

List returns up to limit members starting at offset, ordered by address.

func Owners

method on Set
1func (s *Set) Owners() int
source

Owners returns the number of owners.

func PendingInvites

method on Set
1func (s *Set) PendingInvites() int
source

PendingInvites returns the number of pending invitations.

func Remove

method on Set
1func (s *Set) Remove(addr address) error
source

Remove removes addr. The host must have authorized the actor. The last owner cannot be removed.

func RevokeInvite

method on Set
1func (s *Set) RevokeInvite(addr address) error
source

RevokeInvite removes a pending invitation.

func RoleOf

method on Set
1func (s *Set) RoleOf(addr address) core.Role
source

RoleOf returns addr's role, RoleNone for non-members.

func SetRole

method on Set
1func (s *Set) SetRole(addr address, role core.Role) error
source

SetRole changes an existing member's role. Demoting the last owner fails.

func Size

method on Set
1func (s *Set) Size() int
source

Size returns the number of members.

func Snapshot

method on Set
1func (s *Set) Snapshot(minRole core.Role, max int) ([]address, bool)
source

Snapshot implements core.MembershipReader. A negative max or an invalid minRole yields (nil, false).

Dependencies

Imports 2

/p/g1lnkytfqcjwllws63gvf0mv9yt04aswy4y9amhm/remixlab/membership/v1

Imported by indexer

Source Files 2