Skip to content Search Apps Documentation Source Content 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

1.62 Kb · 53 lines
 1package nightsky
 2
 3import (
 4	"gno.land/p/nt/avl/v0"
 5	"gno.land/p/nt/ownable/v0"
 6	nightsky "gno.land/p/nym-vikbez000/nightsky/v1"
 7)
 8
 9// OwnableMain holds the network admin. Ownable is safe to export as a
10// top-level object: its authority-mutating methods verify the caller against
11// the stored owner, so exporting it does not grant write access.
12var OwnableMain = ownable.NewWithAddress("g13kytw9mpyutwmyg5eq7arqxqcszfl6uq4p89zg")
13
14// RemoveTelescope allows the admin to remove a telescope from the network.
15// pkgPath is the telescope realm's package path (the registry key).
16func RemoveTelescope(cur realm, pkgPath string) {
17	assertAdmin(cur)
18
19	if _, removed := telescopes.Remove(pkgPath); !removed {
20		panic("telescope not found")
21	}
22}
23
24// ClearAllTelescopes removes all telescopes (emergency use only)
25func ClearAllTelescopes(cur realm) {
26	assertAdmin(cur)
27
28	telescopes = avl.NewTree()
29}
30
31// ClearCaptures clears the recent captures feed
32func ClearCaptures(cur realm) {
33	assertAdmin(cur)
34
35	recentCaptures = nightsky.NewCaptureFeed(maxRecentCaptures)
36}
37
38// RemoveCapture removes a single capture by its position in the newest-first
39// feed (0 = most recent), for moderating an individual entry.
40func RemoveCapture(cur realm, index int) {
41	assertAdmin(cur)
42
43	if !recentCaptures.RemoveAt(index) {
44		panic("invalid capture index")
45	}
46}
47
48// assertAdmin panics unless the calling EOA is the network admin. These are
49// crossing functions, so cur.Previous() is the statically-scoped immediate
50// caller and the AssertOwnedBy check is sound — no chain/runtime/unsafe needed.
51func assertAdmin(cur realm) {
52	OwnableMain.AssertOwnedBy(cur.Previous().Address())
53}