session.gno
2.39 Kb · 86 lines
1package kourt
2func SettleUndisputed(cur realm, courtSlug string, claimID uint64) {
3 if !cur.IsCurrent() {
4 panic(errStaleRealm)
5 }
6 c := mustCourt(courtSlug)
7 cs := mustClaim(c, claimID)
8 if cs.frozenAt == 0 {
9 panic("kourtv2: there is no answer to settle")
10 }
11 if cs.disputeOpen || cs.round > 0 {
12 panic("kourtv2: this claim was disputed; it settles by vote")
13 }
14 if cs.verdictAt != 0 {
15 panic("kourtv2: already settled")
16 }
17 if passed, known := pastDeadline(cs.answeredAtTime, settleSecs); (known && !passed) ||
18 (!known && heightNow() < cs.answerHeight+settleDelay) {
19 panic("kourtv2: the answer has not aged the 72h settlement minimum")
20 }
21 touch(c)
22 cs.verdictAt = heightNow()
23 cs.verdictAtTime = nowTime()
24 cs.route = "undisputed"
25 trimClaimHistory(c, cs, uint32(cs.frozenAt/epochBlocks)+1)
26 cs.provisional = cs.answer
27 if cs.answerBond > 0 {
28 settleAnswerBond(c, cs)
29 }
30 releasePriority(c, cs.answerer, claimID)
31}
32func WithdrawStake(cur realm, courtSlug string, claimID uint64, side int) int64 {
33 if !cur.IsCurrent() {
34 panic(errStaleRealm)
35 }
36 who := cur.Previous().Address()
37 c := mustCourt(courtSlug)
38 cs := mustClaim(c, claimID)
39 mustSide(side)
40 if cs.verdictAt == 0 && !(cs.provisional >= 0 && side != int(cs.provisional)) {
41 panic("kourtv2: no verdict yet — unstake freely before an answer, withdraw after the verdict")
42 }
43 touch(c)
44 advancePools(c, cs)
45 p := getPos(c, cs, who, side)
46 if p.stake <= 0 {
47 panic("kourtv2: nothing staked on that side")
48 }
49 accrue(c, cs, p, side)
50 amount := p.stake
51 p.stake = 0
52 if side == sideYES {
53 cs.yesStake -= amount
54 } else {
55 cs.noStake -= amount
56 }
57 releaseStake(c, who, amount)
58 return amount
59}
60func Settled(courtSlug string, claimID uint64) bool {
61 return mustClaim(mustCourt(courtSlug), claimID).verdictAt != 0
62}
63func Verdict(courtSlug string, claimID uint64) int {
64 cs := mustClaim(mustCourt(courtSlug), claimID)
65 if cs.verdictAt == 0 {
66 panic("kourtv2: no verdict yet")
67 }
68 if cs.provClose {
69 panic("kourtv2: closed without a decision (three failed dispute rounds)")
70 }
71 return int(cs.provisional)
72}
73func VerdictRoute(courtSlug string, claimID uint64) string {
74 cs := mustClaim(mustCourt(courtSlug), claimID)
75 if cs.verdictAt == 0 {
76 panic("kourtv2: no verdict yet")
77 }
78 return cs.route
79}
80func SettleDeadline(courtSlug string, claimID uint64) int64 {
81 cs := mustClaim(mustCourt(courtSlug), claimID)
82 if cs.frozenAt == 0 {
83 return 0
84 }
85 return cs.answerHeight + settleDelay
86}