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.

owner.gno

1.51 Kb · 63 lines
 1package arena
 2
 3import (
 4	"chain/runtime"
 5
 6	"gno.land/p/nt/ownable/v0"
 7	"gno.land/r/nym-gfanton001/gnomepit/standings/v0"
 8)
 9
10var (
11	owner   *ownable.Ownable
12	retired bool
13)
14
15func init(cur realm) {
16	owner = ownable.NewWithAddress(cur.Previous().Address())
17}
18
19// Retire closes the arena to new challenges and acceptances, for good. Matches already
20// running play out and are rated, and an open challenge can still be withdrawn. Owner
21// only.
22func Retire(cur realm) {
23	refuseSession()
24	owner.AssertOwnedBy(cur.Previous().Address())
25	retired = true
26}
27
28// TransferOwnership makes newOwner the owner. Owner only.
29func TransferOwnership(cur realm, newOwner address) {
30	refuseSession()
31	if err := owner.TransferOwnership(0, cur, newOwner); err != nil {
32		panic(err.Error())
33	}
34}
35
36// Retired reports whether the owner has retired the arena.
37func Retired() bool {
38	return retired
39}
40
41// Owner is the address that may retire the arena.
42func Owner() address {
43	return owner.Owner()
44}
45
46// refuseSession refuses a call signed with a session key: the page signs a match's moves
47// with one, so an owner who plays from the owner's wallet must not hand it the owner's calls.
48func refuseSession() {
49	if _, _, _, isSession := runtime.GetSessionInfo(); isSession {
50		panic("sign with the owner's own key, not a session key")
51	}
52}
53
54// mustBeOpen refuses a new match on a retired arena, or on one the standings realm takes no
55// results from.
56func mustBeOpen() {
57	if retired {
58		panic("arena retired")
59	}
60	if !standings.IsWriter(self) {
61		panic("arena not open")
62	}
63}