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.

guards.gno

1.31 Kb · 44 lines
 1package bolo
 2
 3import (
 4	"chain"
 5	"chain/runtime"
 6)
 7
 8// assertCurrent is the first statement of every crossing function (API C2).
 9func assertCurrent(cur realm) {
10	if !cur.IsCurrent() {
11		panic("bolo registry: not the current realm")
12	}
13}
14
15// assertCodeCaller refuses any caller but a deployed realm (API C11). A maketx run
16// script is ephemeral and code at once: it is refused here, as is a user.
17func assertCodeCaller(cur realm) {
18	if p := cur.Previous(); !p.IsCode() || p.IsEphemeral() {
19		panic(ErrNotUserCall)
20	}
21}
22
23// assertSigner runs right after C11's branch in every write: no session key, in
24// either branch (C11), then the caller must be who (API §3.7).
25func assertSigner(cur realm, who address) {
26	if _, _, _, isSession := runtime.GetSessionInfo(); isSession {
27		panic(ErrSessionKey)
28	}
29	if cur.Previous().Address() != who {
30		panic(ErrNotAdmin)
31	}
32}
33
34// checkCandidate refuses, with ErrSetting, a malformed address (C12: exactly 40
35// characters, a lowercase "g" first, then IsValid) and the registry's own address
36// and storage-deposit address, which can never accept the admin role (API §3.7).
37func checkCandidate(a address) {
38	if len(a) != 40 || a[0] != 'g' || !a.IsValid() {
39		panic(ErrSetting)
40	}
41	if a == chain.PackageAddress(registryPath) || a == chain.DeriveStorageDepositAddr(registryPath) {
42		panic(ErrSetting)
43	}
44}