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

permbook_demo source realm

Package permbook\_demo is the reference consumer for the permbook permission primitive. It exists to make permbook's ...

Overview

Package permbook_demo is the reference consumer for the permbook permission primitive. It exists to make permbook's central claim falsifiable on a live chain.

That claim is: a permission revoked in transaction N is refused in transaction N+1. A pure package cannot demonstrate this — a vm/qeval is a single ephemeral evaluation and nothing it writes survives it. Only a realm, called across several transactions, can show a grant taking effect and then a revoke taking it away. So this realm is not a decoration on the primitive; it is the experiment.

What it does

Two permission-gated actions, deliberately trivial so that the only interesting thing about them is the gate:

  • bump — increments a counter and records who did it
  • notice — replaces a short public notice

Neither action is reachable without the corresponding permission. The deployer is the book's admin and is the only account that may grant or revoke. Holding "bump" confers no authority over the book itself: a holder cannot grant, cannot revoke, and cannot nominate. That separation is the property being demonstrated.

How it wires permbook correctly

This realm is also the worked example of permbook's consumer contract:

  • every permbook mutator is called from a CROSSING entrypoint, passing that entrypoint's own cur, so the principal permbook resolves is this realm's immediate caller (contract 1);
  • the *Book is an unexported package-level var and is never returned across a realm boundary (contract 2);
  • Has is asked about an address this realm derived itself from cur.Previous().Address(), never about a parameter (contract 3);
  • the limits are chosen once, at init, and documented below (contract 4).

This realm holds no coins and imports no banker. Every crossing entrypoint rejects attached coins; the read views are non-crossing, which MsgCall will not dispatch to, so no transaction can attach coins to one.

Constants 2

const PermBump, PermNotice

1const (
2	PermBump   = "bump"
3	PermNotice = "notice"
4)
source

The permission names this realm gates on. They are constants rather than caller-supplied strings for the gated actions, so a typo cannot silently create an unenforced gate.

const MaxPermissions, MaxHolders, MaxNameLen, MaxNoticeLen, MaxListed

 1const (
 2	// The book's limits. Deliberately far below permbook's ceilings: this
 3	// realm needs two permissions and a handful of holders, and a bound
 4	// should describe what the application actually does rather than the
 5	// most the library would tolerate. A few spare slots are left so the
 6	// permission limit can be exercised on-chain without wedging the demo.
 7	MaxPermissions = 8
 8	MaxHolders     = 32
 9	MaxNameLen     = 24
10
11	// MaxNoticeLen bounds the public notice. A BYTE length, not a rune
12	// count, because its job is to bound storage.
13	MaxNoticeLen = 200
14
15	// MaxListed caps how many rows any single query or view returns, so no
16	// read is unbounded regardless of how full the book is.
17	MaxListed = 50
18)
source

Functions 25

func AcceptAdmin

crossing Action
1func AcceptAdmin(cur realm) string
source

AcceptAdmin completes a pending handoff. Only the nominee may call it.

func Bump

crossing Action
1func Bump(cur realm) string
source

Bump increments the counter. Requires the "bump" permission.

This is the experiment: call it with the permission and it succeeds; have the admin revoke, call it again in a later transaction, and it aborts.

func Bumps

Action
1func Bumps() int64
source

Bumps returns how many times Bump has succeeded.

func CanBump

Action
1func CanBump(addr address) bool
source

CanBump reports whether addr would be allowed to call Bump right now.

func DropPermission

crossing Action
1func DropPermission(cur realm, perm string) string
source

DropPermission removes a permission and every grant of it. Admin only.

func Grant

crossing Action
1func Grant(cur realm, perm string, addr address) string
source

Grant gives addr a permission. Admin only.

func Has

Action
1func Has(perm string, addr address) bool
source

Has reports whether addr holds perm. This is the primitive's core query, exposed verbatim so it can be checked from off-chain.

func Height

Action
1func Height() int64
source

Height returns the chain height this realm is reading as "now".

func HolderCount

Action
1func HolderCount(perm string) int
source

HolderCount returns how many addresses hold perm, or 0 if it does not exist.

func Holders

Action
1func Holders(perm string) string
source

Holders returns up to MaxListed holders of perm, comma-separated in sorted order.

func LastBump

Action
1func LastBump() string
source

LastBump describes the most recent successful Bump, or "none".

func NominateAdmin

crossing Action
1func NominateAdmin(cur realm, nominee address) string
source

NominateAdmin records a nominee for the admin role. Admin only. The handoff does not take effect until the nominee calls AcceptAdmin.

func PendingAdmin

Action
1func PendingAdmin() string
source

PendingAdmin returns the nominated-but-not-yet-accepted admin, or "".

func Permissions

Action
1func Permissions() string
source

Permissions returns up to MaxListed permission names, comma-separated in lexicographic order.

func PermissionsOf

Action
1func PermissionsOf(addr address) string
source

PermissionsOf returns the permissions addr holds, comma-separated in lexicographic order, or "" for none. Names are restricted by permbook to lowercase alphanumerics and underscore, so a comma can never appear in one and this encoding is unambiguous.

func Ready

Action
1func Ready() bool
source

Ready reports whether init captured a deploy-time admin and constructed the book. False means the realm is inert; see the note in init.

func Render

1func Render(path string) string
source

Render serves three views, selected by path.

Example
1(empty)  summary, the permission table, and the gated state
2holders  every permission with its holders, up to MaxListed each
3about    what this realm is and why it exists

An inert realm (see init) reports that instead of rendering. Every view reads the book, so without this the gnoweb page would abort on a nil dereference — which is exactly the moment an operator needs it to say what is wrong. The typed read functions still abort when inert; Ready is the probe that answers the question without panicking.

func Revoke

crossing Action
1func Revoke(cur realm, perm string, addr address) string
source

Revoke removes a permission from addr. Admin only.

The revoke is committed by this transaction. Any later transaction that reaches a gate on that permission is refused — that is the claim.

func RevokeAll

crossing Action
1func RevokeAll(cur realm, addr address) string
source

RevokeAll removes every permission addr holds and reports how many. Admin only.

func SetNotice

crossing Action
1func SetNotice(cur realm, text string) string
source

SetNotice replaces the public notice. Requires the "notice" permission.

It exists so the demo shows two INDEPENDENT permissions on one book: holding "bump" does not let an address set the notice, and revoking one leaves the other intact.

Imports 6

Source Files 2