1package arena23import (4 "strconv"5 "time"67 "gno.land/p/nt/bptree/v0"8)910// The whole state of the realm. Everything is unexported and nothing below is11// ever returned by reference: the trees are /p/ types with mutator methods,12// so handing one out would be handing out write access to the realm.13var (14 version int64 // bumps on every admin write, see Version1516 // Arenas exist from the first paid entry until their game is over, or17 // their lobby is empty. An arena nobody paid into is never stored.18 arenas bptree.BPTree // arena id -> *arena, with its lobby and its round1920 // The last games played, for readers: their result, by arena id, and the21 // ids in the order they closed, oldest first.22 results bptree.BPTree // arena id -> encoded result, see results.gno23 closed []string2425 refundDelay int64 // seconds after a game's time limit before anyone may refund it2627 escrowed int64 // ugnot owed to players: the stakes of every lobby and running game, and their unclaimed winnings2829 // Winnings not claimed yet, see claims.gno.30 claims bptree.BPTree // player address -> encoded credits3132 // What players won, see earnings.gno.33 earnings bptree.BPTree // player address -> encoded totals, allocated on a first settled game34 winners ranking // the top players by winnings3536 webPath string // "/r/g1t2kg2vtr3fukg43eujkn6x53gfdyakhngt4sfd/gnofly/arena/v0", used to build links in Render37)3839const defaultRefundDelay = 600 // seconds4041// init runs once, when the package is added to the chain. Unlike the game42// realm this one has nothing to remember about its deployer: it has no role43// of its own.44func init(cur realm) {45 bootstrap(cur.PkgPath())46}4748// bootstrap (re)creates the initial state. The tests call it to start from a49// clean slate.50func bootstrap(pkgPath string) {51 arenas = bptree.BPTree{}52 results = bptree.BPTree{}53 closed = nil54 refundDelay = defaultRefundDelay55 escrowed = 056 claims = bptree.BPTree{}57 earnings = bptree.BPTree{}58 winners = ranking{}59 webPath = webPathOf(pkgPath)60 version = 161}6263// Version returns a counter that bumps on every admin write: the refund64// delay. Player and referee actions do not bump it.65func Version() int64 {66 return version67}6869// now returns the block time in Unix seconds.70func now() int64 {71 return time.Now().Unix()72}7374// webPathOf turns "gno.land/r/..." into "/r/...".75func webPathOf(pkgPath string) string {76 for i := 0; i < len(pkgPath); i++ {77 if pkgPath[i] == '/' {78 return pkgPath[i:]79 }80 }81 return ""82}8384func itoa(n int64) string {85 return strconv.FormatInt(n, 10)86}87ArenaJSON(id string) string
ArenasJSON() string
CancelRound(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, id string)
Claim(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}) int64
Claimable(addr string) int64
ClaimsJSON(addr string) string
EarningsJSON() string
Enter(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, spec string, ticket string) string
Escrowed() int64
ExpireLobby(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, id string)
Leave(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, id string)
PlayerJSON(addr string) string
RefundDelay() int64
RefundRound(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, id string)
Render(path string) string
ResultJSON(id string) string
ResultsJSON() string
SetRefundDelay(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, seconds int64)
SettleRound(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, id string, deaths string)
StartRound(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, id string) int64
Version() int64
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.