Skip to content

Commit

Permalink
chore: fixup
Browse files Browse the repository at this point in the history
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
  • Loading branch information
moul committed Aug 25, 2022
1 parent 4245757 commit a274f85
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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
11 changes: 6 additions & 5 deletions examples/gno.land/r/profile/profile.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
28 changes: 20 additions & 8 deletions examples/gno.land/r/profile/profiles.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ package profile

import (
"std"
"strings"

"gno.land/p/avl"
"gno.land/p/ufmt"
"gno.land/r/users"
)

// TODO: makes sense to implement an allowance system?

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()
Expand All @@ -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
}

Expand All @@ -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()
}
Expand Down

0 comments on commit a274f85

Please sign in to comment.