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.

deadline.gno

1.20 Kb · 34 lines
 1package bolo
 2
 3import "chain"
 4
 5// recordDeadline records a passed deadline (API §3.1): an open campaign whose
 6// deadline has passed becomes closed, at its deadline, for reason deadline, and
 7// leaves the active indexes; Closed is emitted, naming the caller there and only
 8// there. Every crossing function that takes a campaign ID calls it before any other
 9// precondition; queries and Render compute the same with effective, writing nothing.
10func recordDeadline(cur realm, c *campaign) {
11	s := c.state
12	if s.status != statusOpen || c.deadline == 0 || now() < c.deadline {
13		return
14	}
15	s.status, s.closedAt, s.closeReason = statusClosed, c.deadline, reasonDeadline
16	stats.open--
17	dropActive(c)
18	chain.Emit(evClosed, "id", idString(c.id), "reason", reasonDeadline, "by", cur.Previous().Address().String())
19}
20
21// addActive puts c in the two active indexes, which list the open, listed campaigns
22// (API §2.5).
23func addActive(c *campaign) {
24	key := c.id.Binary()
25	active.Set(key, true)
26	activeByCategory.Set(c.category+"/"+key, true)
27}
28
29// dropActive takes c out of the two active indexes (API §2.5).
30func dropActive(c *campaign) {
31	key := c.id.Binary()
32	active.Remove(key)
33	activeByCategory.Remove(c.category + "/" + key)
34}