Skip to content

Commit c695303

Browse files
committed
chore: fixup
Signed-off-by: Manfred Touron <[email protected]>
1 parent af4c8a2 commit c695303

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package main
22

33
import (
4-
"fmt"
5-
64
"gno.land/r/profile"
75
)
86

97
func main() {
10-
fmt.Println("test")
8+
println(profile.Render(""))
9+
//_ = profile.Render
1110
// various data types
1211
// avatar
1312
// ip address
1413
}
1514

1615
// Output:
16+
// a

examples/gno.land/r/profile/profile.gno

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package profile
33
import (
44
"std"
55

6-
"gno.land/r/users"
6+
"gno.land/p/ufmt"
7+
// "gno.land/r/users"
78
)
89

910
// FIXME: manage privacy?
1011

1112
func newProfile(addr std.Address) *Profile {
12-
now := std.GetTime()
13+
now := std.GetTimestamp()
1314
return &Profile{
1415
address: addr,
1516
created: now,
@@ -19,12 +20,12 @@ func newProfile(addr std.Address) *Profile {
1920
type Profile struct {
2021
dict map[string]interface{}
2122
address std.Address
22-
created uint64
23-
updated uint64
23+
created std.Time
24+
updated std.Time
2425
}
2526

2627
func (p *Profile) save() {
27-
now := std.GetTime()
28+
now := std.GetTimestamp()
2829
if p.created == 0 {
2930
p.created = now
3031
}

examples/gno.land/r/profile/profiles.gno

+20-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ package profile
22

33
import (
44
"std"
5+
"strings"
56

7+
"gno.land/p/avl"
8+
"gno.land/p/ufmt"
69
"gno.land/r/users"
710
)
811

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

1114
var profiles *avl.MutTree // std.Address.String() -> *Profile
1215

16+
func init() {
17+
// profiles = avl.NewMutTree()
18+
}
19+
1320
func Update(dict map[string]interface{}) {
1421
// FIXME: ask a price per stored data length?
1522
currentUser := std.GetOrigCaller()
@@ -18,20 +25,24 @@ func Update(dict map[string]interface{}) {
1825
}
1926

2027
func GetByAddressOrName(aon users.AddressOrName) *Profile {
21-
return profiles.Get(aon)
28+
addr := aon.Resolve()
29+
profile, found := profiles.Get(addr.String())
30+
if !found {
31+
return nil
32+
}
33+
return profile.(*Profile)
2234
}
2335

24-
func getOrCreateProfileByAddress(aon users.AddressOrName) *Profile {
36+
func getOrCreateProfileByAddress(addr std.Address) *Profile {
2537
// lookup existing profile
26-
profile := profiles.Get(aon)
27-
if profile != nil {
28-
return profile
38+
profile, found := profiles.Get(addr.String())
39+
if found {
40+
return profile.(*Profile)
2941
}
3042

3143
// create
32-
addr := aon.Resolve()
3344
newProfile := &Profile{address: addr}
34-
profiles.Set(addr, newProfile)
45+
profiles.Set(addr.String(), newProfile)
3546
return newProfile
3647
}
3748

@@ -43,7 +54,8 @@ func Render(path string) string {
4354
output := ufmt.Sprintf("stats: %d known profiles\n", profiles.Size())
4455
return output
4556
case len(parts) == 1:
46-
profile := GetByAddressOrName(parts[0])
57+
aon := users.AddressOrName(parts[0])
58+
profile := GetByAddressOrName(aon)
4759
if profile != nil {
4860
return profile.Render()
4961
}

0 commit comments

Comments
 (0)