const PermBump, PermNotice
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.
Package permbook\_demo is the reference consumer for the permbook permission primitive. It exists to make permbook's ...
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.
Two permission-gated actions, deliberately trivial so that the only interesting thing about them is the gate:
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.
This realm is also the worked example of permbook's consumer contract:
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.
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.
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)AcceptAdmin completes a pending handoff. Only the nominee may call it.
Admin returns the book's current admin.
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.
Bumps returns how many times Bump has succeeded.
CanBump reports whether addr would be allowed to call Bump right now.
CancelNomination withdraws a pending nomination. Admin only.
DropPermission removes a permission and every grant of it. Admin only.
Grant gives addr a permission. Admin only.
Has reports whether addr holds perm. This is the primitive's core query, exposed verbatim so it can be checked from off-chain.
Height returns the chain height this realm is reading as "now".
HolderCount returns how many addresses hold perm, or 0 if it does not exist.
Holders returns up to MaxListed holders of perm, comma-separated in sorted order.
LastBump describes the most recent successful Bump, or "none".
Limits reports the book's fixed limits.
NominateAdmin records a nominee for the admin role. Admin only. The handoff does not take effect until the nominee calls AcceptAdmin.
Notice returns the current public notice, or "".
PendingAdmin returns the nominated-but-not-yet-accepted admin, or "".
PermissionCount returns how many distinct permissions currently exist.
Permissions returns up to MaxListed permission names, comma-separated in lexicographic order.
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.
Ready reports whether init captured a deploy-time admin and constructed the book. False means the realm is inert; see the note in init.
Render serves three views, selected by path.
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.
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.
RevokeAll removes every permission addr holds and reports how many. Admin only.
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.