package nsdata import ( "strings" "time" "gno.land/r/nym-mnsrehearsal001/nsnft/v2" ) // Plain reads — no `cur realm` parameter, no authentication, since there // is no caller identity to check on a read. Everything here returns raw // stored values; formatting them for display is the view realm's job, // not the vault's. (Status strings like "VALID (363 days left)" used to // live here. They were display logic in a realm that can never be // redeployed, so they moved to nsview.) func ListDomains() string { var b strings.Builder first := true domains.Iterate("", "", func(key string, v any) bool { if !first { b.WriteString(",") } b.WriteString(key) first = false return false }) return b.String() } // ListNames and CountNames scan only the key span belonging to // `domainLabel` (see domainRange in auth.gno), costing O(names in that // domain) rather than O(every name in the registry). func ListNames(domainLabel string) string { var b strings.Builder first := true start, end := domainRange(domainLabel) // The label is the part of the key after "domain*". Records no // longer carry their own label — the key already held it, and // storing it twice cost storage forever to say the same thing. cut := len(domainLabel) + 1 names.Iterate(start, end, func(key string, v any) bool { if !first { b.WriteString(",") } b.WriteString(key[cut:]) first = false return false }) return b.String() } func CountNames(domainLabel string) int64 { var count int64 start, end := domainRange(domainLabel) names.Iterate(start, end, func(key string, v any) bool { count++ return false }) return count } func CountDomains() int64 { return int64(domains.Size()) } func DomainExists(label string) bool { _, ok := getDomain(label); return ok } func NameExists(label, domainLabel string) bool { _, ok := getName(label, domainLabel); return ok } func GetDomainOwner(label string) address { return mustGetDomain(label).owner } // GetNameOwner asks the ledger. It still panics for an unknown NAME, as it // always did, so callers that relied on that are unchanged. func GetNameOwner(label, domainLabel string) address { mustGetName(label, domainLabel) return nsnft.OwnerOf(nameTokenID(label, domainLabel)) } // GetDomainInfo / GetNameInfo return a whole record in one call, so a // view realm can render a page without six round trips. // Timestamps come back as unix SECONDS. They used to be time.Time, // which vm/qeval rendered using gno's internal epoch, so every consumer // had to know to subtract 62135596800 — our own frontend did exactly // that. Returning unix seconds stops leaking that offset into every // integration, and it is what the records now hold anyway. // // `streak` is computed from the registration date rather than read from // a stored field. See streakOf. func GetDomainInfo(label string) (owner address, registered, expires, streak int64, frozen bool) { d := mustGetDomain(label) return d.owner, d.registered, d.expires, streakOf(d.registered, time.Now().Unix()), d.frozen } /* GetNameInfo keeps its six-value shape so every existing reader — nslogic, nsview, nsskin, nsvote, the site, both snapshot tools — goes on parsing it unchanged. Two of the six are now answered differently: owner is read from nsnft, never stored here. The snapshot tools record whatever this returns, so they now record the real owner — the restore-hands-sold-names-back bug the first attempt had cannot happen, because there is no stale copy for them to read. paid replaces isNFT and means exactly one thing: the name is NOT held as an un-upgraded free-tier record. It is deliberately not "transferable" — a frozen paid name is locked too, and reading the lock would have made a frozen paid name look free, which is precisely the proxy bug that let free renewals renew paid names. */ func GetNameInfo(label, domainLabel string) (owner address, registered, expires, streak int64, frozen, paid bool) { n := mustGetName(label, domainLabel) tid := nameTokenID(label, domainLabel) return nsnft.OwnerOf(tid), n.registered, n.expires, streakOf(n.registered, time.Now().Unix()), n.frozen, nsnft.LockBits(tid)&(1<