diff --git a/examples/gno.land/r/system/names/names.gno b/examples/gno.land/r/system/names/names.gno index e63b559ae14..2bf2c639446 100644 --- a/examples/gno.land/r/system/names/names.gno +++ b/examples/gno.land/r/system/names/names.gno @@ -24,6 +24,13 @@ type Space struct { InPause bool } +func (s *Space) isAdmin(addr std.Address) bool { + if containsAddress(s.Admins, addr) { + return true + } + return false +} + func (s *Space) addAdmin(newAdmin std.Address) { if !containsAddress(s.Admins, newAdmin) { s.Admins = append(s.Admins, newAdmin) @@ -87,34 +94,34 @@ func Register(namespace string) { } func AddAdmin(namespace string, newAdmin std.Address) { - assertIsAdmin(namespace) space := getSpace(namespace) + assertIsAdmin(space) space.addAdmin(newAdmin) } func RemoveAdmin(namespace string, admin std.Address) { - assertIsAdmin(namespace) space := getSpace(namespace) + assertIsAdmin(space) err := space.removeAdmin(admin) checkErr(err) } func AddEditor(namespace string, newEditor std.Address) { - assertIsAdmin(namespace) space := getSpace(namespace) + assertIsAdmin(space) space.addEditor(newEditor) } func RemoveEditor(namespace string, editor std.Address) { - assertIsAdmin(namespace) space := getSpace(namespace) + assertIsAdmin(space) err := space.removeEditor(editor) checkErr(err) } func SetInPause(namespace string, state bool) { - assertIsAdmin(namespace) space := getSpace(namespace) + assertIsAdmin(space) space.InPause = state } diff --git a/examples/gno.land/r/system/names/utils.gno b/examples/gno.land/r/system/names/utils.gno index b44341fe33f..8215ddc5b5a 100644 --- a/examples/gno.land/r/system/names/utils.gno +++ b/examples/gno.land/r/system/names/utils.gno @@ -17,11 +17,9 @@ func existsNamespace(name string) bool { return ok } -func assertIsAdmin(namespace string) { +func assertIsAdmin(space *Space) { caller := std.GetOrigCaller() - space := getSpace(namespace) - - if !containsAddress(space.Admins, caller) { + if !space.isAdmin(caller) { panic("Only admins can call this function") } }