Skip to content

Commit

Permalink
Merge pull request #34 from jefft0/chore/add-GetJsonUserByAddress
Browse files Browse the repository at this point in the history
chore: Add GetJsonUserByAddress
  • Loading branch information
jefft0 authored Mar 5, 2024
2 parents 13e020e + 5790c7f commit f1b457b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions realm/public.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package social

import (
"std"
"strconv"
"time"

"gno.land/p/demo/avl"
Expand Down Expand Up @@ -251,3 +252,16 @@ func Unfollow(followedAddr std.Address) {

userPosts.Unfollow(followedAddr)
}

// Call users.GetUserByAddress and return the result as JSON, or "" if not found.
// (This is a temporary utility until gno.land supports returning structured data directly.)
func GetJsonUserByAddress(addr std.Address) string {
user := users.GetUserByAddress(addr)
if user == nil {
return ""
}

return ufmt.Sprintf(
"{\"address\": \"%s\", \"name\": \"%s\", \"profile\": %s, \"number\": %d, \"invites\": %d, \"inviter\": \"%s\"}",
user.Address.String(), user.Name, strconv.Quote(user.Profile), user.Number, user.Invites, user.Inviter.String())
}

0 comments on commit f1b457b

Please sign in to comment.