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(examples): awesome gno #3963

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

matijamarjanovic
Copy link
Contributor

@matijamarjanovic matijamarjanovic commented Mar 18, 2025

implementation of #3928

This is an on chain representation of the Awesome Gno repo which serves a purpose of showcasing dApp built in the community. The way this implementation works is:

  • there is a group of admins who are in charge of accepting/rejecting proposals
  • one becomes admin by getting added by another admin
  • anyone can make a proposal that some dapp is presented on awesome-gno
  • one dapp can belong to multiple categories
  • categories allow different types of realms/dapps to be present on awesome gno realm
UI (mock data):

image
image
image
image
image
image

@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Mar 18, 2025
@Gno2D2 Gno2D2 requested a review from a team March 18, 2025 02:16
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Mar 18, 2025

🛠 PR Checks Summary

🔴 Pending initial approval by a review team member, or review from tech-staff

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
  • The pull request description provides enough details
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)
🔴 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: matijamarjanovic/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🔴 Requirement not satisfied
└── 🔴 If
    ├── 🔴 Condition
    │   └── 🔴 Or
    │       ├── 🔴 At least 1 user(s) of the organization reviewed the pull request (with state "APPROVED")
    │       ├── 🔴 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🔴 Else
        └── 🔴 And
            ├── 🟢 This label is applied to pull request: review/triage-pending
            └── 🔴 On no pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission
The pull request description provides enough details

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 Not (🔴 Pull request author is a member of the team: core-contributors)
    └── 🟢 Not (🔴 Pull request author is user: dependabot[bot])

Can be checked by

  • team core-contributors

@matijamarjanovic matijamarjanovic changed the title feat(examples): awesome gno on chain feat(examples): awesome gno realm Mar 18, 2025
@matijamarjanovic matijamarjanovic changed the title feat(examples): awesome gno realm feat(examples): awesome gno Mar 18, 2025
@matijamarjanovic matijamarjanovic marked this pull request as ready for review March 18, 2025 20:48
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Mar 18, 2025
Copy link

codecov bot commented Mar 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@jefft0
Copy link
Contributor

jefft0 commented Mar 20, 2025

Problem here with "not enough arguments in call to page.Picker", same as #3793 (comment) :-)

@matijamarjanovic
Copy link
Contributor Author

Problem here with "not enough arguments in call to page.Picker", same as #3793 (comment) :-)

Addressed in 567df81. I've also added hof registration (if you remember #3479 it caused lint to break in init) which suprisingly causes no trouble here..

@michelleellen michelleellen requested a review from wyhaines March 21, 2025 11:00
@leohhhn leohhhn requested a review from jeronimoalbi March 24, 2025 11:49
Comment on lines 27 to 30
admins.Set("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y", true)
admins.Set(std.CurrentRealm().Address().String(), true)
admins.Set(std.PreviousRealm().Address().String(), true)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use p/moul/addrset for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I figured since authz is already managing admin set so I've just implemented that instead in 048d3ef

