Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

assert.gno

1.00 Kb · 35 lines
 1package referral
 2
 3import (
 4	prabc "gno.land/p/gnoswap/rbac"
 5
 6	"gno.land/r/gnoswap/access"
 7	_ "gno.land/r/gnoswap/rbac"
 8)
 9
10// MUST BE IMMUTABLE, DO NOT MODIFY.
11// validCallerRoles is a list of roles that are authorized to modify referral data.
12// This includes governance contracts, router, position manager, and staker contracts.
13var validCallerRoles = []string{
14	prabc.ROLE_GOVERNANCE.String(),
15	prabc.ROLE_GOV_STAKER.String(),
16	prabc.ROLE_ROUTER.String(),
17	prabc.ROLE_POSITION.String(),
18	prabc.ROLE_STAKER.String(),
19	prabc.ROLE_LAUNCHPAD.String(),
20}
21
22// assertValidCaller checks if the caller address has permission to modify referral data.
23// Only addresses with specific roles defined in validCallerRoles are authorized.
24//
25// Errors:
26//   - ErrUnauthorized: the caller is not authorized to modify referral data
27func assertValidCaller(caller address) {
28	for _, role := range validCallerRoles {
29		if access.IsAuthorized(role, caller) {
30			return
31		}
32	}
33
34	panic(makeErrorWithDetails(ErrUnauthorized, caller.String()))
35}