Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add r/demo/users #24

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/p/memeland/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ require (
gno.land/p/demo/seqid v0.0.0-latest
gno.land/p/demo/testutils v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
)
14 changes: 13 additions & 1 deletion api/p/memeland/memeland.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"gno.land/p/demo/avl"
"gno.land/p/demo/ownable"
"gno.land/p/demo/seqid"
"gno.land/r/demo/users"
)

const (
Expand Down Expand Up @@ -38,19 +39,30 @@ func NewMemeland() *Memeland {
}
}

func isUserRegistered(add std.Address) bool {
user := users.GetUserByAddress(add)
return user != nil
}

// PostMeme - Adds a new post
func (m *Memeland) PostMeme(data string, timestamp int64) string {
if data == "" || timestamp <= 0 {
panic("timestamp or data cannot be empty")
}

// check address is register
author := std.PrevRealm().Addr()
if !isUserRegistered(author) {
panic("you have to register in r/demo/users to post!")
}

// Generate ID
id := m.MemeCounter.Next().String()

newPost := &Post{
ID: id,
Data: data,
Author: std.PrevRealm().Addr(),
Author: author,
Timestamp: time.Unix(timestamp, 0),
UpvoteTracker: avl.NewTree(),
}
Expand Down