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.

admin.gno

3.01 Kb · 94 lines
 1package gnodice
 2
 3import (
 4	"chain"
 5	"strconv"
 6)
 7
 8// Administration : réservée au propriétaire (sauf AcceptOwnership).
 9// Chaque action émet un événement on-chain, pour garder une trace publique.
10
11// SetPaused met le jeu en pause (true) ou le relance (false). En pause, les
12// nouvelles mises sont refusées mais les parties en cours peuvent se terminer.
13func SetPaused(cur realm, value bool) {
14	assertOwner(cur)
15	paused = value
16	chain.Emit("PauseChanged", "paused", strconv.FormatBool(value), "by", "owner")
17}
18
19// SetCroupier désigne l'adresse du service qui tire les dés.
20func SetCroupier(cur realm, addr address) {
21	assertOwner(cur)
22	if !addr.IsValid() {
23		panic("gnodice: adresse invalide")
24	}
25	previous := croupier
26	croupier = addr
27	chain.Emit("CroupierChanged", "from", previous.String(), "to", addr.String())
28}
29
30// SetBlocked interdit (true) ou autorise de nouveau (false) une adresse à jouer.
31// Les parties déjà en cours de cette adresse se terminent normalement.
32func SetBlocked(cur realm, addr address, value bool) {
33	assertOwner(cur)
34	if !addr.IsValid() {
35		panic("gnodice: adresse invalide")
36	}
37	if value {
38		blocked.Set(addr.String(), true)
39	} else {
40		blocked.Remove(addr.String())
41	}
42	chain.Emit("PlayerBlocked", "player", addr.String(), "blocked", strconv.FormatBool(value))
43}
44
45// SetLimits règle le coupe-circuit (gains maximum par jour) et le seuil
46// d'alerte de la banque, en ugnot.
47func SetLimits(cur realm, dailyLimit, lowBankrollThreshold int64) {
48	assertOwner(cur)
49	if dailyLimit < MaxBet*PayoutMultiplier {
50		panic("gnodice: la limite du jour doit couvrir au moins un gain maximal (50 GNOT)")
51	}
52	if lowBankrollThreshold < 0 {
53		panic("gnodice: seuil invalide")
54	}
55	dailyPayoutLimit = dailyLimit
56	lowBankroll = lowBankrollThreshold
57	chain.Emit("LimitsChanged", "dailyPayoutLimit", itoa64(dailyLimit), "lowBankroll", itoa64(lowBankrollThreshold))
58}
59
60// TransferOwnership PROPOSE un nouveau propriétaire. Il ne devient
61// propriétaire qu'en appelant AcceptOwnership : une faute de frappe dans
62// l'adresse ne fait donc jamais perdre le contrôle du contrat.
63func TransferOwnership(cur realm, newOwner address) {
64	assertOwner(cur)
65	if !newOwner.IsValid() {
66		panic("gnodice: adresse invalide")
67	}
68	pendingOwner = newOwner
69	chain.Emit("OwnershipProposed", "from", owner.String(), "to", newOwner.String())
70}
71
72// AcceptOwnership : le propriétaire proposé accepte le contrôle du contrat.
73func AcceptOwnership(cur realm) {
74	caller := cur.Previous().Address()
75	if pendingOwner == "" || caller != pendingOwner {
76		panic("gnodice: aucune proposition de transfert pour cette adresse")
77	}
78	previous := owner
79	owner = pendingOwner
80	pendingOwner = ""
81	chain.Emit("OwnershipTransferred", "from", previous.String(), "to", owner.String())
82}
83
84// Owner renvoie l'adresse du propriétaire.
85func Owner() address { return owner }
86
87// Croupier renvoie l'adresse du croupier.
88func Croupier() address { return croupier }
89
90func assertOwner(cur realm) {
91	if cur.Previous().Address() != owner {
92		panic("gnodice: action réservée au propriétaire du contrat")
93	}
94}