render.gno
2.75 Kb · 76 lines
1package lastwords
2
3import (
4 "strconv"
5 "strings"
6
7 "chain/runtime"
8
9 "gno.land/p/moul/kit/ui/v0"
10)
11
12// Render shows the slot, the clock and the money. The message is caller-typed
13// text, so it goes through ui.Inline: a stored string that renders as markdown
14// is a phishing link on a page nobody can edit, and this realm's whole product
15// is a string somebody else wrote.
16func Render(path string) string {
17 h := runtime.ChainHeight()
18 var b strings.Builder
19
20 b.WriteString("# Last Words\n\n")
21
22 if message == "" {
23 b.WriteString("_The slot is empty. Whoever writes last, writes forever._\n\n")
24 } else {
25 b.WriteString("> " + ui.Inline(message) + "\n\n")
26 b.WriteString("by " + ui.AddrOf(author.String()) + ", for " + gnot(paid) + " GNOT\n\n")
27 }
28
29 closed := clk.Expired(h)
30 b.WriteString("## The clock\n\n")
31 if closed {
32 b.WriteString("**Closed** at height " + strconv.FormatInt(clk.Deadline(), 10) + ". ")
33 if settled {
34 b.WriteString("Settled: the pot has been credited, call `Withdraw` to sweep yours.\n\n")
35 } else {
36 b.WriteString("Anyone may call `Settle` to split the pot.\n\n")
37 }
38 } else {
39 b.WriteString("Open for another **" + strconv.FormatInt(clk.Remaining(h), 10) +
40 "** blocks, until height " + strconv.FormatInt(clk.Deadline(), 10) + ".\n\n")
41 if clk.Final() {
42 b.WriteString("This is the **last stretch**: the deadline has reached the hard end at " +
43 strconv.FormatInt(clk.HardEnd(), 10) + " and no write can move it again.\n\n")
44 } else {
45 b.WriteString("Hard end at height " + strconv.FormatInt(clk.HardEnd(), 10) +
46 ". A write buys " + strconv.FormatInt(BumpPct, 10) +
47 "% of the gap to it, never less than " + strconv.FormatInt(Floor, 10) + " blocks.\n\n")
48 }
49 }
50
51 b.WriteString("## The money\n\n")
52 b.WriteString("| | |\n|---|---|\n")
53 b.WriteString("| Pot | " + gnot(pot) + " GNOT |\n")
54 b.WriteString("| Price of the next write | " + gnot(Price("")) + " GNOT, plus " +
55 strconv.FormatInt(PerByte, 10) + " ugnot per byte |\n")
56 b.WriteString("| Writes | " + strconv.FormatInt(writes, 10) + " |\n")
57 b.WriteString("| Writers | " + strconv.Itoa(len(order)) + " |\n")
58 b.WriteString("| Owed, unswept | " + gnot(ledger.TotalOwed()) + " GNOT |\n\n")
59
60 b.WriteString("The holder does **not** take the pot. It goes to everyone else who wrote, ")
61 b.WriteString("pro rata to what they paid. Half of every payment is credited to the writer ")
62 b.WriteString("it displaced, immediately.\n\n")
63
64 if !ledger.IsEmpty() {
65 b.WriteString("## Owed\n\n| address | ugnot |\n|---|---|\n")
66 shown := 0
67 ledger.Iterate(func(payee string, amount int64) bool {
68 b.WriteString("| " + ui.AddrOf(payee) + " | " + strconv.FormatInt(amount, 10) + " |\n")
69 shown++
70 return shown >= 20
71 })
72 b.WriteString("\nCall `Withdraw` to sweep yours.\n")
73 }
74
75 return b.String()
76}