← Back to Realms

Realm

Gno.land Mainnet

gno.land/r/gnoswap/order/keeper

Overview

Network
gnoland-1
Realm Path
gno.land/r/gnoswap/order/keeper
Exported Functions
18
State Entries
25
Source Files
9
Total Package Entries
62

Exported Functions

18 exported functions

State

25 state entries

Source Code

FILES
assert.gno
go
1package keeper
2
3import (
4	"gno.land/p/gnoswap/order/access/manager/v1"
5	ufmt "gno.land/p/nt/ufmt/v0"
6
7	"gno.land/r/gnoswap/access/v1"
8)
9
10// AssertIsAuthorizedCaller panics unless the caller of rlm may call selector
11// on the realm of rlm. Order realms call it with their own realm value,
12// so a realm can only assert for itself.
13func AssertIsAuthorizedCaller(_ int, rlm realm, selector manager.Selector) {
14	if !rlm.IsCurrent() {
15		panic(errSpoofedRealm)
16	}
17
18	caller := rlm.Previous().Address()
19
20	target := rlm.PkgPath()
21	if !accessState.IsAuthorized(caller, target, selector) {
22		panic(makeErrorWithDetails(
23			errUnauthorizedCall,
24			ufmt.Sprintf("%s cannot call %s on %s", caller.String(), string(selector), target),
25		).Error())
26	}
27}
28
29// assertIsAdminOrGovernance checks that the caller of cur is the GnoSwap
30// admin or governance.
31func assertIsAdminOrGovernance(cur realm) {
32	access.AssertIsAdminOrGovernance(cur.Previous().Address())
33}
34
35// assertIsRegisteredRole rejects roles that were never registered.
36// manager.AdminRole is never registered here.
37func assertIsRegisteredRole(role manager.RoleId) {
38	if !isRegisteredRole(role) {
39		panic(makeErrorWithDetails(errInvalidRole, ufmt.Sprintf("role(%s) is not registered", role.String())).Error())
40	}
41}
42
43// assertIsAssignableRole accepts a registered role or PublicRole.
44func assertIsAssignableRole(role manager.RoleId) {
45	if role != manager.PublicRole {
46		assertIsRegisteredRole(role)
47	}
48}
49
50func assertIsAvailableLabel(label string) {
51	if label == "" || len(label) > maxLabelLength {
52		panic(makeErrorWithDetails(errInvalidLabel, ufmt.Sprintf("label(%s) must be 1 to %d bytes", label, maxLabelLength)).Error())
53	}
54
55	if isLabelTaken(label) {
56		panic(makeErrorWithDetails(errInvalidLabel, ufmt.Sprintf("label(%s) already exists", label)).Error())
57	}
58}
59
60func assertIsValidAddress(account address) {
61	if !account.IsValid() {
62		panic(makeErrorWithDetails(errInvalidAddress, ufmt.Sprintf("account(%s)", account.String())).Error())
63	}
64}
65
66func assertIsValidTarget(target string) {
67	if target == "" {
68		panic(makeErrorWithDetails(errInvalidTarget, "empty target").Error())
69	}
70}
71

Raw Package Data

Raw JSON data