api.gno
1.56 Kb · 37 lines
1package users
2
3// IsNameTaken reports whether the exact-string name exists in nameStore.
4// Returns true for any name ever registered, including:
5//
6// - active registrations
7// - tombstoned (deleted) users' names — Delete() sets `deleted=true`
8// but does not remove the nameStore entry (anti-revival policy)
9// - old aliases from renames — UpdateName inserts the new name
10// alongside the old; the old key stays (anti-rename-squat policy)
11//
12// In short: IsNameTaken(name) answers "would RegisterUser(name, _)
13// fail with ErrNameTaken?" — same answer for active, deleted, or
14// aliased-away names. Pairs with IsCanonicalTaken (canonical-match)
15// and ResolveName (active-current-user lookup with full UserData).
16//
17// No canonicalization is applied. For controllers that want exact-
18// match uniqueness without pulling in canonical-collision logic.
19func IsNameTaken(name string) bool {
20 return nameStore.Has(name)
21}
22
23// IsCanonicalTaken reports whether the given name's canonical form is
24// already registered. Pass the raw name; canonicalization is applied
25// internally. The first return is the original (non-canonical) name
26// that owns the canonical key, for UX in collision messages.
27//
28// When a bypass write (RegisterUserIgnoreCanonical or the bypass path
29// through ProposeRegisterUser/ProposeUpdateName) overwrites a prior
30// canonical entry, this returns the most-recently-written original.
31func IsCanonicalTaken(name string) (existing string, taken bool) {
32 v, ok := canonicalStore.Get(Canonicalize(name))
33 if !ok {
34 return "", false
35 }
36 return v.(string), true
37}