Skip to content Search Apps Documentation Source Content Run Reset Eval Playground 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.

usernames source realm

Package usernames is the toolbox tool for gno.land identities: it turns a username into an address, an address into a...

Readme View source

gno.land/r/moul/toolbox/usernames

Who holds a name, and what name an address holds. Type either one into the box.

It is the page form of

1gnokey query vm/qeval -remote https://rpc.gno.land \
2  -data 'gno.land/r/sys/users.ResolveName("akkadia")'

with the three follow-up questions already asked: whether the name you typed is the user's current name or one they renamed away from, what canonical key it collapses to, and whether a lookalike of it is already taken.

/r/moul/toolbox/usernames                 the form
/r/moul/toolbox/usernames:lookup?q=moul   the result, where the form submits
/r/moul/toolbox/usernames:moul            the same result, addressable directly
/r/moul/toolbox/usernames:g1manfred...    the same, by address

ResolveAny is the trap this tool exists not to repeat

r/sys/users.ResolveAny returns (*UserData, bool) and the bool does not mean "found". For an input that parses as an address it returns (ResolveAddress(addr), true) whatever the lookup produced, so an unregistered address comes back as (nil, true). Every caller that reads the bool and dereferences the pointer panics on the first address nobody claimed. This realm branches on the input itself and checks the pointer, and pins the upstream behaviour in a test so a later fix is visible here.

The read API

1gnokey query vm/qeval -remote https://rpc.gno.land \
2  -data 'gno.land/r/moul/toolbox/usernames.Resolve("moul")'
3gnokey query vm/qeval -remote https://rpc.gno.land \
4  -data 'gno.land/r/moul/toolbox/usernames.AddressOf("moul")'

AddressOf is the call another realm would want and the one it cannot have: this realm is private = true, so nothing can import it. Over vm/qeval it is the whole point.

Three behaviours worth knowing:

  • Not found means three different things, and the page says which: a valid address with no username, a name nobody ever held, and a name that is taken by an account that was deleted or renamed away. The last one still refuses a registration, which is why it is not folded into the second.
  • An address is only ever looked up as an address. A bech32 address is not a legal username, so trying both would only widen what a typo can hit.
  • The terminal hint disappears for input it cannot quote. Nothing escapes inside a fenced code block, so an input carrying a backtick gets no command block rather than a broken page. Everything else the page reflects is escaped first.

Part of r/moul/toolbox.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

On mainnet: deployment status transactions unique callers deployed revision

Dependency graph:

gno.land/r/moul/toolbox/usernames dependency graph

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.

Overview

Package usernames is the toolbox tool for gno.land identities: it turns a username into an address, an address into a username, and tells you which of the two you are actually holding.

It is the page form of

Example
1gnokey query vm/qeval --data 'gno.land/r/sys/users.ResolveName("akkadia")' -remote https://rpc.gno.land

with the three things that query does not tell you: whether the name you asked about is the user's CURRENT name or an alias they renamed away from, what canonical key it collapses to, and whether a lookalike of it is already taken.

Why not r/sys/users.ResolveAny

`ResolveAny` returns `(*UserData, bool)` and the bool does not mean "found". For an input that parses as an address it returns `(ResolveAddress(addr), true)` whatever the lookup produced, so an unregistered address comes back as `(nil, true)`. Every caller that reads the bool and dereferences the pointer panics on the first address nobody claimed. [lookup] branches on the input itself and checks the pointer instead.

Part of r/moul/toolbox(/r/moul/toolbox).

Functions 9

func AddressOf

Action
1func AddressOf(input string) string
source

AddressOf returns the address behind a username or an address, or "" when nobody holds it.

It is the call another realm would want, and the one it cannot have: this realm is `private = true`, so nothing can import it. Over `vm/qeval` it is the whole point.

Example
1gnokey query vm/qeval -data 'gno.land/r/moul/toolbox/usernames.AddressOf("moul")'

func Canonical

Action
1func Canonical(name string) string
source

Canonical returns the canonical key a name collapses to. Two names with the same canonical form cannot both be registered, which is how `r/sys/users` refuses a lookalike of an existing account.

Example
1gnokey query vm/qeval -data 'gno.land/r/moul/toolbox/usernames.Canonical("M0ul")'

func CanonicalOwner

Action
1func CanonicalOwner(name string) string
source

CanonicalOwner returns the name that already holds this name's canonical key, or "" when the key is free. A non-empty answer that is not the name itself is a lookalike collision.

func CurrentName

Action
1func CurrentName(input string) string
source

CurrentName reports the user's current name when input is an alias they renamed away from, and "" otherwise.

`r/sys/users` keeps old names resolving on purpose, so an address looked up by a name that is no longer current is not an error and nothing in the resolve result says so. This is the one call that does.

func Display

Action
1func Display(input string) string
source

Display returns what a page should print for an input: "@name" when there is a username, and the input unchanged when there is not.

So it is total over every input a page actually has, and a caller never has to branch on "not found" the way NameOf makes it. The one input it has nothing to say about is "", which it returns unchanged: an empty answer to an empty question, rather than a placeholder a page would then have to special case anyway.

func NameOf

Action
1func NameOf(input string) string
source

NameOf returns the current username behind a username or an address, or "" when nobody holds it.

func Render

1func Render(path string) string
source

Render routes gnoweb paths:

Example
1/                the form, and what the tool answers
2/lookup?q=moul   the result, which is where the form submits
3/moul            the same result, addressable directly
4/g1manfred...    the same, by address

func Resolve

Action
1func Resolve(input string) (name string, addr string, found bool)
source

Resolve returns the current username and the address behind any input, a username or a `g1` address.

found is false when nobody holds it, which is also the answer for a deleted user: `r/sys/users` keeps the tombstone and resolves it to nothing.

Example
1gnokey query vm/qeval -data 'gno.land/r/moul/toolbox/usernames.Resolve("moul")'

func Taken

Action
1func Taken(name string) bool
source

Taken reports whether the exact name is registered, including names that were deleted or renamed away from: it answers "would registering this fail", not "is somebody using this".

Dependencies

Source Files 7