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

duebook_demo source realm

Package duebook\_demo is the reference consumer for the duebook scheduling primitive. It exists to make duebook's cen...

Overview

Package duebook_demo is the reference consumer for the duebook scheduling primitive. It exists to make duebook's central claim falsifiable on a live chain.

That claim is: a deferral claimed in transaction N is refused in transaction N+1, forever. A pure package cannot demonstrate this — a vm/qeval is a single ephemeral evaluation with no state that survives it. Only a realm, called twice, can show it. So this realm is not a decoration on the primitive; it is the experiment.

What it does

Anyone schedules an announcement to be published no earlier than delayBlocks from now. Once due, ANYONE may publish it — publication is deliberately permissionless, so that what protects the announcement from being published twice is duebook's exactly-once Claim and nothing else. If an access-control list were guarding Publish, the experiment would prove nothing about duebook.

The scheduler may cancel at any time before publication. Once the optional time-to-live elapses, the announcement can never be published and anyone may clear it to free a slot.

How it wires duebook correctly

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

  • the clock is runtime.ChainHeight(), never a call argument (contract 1);
  • heights are the only unit used (contract 2);
  • the *Book is an unexported package-level var and is never returned across a realm boundary (contract 3);
  • the owner is cur.Previous().Address(), never a parameter (contract 4);
  • Publish performs its effect immediately after a successful Claim, in the same transaction (contract 5).

This realm holds no coins and has no admin. Every entrypoint rejects attached coins.

Constants 1

const MinDelayBlocks, MaxDelayBlocks, MaxTTLBlocks, MaxOpen, MaxTextLen, MaxPublishedKept, MaxListed

 1const (
 2	// MinDelayBlocks is the floor on how far ahead an announcement may be
 3	// scheduled. One block is enough to prove the delay is enforced while
 4	// keeping the realm exercisable on a live chain.
 5	MinDelayBlocks = int64(1)
 6
 7	// MaxDelayBlocks caps scheduling roughly 100 days out at pearl-1's
 8	// ~3.42s blocks. It also bounds now+delay well inside int64.
 9	MaxDelayBlocks = int64(2_500_000)
10
11	// MaxTTLBlocks caps how long a due announcement stays publishable.
12	MaxTTLBlocks = int64(2_500_000)
13
14	// MaxOpen caps simultaneously scheduled announcements, bounding both
15	// storage and the cost of the Due/Expirable scans.
16	MaxOpen = 200
17
18	// MaxTextLen bounds one announcement. It is a BYTE length, not a rune
19	// count, because its job is to bound storage; a multi-byte script
20	// therefore gets fewer than 280 visible characters.
21	MaxTextLen = 280
22
23	// MaxPublishedKept is how many recent publications Render shows. The
24	// permanent record is the emitted event; this is a bounded window so
25	// realm storage cannot grow without limit.
26	MaxPublishedKept = 50
27
28	// MaxListed caps how many entries a single query returns.
29	MaxListed = 50
30)
source

Functions 12

func Cancel

crossing Action
1func Cancel(cur realm, id int64) string
source

Cancel withdraws a scheduled announcement before it is published. Only the account that scheduled it may cancel, and only while it is still open — a cancellation that arrives after publication aborts.

func DueNow

Action
1func DueNow() string
source

DueNow returns the IDs of announcements publishable at the current height, oldest first, capped at MaxListed.

func ExpirableNow

Action
1func ExpirableNow() string
source

ExpirableNow returns the IDs that Expire would accept at the current height, oldest first, capped at MaxListed.

func Expire

crossing Action
1func Expire(cur realm, id int64) string
source

Expire clears an announcement whose time-to-live has elapsed, freeing its slot against MaxOpen. It is permissionless because an expired announcement can never be published, so there is nothing left to protect and everything to gain from letting anyone tidy up.

func Height

Action
1func Height() int64
source

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

func NextID

Action
1func NextID() string
source

NextID returns the deferral ID the next Schedule will allocate. It only ever increases; that is what makes a consumed ID permanently unusable.

func OpenCount

Action
1func OpenCount() int
source

OpenCount returns how many announcements are currently scheduled.

func Publish

crossing Action
1func Publish(cur realm, id int64) string
source

Publish publishes a scheduled announcement once it is due. It is deliberately permissionless: duebook's exactly-once Claim is the only thing preventing a second publication, which is precisely what this realm exists to demonstrate.

Aborts if the announcement does not exist, is not due yet, has expired, or has already been consumed by a publication or a cancellation.

func PublishedTotal

Action
1func PublishedTotal() int64
source

PublishedTotal returns how many announcements have ever been published, including ones since evicted from the rendered window.

func Render

1func Render(path string) string
source

Render serves three views, selected by path. Anyone may Schedule, so the default view must not be something a stranger can inflate: it shows only what is publishable right now, capped at MaxListed. The full scheduled table lives behind :open and is capped too, so no view is unbounded and none of them is the landing page by default.

Example
1(empty)  summary + publishable now + recent publications
2open     every scheduled announcement, up to MaxListed rows
3about    what this realm is and why it exists

func Schedule

crossing Action
1func Schedule(cur realm, text string, delayBlocks, ttlBlocks int64) string
source

Schedule registers an announcement to be published no earlier than delayBlocks from the current height, and returns its deferral ID.

ttlBlocks is how long after the due height the announcement stays publishable; 0 means it never expires. The caller becomes the owner and is the only account that may Cancel it.

func Status

Action
1func Status(id int64) string
source

Status describes a scheduled announcement: its window, and whether it is publishable right now. Returns "unknown" when the ID was never issued or has already been consumed — duebook keeps no tombstone, so those two cases are indistinguishable by design.

Imports 7

Source Files 2