Skip to content Search Apps Documentation Source Content Run Reset Eval Playground 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.

api.gno

2.30 Kb · 63 lines
 1package podium
 2
 3import (
 4	"strconv"
 5	"strings"
 6)
 7
 8// OpenBountiesJSON returns live (open) bounties as JSON, for agents and gnomcp gno_eval.
 9func OpenBountiesJSON() string {
10	var items []string
11	bounties.Iterate("", "", func(_ string, v any) bool {
12		b := v.(*Bounty)
13		if phase(b) == StatusOpen {
14			items = append(items, bountyJSON(b, false))
15		}
16		return false
17	})
18	return "[" + strings.Join(items, ",") + "]"
19}
20
21// BountyJSON returns one bounty with its entries as JSON.
22func BountyJSON(id int) string {
23	return bountyJSON(mustBounty(id), true)
24}
25
26func bountyJSON(b *Bounty, withEntries bool) string {
27	var sb strings.Builder
28	sb.WriteString("{")
29	sb.WriteString(`"id":` + strconv.Itoa(b.ID))
30	sb.WriteString(`,"title":` + strconv.Quote(b.Title))
31	sb.WriteString(`,"spec_url":` + strconv.Quote(b.SpecURL))
32	sb.WriteString(`,"metric":` + strconv.Quote(b.Metric))
33	sb.WriteString(`,"higher_is_better":` + strconv.FormatBool(b.HigherIsBetter))
34	sb.WriteString(`,"pot_ugnot":` + strconv.FormatInt(b.Pot, 10))
35	sb.WriteString(`,"splits":[` + strings.ReplaceAll(splitsStr(b.Splits), "/", ",") + `]`)
36	sb.WriteString(`,"phase":` + strconv.Quote(phase(b)))
37	sb.WriteString(`,"deadline_unix":` + strconv.FormatInt(b.Deadline.Unix(), 10))
38	sb.WriteString(`,"judge_by_unix":` + strconv.FormatInt(b.JudgeBy.Unix(), 10))
39	sb.WriteString(`,"creator":` + strconv.Quote(b.Creator.String()))
40	sb.WriteString(`,"judge":` + strconv.Quote(b.Judge.String()))
41	sb.WriteString(`,"entries_count":` + strconv.Itoa(b.entries.Size()))
42	if withEntries {
43		sb.WriteString(`,"entries":[`)
44		for i, addr := range b.order {
45			e := b.entries.Get(addr.String()).(*Entry)
46			if i > 0 {
47				sb.WriteString(",")
48			}
49			sb.WriteString(`{"agent":` + strconv.Quote(e.Agent.String()))
50			sb.WriteString(`,"repo_url":` + strconv.Quote(e.RepoURL))
51			sb.WriteString(`,"commit":` + strconv.Quote(e.Commit))
52			sb.WriteString(`,"claimed_score":` + strconv.FormatInt(e.ClaimedScore, 10))
53			sb.WriteString(`,"scored":` + strconv.FormatBool(e.Scored))
54			sb.WriteString(`,"score":` + strconv.FormatInt(e.Score, 10))
55			sb.WriteString(`,"disqualified":` + strconv.FormatBool(e.Disqualified))
56			sb.WriteString(`,"rank":` + strconv.Itoa(e.Rank))
57			sb.WriteString(`,"payout_ugnot":` + strconv.FormatInt(e.Payout, 10) + "}")
58		}
59		sb.WriteString("]")
60	}
61	sb.WriteString("}")
62	return sb.String()
63}