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.

courtburn.gno

1.42 Kb · 50 lines
 1package kourtv3
 2import (
 3	"chain"
 4	"chain/banker"
 5	"chain/runtime/unsafe"
 6)
 7const courtCreationBurnInit = int64(0)
 8var courtCreationBurn = courtCreationBurnInit
 9func CourtCreationBurn() int64 { return courtCreationBurn }
10func SetCourtCreationBurn(cur realm, amount int64) {
11	if !cur.IsCurrent() {
12		panic(errStaleRealm)
13	}
14	d := ensureGlobalDAO()
15	if cur.Previous().Address() != d.admin {
16		panic("kourtv3: only the global DAO admin prices court creation")
17	}
18	mustSanePrice(amount)
19	courtCreationBurn = amount
20}
21func ugnotAmt(n int64) string { return ccAmt(n) }
22func mustSanePrice(amount int64) {
23	if amount < 0 {
24		panic("kourtv3: a court-creation burn cannot be negative")
25	}
26}
27func takeCourtCreationBurn(cur realm) {
28	if !cur.IsCurrent() {
29		panic(errStaleRealm)
30	}
31	price := courtCreationBurn
32	prev := cur.Previous()
33	if price <= 0 {
34		if prev.IsUserCall() && unsafe.OriginSend().AmountOf(gnotDenom) > 0 {
35			panic("kourtv3: court creation is free right now; send no GNOT")
36		}
37		return
38	}
39	if !prev.IsUserCall() {
40		panic("kourtv3: starting a court burns GNOT, so it must be a direct user call")
41	}
42	sent := unsafe.OriginSend().AmountOf(gnotDenom)
43	if sent < price {
44		panic("kourtv3: starting a court burns at least " + ugnotAmt(price) +
45			" GNOT, you sent " + ugnotAmt(sent))
46	}
47	b := banker.NewBanker(banker.BankerTypeRealmSend, cur)
48	b.SendCoins(cur.Address(), chain.PackageAddress(burnSinkPath),
49		chain.Coins{chain.NewCoin(gnotDenom, sent)})
50}