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.

launch.gno

4.51 Kb · 100 lines
  1package sugarproxy
  2
  3import (
  4	"chain"
  5	"strconv"
  6	"time"
  7)
  8
  9// The launch: what the first install holds, and a launcher for its first two weeks (Jae, 2026-11-01: "Yes, 14-day
 10// window"). The launcher may add and remove sites, each counting at once, so the exact addresses video sites need
 11// can be found in minutes rather than a vote each; the guardian and GovDAO can remove anything it adds; it can't
 12// touch customers, hubs, payers or releases; and its power ends LaunchDays after the first install, for good.
 13//
 14// owner, launchSeed and launcher are written by deploy/realm/prepare.py just before the realm is deployed, from the
 15// hub's real pin and payer and the first release's hashes. The realm is deployed from a hot key (Jae's Ledger can't
 16// sign a transaction carrying the whole source) under that key's namespace, so the code itself names the owner,
 17// Jae's cold key: it is the first guardian and holds the first SUGAR; the deploying key ends up holding nothing.
 18
 19const LaunchDays = 14
 20
 21var (
 22	owner      address = "g1ecsuj0q572jr0dhu29q9njtnmw03hyu7tyyvv6"
 23	launcher   address = "g1w0p203thf56zndjsqv38hn8xm4jynzr7f2nkm9"
 24	launchSeed         = []string{
 25		"customer|sugar|sugar.video fetches the videos its users paste, to caption, translate and dub them",
 26		"hub|hub.sugar.video:8443|da9c7e1b22a7fb1c9af7aed7e4268691625718260ebeb57192d671c3758a04f8",
 27		"payer|g14qh9d2y2wrzwfhzneu8d4wx0fem93yq76zjsux",
 28		"release|0.1.0|darwin-amd64|255f74db2f00164f3236d7004a9628a1c1afa97bef44ee1a56e36c209e1056a5|https://sugar.video/proxy/dl/sugar-proxy-0.1.0-darwin-amd64",
 29		"release|0.1.0|darwin-arm64|d363ec51db2e869d561715bb7f5df8c0103fa035f8fd0f05f8e712df2d955332|https://sugar.video/proxy/dl/sugar-proxy-0.1.0-darwin-arm64",
 30		"release|0.1.0|linux-amd64|0db436c9ea1557d9560dc03e565b930f5539b79409a50e9cd80af99d68e57f39|https://sugar.video/proxy/dl/sugar-proxy-0.1.0-linux-amd64",
 31		"release|0.1.0|linux-arm64|98d784373569d758b9f0eee7acd3d6463e63ede1229770cbe3f9bcba886fde28|https://sugar.video/proxy/dl/sugar-proxy-0.1.0-linux-arm64",
 32		"release|0.1.0|windows-amd64|8e57e22bbc8951b2f86990a340f03567d330b48bb6807b636f3dce26207fb117|https://sugar.video/proxy/dl/sugar-proxy-0.1.0-windows-amd64.exe",
 33		"site|youtube.com|sugar|YouTube pages of the videos sugar.video users paste",
 34		"site|www.youtube.com|sugar|YouTube pages of the videos sugar.video users paste",
 35		"site|m.youtube.com|sugar|YouTube pages of the videos sugar.video users paste",
 36		"site|youtu.be|sugar|YouTube short links sugar.video users paste",
 37		"site|*.googlevideo.com|sugar|the video files of those YouTube videos",
 38		"site|vimeo.com|sugar|Vimeo pages of the videos sugar.video users paste",
 39		"site|player.vimeo.com|sugar|Vimeo's player for those videos",
 40		"site|*.vimeocdn.com|sugar|the video files of those Vimeo videos",
 41		"site|www.reddit.com|sugar|Reddit posts with the videos sugar.video users paste",
 42		"site|v.redd.it|sugar|the video files of those Reddit posts",
 43	}
 44	launchEnd  int64
 45)
 46
 47// launch seeds the first install's items, counting at once (they are in the deployed code, which Jae signs), and
 48// starts the launcher's window. init calls it.
 49func launch() {
 50	launchEnd = time.Now().Unix() + LaunchDays*86400
 51	launching = true // the doc is written once, after the last item, not after each
 52	for _, p := range launchSeed {
 53		if _, err := add(p, "init"); err != nil {
 54			panic("launch item " + p + ": " + err.Error())
 55		}
 56	}
 57	launching = false
 58	publish()
 59}
 60
 61// Launcher is the launcher's address and when its window ends (unix seconds).
 62func Launcher() (address, int64) { return launcher, launchEnd }
 63
 64// LauncherAdd adds a site ("site|pattern|customer|purpose"), counting at once, from the launcher during its window.
 65func LauncherAdd(cur realm, payload string) int {
 66	mustLauncher(cur)
 67	kind, _, err := parse(payload)
 68	if err != nil {
 69		panic(err.Error())
 70	}
 71	if kind != KindSite {
 72		panic("the launcher adds sites only")
 73	}
 74	id, err := add(payload, "launcher")
 75	if err != nil {
 76		panic(err.Error())
 77	}
 78	return id
 79}
 80
 81// LauncherRemove removes a site, from the launcher during its window.
 82func LauncherRemove(cur realm, id int) {
 83	mustLauncher(cur)
 84	if it := find(id); it == nil || it.Kind != KindSite {
 85		panic("the launcher removes sites only")
 86	}
 87	if err := end(id, false, "launcher"); err != nil {
 88		panic(err.Error())
 89	}
 90}
 91
 92func mustLauncher(cur realm) {
 93	if launcher == "" || mustUser(cur) != launcher {
 94		panic("only the launcher may do that")
 95	}
 96	if time.Now().Unix() >= launchEnd {
 97		panic("the launch window ended at " + strconv.FormatInt(launchEnd, 10))
 98	}
 99	chain.Emit("Launcher", "by", launcher.String())
100}