diff --git a/examples/gno.land/r/profile/integration0_test.gno b/examples/gno.land/r/profile/integration0_filetest.gno similarity index 69% rename from examples/gno.land/r/profile/integration0_test.gno rename to examples/gno.land/r/profile/integration0_filetest.gno index a1af5c47292..0129fb1a7c5 100644 --- a/examples/gno.land/r/profile/integration0_test.gno +++ b/examples/gno.land/r/profile/integration0_filetest.gno @@ -1,16 +1,16 @@ package main import ( - "fmt" - "gno.land/r/profile" ) func main() { - fmt.Println("test") + println(profile.Render("")) + //_ = profile.Render // various data types // avatar // ip address } // Output: +// a diff --git a/examples/gno.land/r/profile/profile.gno b/examples/gno.land/r/profile/profile.gno index fc2374fc847..5080cd72964 100644 --- a/examples/gno.land/r/profile/profile.gno +++ b/examples/gno.land/r/profile/profile.gno @@ -3,13 +3,14 @@ package profile import ( "std" - "gno.land/r/users" + "gno.land/p/ufmt" + // "gno.land/r/users" ) // FIXME: manage privacy? func newProfile(addr std.Address) *Profile { - now := std.GetTime() + now := std.GetTimestamp() return &Profile{ address: addr, created: now, @@ -19,12 +20,12 @@ func newProfile(addr std.Address) *Profile { type Profile struct { dict map[string]interface{} address std.Address - created uint64 - updated uint64 + created std.Time + updated std.Time } func (p *Profile) save() { - now := std.GetTime() + now := std.GetTimestamp() if p.created == 0 { p.created = now } diff --git a/examples/gno.land/r/profile/profiles.gno b/examples/gno.land/r/profile/profiles.gno index d0a218607c2..e1b2a1877a1 100644 --- a/examples/gno.land/r/profile/profiles.gno +++ b/examples/gno.land/r/profile/profiles.gno @@ -2,7 +2,10 @@ package profile import ( "std" + "strings" + "gno.land/p/avl" + "gno.land/p/ufmt" "gno.land/r/users" ) @@ -10,6 +13,10 @@ import ( var profiles *avl.MutTree // std.Address.String() -> *Profile +func init() { + // profiles = avl.NewMutTree() +} + func Update(dict map[string]interface{}) { // FIXME: ask a price per stored data length? currentUser := std.GetOrigCaller() @@ -18,20 +25,24 @@ func Update(dict map[string]interface{}) { } func GetByAddressOrName(aon users.AddressOrName) *Profile { - return profiles.Get(aon) + addr := aon.Resolve() + profile, found := profiles.Get(addr.String()) + if !found { + return nil + } + return profile.(*Profile) } -func getOrCreateProfileByAddress(aon users.AddressOrName) *Profile { +func getOrCreateProfileByAddress(addr std.Address) *Profile { // lookup existing profile - profile := profiles.Get(aon) - if profile != nil { - return profile + profile, found := profiles.Get(addr.String()) + if found { + return profile.(*Profile) } // create - addr := aon.Resolve() newProfile := &Profile{address: addr} - profiles.Set(addr, newProfile) + profiles.Set(addr.String(), newProfile) return newProfile } @@ -43,7 +54,8 @@ func Render(path string) string { output := ufmt.Sprintf("stats: %d known profiles\n", profiles.Size()) return output case len(parts) == 1: - profile := GetByAddressOrName(parts[0]) + aon := users.AddressOrName(parts[0]) + profile := GetByAddressOrName(aon) if profile != nil { return profile.Render() }