render.gno
2.99 Kb · 59 lines
1package bubble
2
3import (
4 "strconv"
5 "strings"
6)
7
8// Render: "" the front page (the token's figures, then the governor's page); "gov/…" the governor's pages alone;
9// "json" the figures for the box; "me/<addr>" one holder's balance and votes.
10func Render(path string) string {
11 path = strings.Trim(path, "/")
12 switch {
13 case path == "json":
14 return jsonAll()
15 case strings.HasPrefix(path, "me/"):
16 a := address(path[3:])
17 return "{\"addr\":\"" + a.String() + "\",\"balance\":" + itoa(ledger.BalanceOf(a)) + ",\"votes\":" + itoa(ledger.VotesOf(a)) +
18 ",\"delegate\":\"" + ledger.DelegateOf(a).String() + "\"}"
19 case strings.HasPrefix(path, "gov"):
20 return engine.Render(strings.TrimPrefix(strings.TrimPrefix(path, "gov"), "/"), notes())
21 default:
22 return engine.Render(path, notes())
23 }
24}
25
26// notes are this realm's lines on the governor's front page: the figures the engine cannot know.
27func notes() string {
28 var b strings.Builder
29 b.WriteString("- supply: " + whole(ledger.TotalSupply()) + " of " + whole(MaxSupply) + " BUBBLE (premine " + whole(premined) +
30 ", referrals " + whole(referralMinted) + " of " + whole(ReferralPool) + ", reserve " + whole(reserveMinted) + " of " + whole(Reserve) + ")\n")
31 minted, ceiling := MintedToday()
32 b.WriteString("- today: " + whole(minted) + " of " + whole(ceiling) + " BUBBLE minted; batches " + itoa(batches) + "\n")
33 if admin == "" {
34 b.WriteString("- **the admin is gone** — every setting moves by vote\n")
35 } else {
36 b.WriteString("- admin: " + admin.String() + "\n")
37 }
38 if minter == "" {
39 b.WriteString("- **nobody mints** — the holders can name a minter\n")
40 } else {
41 b.WriteString("- minter: " + minter.String() + (map[bool]string{true: " (paused)", false: ""})[paused] + "\n")
42 }
43 b.WriteString("- a money vote's turnout bar follows the holders: a fifth of the supply, or the mean turnout of the last money votes when that is higher (mean now " + whole(meanTurnout()) + "), never above a third; the reserve moves at most " + whole(ReserveMaxPer) + " a proposal, ninety days apart\n")
44 return b.String()
45}
46
47func jsonAll() string {
48 minted, ceiling := MintedToday()
49 return "{\"name\":\"" + tokenName + "\",\"symbol\":\"" + tokenSymbol + "\",\"decimals\":" + strconv.Itoa(tokenDecimals) +
50 ",\"supply\":" + itoa(ledger.TotalSupply()) + ",\"max\":" + itoa(MaxSupply) + ",\"premine\":" + itoa(premined) +
51 ",\"referralMinted\":" + itoa(referralMinted) + ",\"referralPool\":" + itoa(ReferralPool) +
52 ",\"reserveMinted\":" + itoa(reserveMinted) + ",\"reserve\":" + itoa(Reserve) +
53 ",\"dayCap\":" + itoa(ceiling) + ",\"mintedToday\":" + itoa(minted) + ",\"day\":" + itoa(dayOf()) +
54 ",\"paused\":" + strconv.FormatBool(paused) + ",\"admin\":\"" + admin.String() + "\",\"minter\":\"" + minter.String() +
55 "\",\"lastBatch\":\"" + lastBatch + "\",\"batches\":" + itoa(batches) + ",\"epoch\":" + strconv.FormatUint(uint64(ledger.Epoch()), 10) +
56 ",\"height\":" + itoa(ledger.Height()) + ",\"now\":" + itoa(ledger.Now()) + "}"
57}
58
59func itoa(n int64) string { return strconv.FormatInt(n, 10) }