Comment on lines 34 to 47
func AddAdmin(addr std.Address) error {
caller := std.PreviousRealm().Address()

if !isAdmin(caller) {
return ufmt.Errorf("not authorized: only admins can add new admins")
}
if !addr.IsValid() {
return ufmt.Errorf("invalid address")
}

admins.Set(addr.String(), true)
std.Emit("AdminAdded", "address", addr.String())
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be handled with authorizable or with p/moul/authz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied in 048d3ef

Comment on lines 49 to 65
func RemoveAdmin(addr std.Address) error {
caller := std.PreviousRealm().Address()

if !isAdmin(caller) {
return ufmt.Errorf("not authorized: only admins can remove admins")
}
if !addr.IsValid() {
return ufmt.Errorf("invalid address")
}
if admins.Size() <= 1 {
return ufmt.Errorf("cannot remove the last admin")
}

admins.Remove(addr.String())
std.Emit("AdminRemoved", "address", addr.String())
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, use a package for privileged actions. I suggest you dig into p/moul/authz; we are slowly moving away from ownable and authorizable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied in 048d3ef

Comment on lines 77 to 84
categories.Iterate("", "", func(key string, value interface{}) bool {
cat := value.(Category)
if cat.Name == name {
exists = true
return true
}
return false
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not like this; you should use the fact that AVL tree has a lookup of O(1) - just use the category name as the key. Make sure that you sanitize the key properly (ie no spaces,etc)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also you can use any instead of interface{}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, makes sense, forgot about avl.Has().. implemented in 4f6f4fa

DappIDs: []uint64{},
}

categories.Set(strconv.FormatUint(nextCategoryID, 10), category)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FormatUint > strconv.Itoa

Copy link
Contributor Author

@matijamarjanovic matijamarjanovic Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean I should generally use FormatUint ?

Comment on lines 18 to 19
nextDappID uint64 = 1
nextProposalID uint64 = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seqid is more practical when working with AVL trees

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok implemented in 9887784

Comment on lines 153 to 162
func ListCategories() []Category {
result := []Category{}

categories.Iterate("", "", func(key string, value interface{}) bool {
result = append(result, value.(Category))
return false
})

return result
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need this to be a getter for someone outside of this realm, check out avl/rotree, which exposes a tree without setter functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I was going for (but also for render), applied in 6fe1d53

return result
}

func ProposeNewDapp(title, description, url string, categoryNamesStr string) (uint64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For proposals, let's try using some DAO code that already exists. @jeronimoalbi maybe we can integrate with gno.me as we talked, but maybe we should just do commondao+datasource. wdyt?

Copy link
Member

@jeronimoalbi jeronimoalbi Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using gno.me seems to be the right approach with the caveat that before mainnet will require some small changes to your custom proposal definition methods, there are a couple of changes to be done for security that are still pending. But this way would be interesting so you can have a SubDAO within the gno.me DAO tree.

Using commondao is also valid, as a package or directly though the commondao realm. The package would require a bit more effort. If commondao is used we can also integrate with gnome space if it makes sense and list content there if you support the datasource interface from gno.land/p/jeronimoalbi/datasource.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, so in 381c72d I've added datasource support for Proposals, Dapps and Categories (with tests) as we talked today @leohhhn, I'd love some feedback on that as it is pretty long. Looking forward, I should wait until commonDao package/realm is merged and use that here if I understood our conversation today correctly?

Comment on lines 177 to 202
var categoryNames []string
if categoryNamesStr != "" {
for _, name := range strings.Split(categoryNamesStr, ",") {
trimmedName := strings.TrimSpace(name)
if trimmedName != "" {
categoryNames = append(categoryNames, trimmedName)
}
}
}

if len(categoryNames) > 0 {
for _, catName := range categoryNames {
categoryExists := false
categories.Iterate("", "", func(key string, value interface{}) bool {
cat := value.(Category)
if cat.Name == catName {
categoryExists = true
return true
}
return false
})
if !categoryExists {
return 0, ufmt.Errorf("category '%s' does not exist", catName)
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much nesting, can be simplified

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 29f82c1

caller := std.PreviousRealm().Address()

if !isAdmin(caller) {
return ufmt.Errorf("not authorized: only admins can update dApp categories")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error repeats, it should be declared somewhere. speciifcally for this, either use the p/ errors for control access (ownable/authz), or declare it at top level of this package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4cd9637

this commit defines errors in types.gno and uses those

Comment on lines 379 to 416
for _, catName := range strings.Split(newCategories, ",") {
_, found := GetCategory(catName)
if !found {
return ufmt.Errorf("category not found: %s", catName)
}
}

for _, oldCat := range dapp.Categories {
found := false
for _, newCat := range strings.Split(newCategories, ",") {
if oldCat == newCat {
found = true
break
}
}
if !found {
err := RemoveDappFromCategory(dappID, oldCat)
if err != nil {
return err
}
}
}

for _, newCat := range strings.Split(newCategories, ",") {
found := false
for _, oldCat := range dapp.Categories {
if newCat == oldCat {
found = true
break
}
}
if !found {
err := addDappToCategory(dappID, newCat)
if err != nil {
return err
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely too much nesting.

If you need to use double for loops, you're probably doing something wrong - these could be avoided with the proper use of maps/avl trees

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i see what you mean, hopefully this makes more sense : 27dc704

caller := std.PreviousRealm().Address()

if !isAdmin(caller) {
return ufmt.Errorf("not authorized: only admins can delete dApps")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above for errors

Copy link
Contributor Author

@matijamarjanovic matijamarjanovic Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4cd9637 this and all other non specific errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages. review/triage-pending PRs opened by external contributors that are waiting for the 1st review
Projects
Status: No status
Status: In Review
Status: Triage
Development

Successfully merging this pull request may close these issues.

5 participants