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.

clock.gno

2.14 Kb · 77 lines
 1package kourt
 2import (
 3	"chain/runtime"
 4	"strconv"
 5)
 6const (
 7	settleSecs    = int64(72 * 3600)
 8	deadClaimSecs = int64(12 * 7 * 86400)
 9	finalizeGraceSecs = int64(7 * 86400)
10	priorityWindowSecs = int64(24 * 3600)
11)
12func nowTime() int64 { return tcNow() }
13func deadlineTime(stamp, secs int64) int64 {
14	if stamp == 0 {
15		return 0
16	}
17	return stamp + secs
18}
19func pastDeadline(stamp, secs int64) (passed, known bool) {
20	if stamp == 0 {
21		return false, false
22	}
23	return nowTime() >= stamp+secs, true
24}
25func blocksToSecs(b int64) int64 { return b * 5 }
26func heightNow() int64 {
27	var h int64
28	if tcArmed {
29		h = tcHeightBase + tcHeightSkew
30	} else {
31		h = runtime.ChainHeight()
32		if h < tcHeightFloor {
33			h = tcHeightFloor
34		}
35	}
36	return h
37}
38func itoa(v int64) string { return strconv.FormatInt(v, 10) }
39func ClaimTimeline(courtSlug string, claimID uint64) string {
40	c := mustCourt(courtSlug)
41	cs := mustClaim(c, claimID)
42	out := "opened:" + itoa(cs.openedAtTime) + ":" + itoa(cs.openedAt)
43	if cs.answerHeight != 0 {
44		out += ";answered:" + itoa(cs.answeredAtTime) + ":" + itoa(cs.answerHeight)
45		if cs.verdictAt == 0 && !cs.closed {
46			out += ";settle:" + itoa(deadlineTime(cs.answeredAtTime, settleSecs)) +
47				":" + itoa(cs.answerHeight+settleDelay)
48		}
49	}
50	if cs.verdictAt != 0 {
51		out += ";verdict:" + itoa(cs.verdictAtTime) + ":" + itoa(cs.verdictAt)
52	}
53	if cs.escrowUntil != 0 {
54		out += ";reopen:" + itoa(cs.escrowUntilAt) + ":" + itoa(cs.escrowUntil)
55	}
56	if cs.disputeOpen && cs.proposalID != 0 {
57		opened, closes, _, _ := c.gov.Timings(cs.proposalID)
58		out += ";dispute:" + itoa(cs.disputeOpenedTime) + ":" + itoa(opened)
59		_, closesTime := c.gov.TimingsAt(cs.proposalID)
60		out += ";voteclose:" + itoa(closesTime) + ":" + itoa(closes)
61	}
62	out += ";now:" + itoa(nowTime()) + ":" + itoa(heightNow())
63	if TestClockFabricated() {
64		out += ";testclock:" + itoa(TestClockPeakSkew()) + ":" + itoa(TestHeightPeakSkew())
65	}
66	return out
67}
68type realmClock struct{}
69func (realmClock) Height() int64 { return heightNow() }
70func (realmClock) Now() int64 { return nowTime() }
71func eventHeight() string {
72	h := strconv.FormatInt(heightNow(), 10)
73	if TestClockFabricated() {
74		return h + "~test"
75	}
76	return h
77}