Skip to content

feat(examples): awesome gno #3963

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

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4d90158
initial commit
matijamarjanovic Mar 18, 2025
24d9f54
make good ui
matijamarjanovic Mar 18, 2025
3aa0b32
add tests
matijamarjanovic Mar 18, 2025
c46d19b
make some funcs non exported. tidy
matijamarjanovic Mar 18, 2025
9c8452a
don't use string slices but a single string in args of funcs so MsgCa…
matijamarjanovic Mar 18, 2025
e14e3c2
fix links
matijamarjanovic Mar 18, 2025
12d8f95
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Mar 18, 2025
6dd3a5e
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Mar 20, 2025
567df81
add hof registration & picker implmenetation
matijamarjanovic Mar 20, 2025
9887784
implement seqid
matijamarjanovic Mar 25, 2025
8bb2627
use addrset instead of avl tree for admins
matijamarjanovic Mar 25, 2025
048d3ef
use authz
matijamarjanovic Mar 25, 2025
4f6f4fa
use seq id for categories as well
matijamarjanovic Mar 25, 2025
6fe1d53
implement rotree for listing categories
matijamarjanovic Mar 25, 2025
4cd9637
add error definitions to types and use thos
matijamarjanovic Mar 25, 2025
5f01610
authz doesnt return boolean but err, fix
matijamarjanovic Mar 25, 2025
29f82c1
simplify code in ProposeNewDapp
matijamarjanovic Mar 25, 2025
27dc704
more simplifying + add new error type
matijamarjanovic Mar 25, 2025
77b177b
add errors, fix minor bugs
matijamarjanovic Mar 25, 2025
8e47dc1
fmt
matijamarjanovic Mar 25, 2025
3798051
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Mar 25, 2025
42ad5c6
add working tests
matijamarjanovic Mar 25, 2025
381c72d
add datasource integration
matijamarjanovic Mar 27, 2025
7b77473
add comment separators
matijamarjanovic Mar 27, 2025
e00515d
fmt
matijamarjanovic Mar 27, 2025
165ebca
remove print
matijamarjanovic Mar 28, 2025
7e342ea
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Mar 28, 2025
c5ddd9b
Merge branch 'feat/awesome-gno' of https://github.com/matijamarjanovi…
matijamarjanovic Mar 28, 2025
fd4b73e
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Mar 31, 2025
b8c5220
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Mar 31, 2025
71484f5
- init auth in var block
matijamarjanovic Mar 31, 2025
8fdefd8
convert all uint64 ids to seqid; stop using strconv in general
matijamarjanovic Mar 31, 2025
c0057d6
fix fmt
matijamarjanovic Mar 31, 2025
3c131c5
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Apr 1, 2025
c9156d3
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Apr 7, 2025
e9b63d4
remove add/remove admin and expose Auth object, which by itself is sa…
matijamarjanovic Apr 8, 2025
ef9ba54
Merge branch 'feat/awesome-gno' of https://github.com/matijamarjanovi…
matijamarjanovic Apr 8, 2025
26a9e18
add new errror and use it correctly
matijamarjanovic Apr 8, 2025
4a76788
instead of saving objects in the tree, save pointers
matijamarjanovic Apr 8, 2025
1dccbec
change types to dapp pointers
matijamarjanovic Apr 8, 2025
919678f
- remove all errors and use panics
matijamarjanovic Apr 8, 2025
39b9fdc
rewrite the whole code with basic operations and using authz correctl…
matijamarjanovic Apr 9, 2025
bdd754b
add tests
matijamarjanovic Apr 9, 2025
a0c927d
add datasource support
matijamarjanovic Apr 9, 2025
d874044
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Apr 9, 2025
281e46d
add txlink support
matijamarjanovic Apr 9, 2025
641638f
allow app to have multiple authors
matijamarjanovic Apr 9, 2025
2f831f8
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Apr 16, 2025
05a891e
- change dapps to items
matijamarjanovic Apr 16, 2025
f957103
some formatting
matijamarjanovic Apr 16, 2025
99dc36e
remove uppercase in gno.land
matijamarjanovic Apr 16, 2025
feafe35
make exported adds not return anything
matijamarjanovic Apr 16, 2025
7c90ef5
add newline
matijamarjanovic Apr 16, 2025
fbb2610
make the bottom text more of a disclaimer
matijamarjanovic Apr 16, 2025
c29a297
display couple of most recent items on homepage
matijamarjanovic Apr 16, 2025
20d5c74
remove my addresses from authorized people and remove mock
matijamarjanovic Apr 16, 2025
831a2f9
make items have slices of category ids instead of using avl.Trees
matijamarjanovic Apr 16, 2025
7139c3f
fix fmt
matijamarjanovic Apr 16, 2025
42999de
Merge branch 'master' into feat/awesome-gno
matijamarjanovic Apr 16, 2025
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
272 changes: 272 additions & 0 deletions examples/gno.land/r/demo/awesomegno/awesomegno.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
package awesomegno

import (
"std"
"time"

"gno.land/p/demo/avl"
"gno.land/p/demo/avl/rotree"
"gno.land/p/demo/seqid"
"gno.land/p/moul/authz"

"gno.land/r/leon/hor"
)

var (
items = avl.NewTree()
categories = avl.NewTree()

Items = rotree.Wrap(items, nil)
Categories = rotree.Wrap(categories, nil)

nextItemID seqid.ID
nextCategoryID seqid.ID

authority = authz.NewMemberAuthority(
std.Address("g125em6arxsnj49vx35f0n0z34putv5ty3376fg5"), // leon
std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5"), // moul
)
Auth = authz.NewWithAuthority(authority)
)

func init() {
hor.Register("AwesomeGno", "Awesome Gno is a registry for gnowesome dApps, tools and resources on gno.land")
}

func AddItem(title, description, url, authorAddress string) {
if title == "" {
panic("item title cannot be empty")
}

if err := Auth.Do("add_item", func() error {
addItem(title, description, url, std.Address(authorAddress))
return nil
}); err != nil {
panic(err)
}
}

func UpdateItem(itemID seqid.ID, title, description, url string, categories ...seqid.ID) {
if err := Auth.Do("update_item", func() error {
updateItem(itemID, title, description, url, []std.Address{}, categories...)
return nil
}); err != nil {
panic(err)
}
}

func UpdateItemsAuthors(itemID seqid.ID, authors []std.Address) {
if err := Auth.Do("update_items_authors", func() error {
updateItem(itemID, "", "", "", authors, []seqid.ID{}...)
return nil
}); err != nil {
panic(err)
}
}

func DeleteItem(itemID seqid.ID) {
if err := Auth.Do("delete_item", func() error {
deleteItem(itemID)
return nil
}); err != nil {
panic(err)
}
}

func AddCategory(name, description string) {
if name == "" {
panic("category name cannot be empty")
}

if err := Auth.Do("add_category", func() error {
addCategory(name, description)
return nil
}); err != nil {
panic(err)
}
}

func UpdateCategory(categoryID seqid.ID, name, description string) {
if err := Auth.Do("update_category", func() error {
updateCategory(categoryID, name, description)
return nil
}); err != nil {
panic(err)
}
}

func DeleteCategory(categoryID seqid.ID) {
if err := Auth.Do("delete_category", func() error {
deleteCategory(categoryID)
return nil
}); err != nil {
panic(err)
}
}

func addItem(name, description, url string, author std.Address) seqid.ID {
item := &Item{
ID: nextItemID.Next(),
Title: name,
Description: description,
Authors: []std.Address{author},
URL: url,
CreatedAt: time.Now(),
Categories: []seqid.ID{},
}

items.Set(item.ID.String(), item)

std.Emit("ItemAdded",
"id", item.ID.String(),
"name", name,
)

return item.ID
}

func updateItem(itemID seqid.ID, title, description, url string, authors []std.Address, categoryIDs ...seqid.ID) {
item, found := items.Get(itemID.String())
if !found {
panic("item not found: " + itemID.String())
}

d := item.(*Item)

if title != "" {
d.Title = title
}
if description != "" {
d.Description = description
}
if url != "" {
d.URL = url
}
if len(authors) > 0 {
d.Authors = authors
}

if len(categoryIDs) > 0 {
for _, oldCatID := range d.Categories {
if cat, found := categories.Get(oldCatID.String()); found {
cat.(*Category).items.Remove(itemID.String())
}
}

d.Categories = categoryIDs
for _, categoryID := range categoryIDs {
category, found := categories.Get(categoryID.String())
if !found {
panic("category not found: " + categoryID.String())
}
category.(*Category).items.Set(itemID.String(), item)
}
}

categoriesstr := ""
for _, categoryID := range categoryIDs {
categoriesstr += categoryID.String() + ","
}

std.Emit("ItemUpdated",
"id", itemID.String(),
"title", d.Title,
"description", d.Description,
"url", d.URL,
"authors", authorsToString(d.Authors),
"categories", categoriesstr,
)
}

func authorsToString(authors []std.Address) string {
result := ""
for i, author := range authors {
if i > 0 {
result += ","
}
result += string(author)
}
return result
}

func deleteItem(itemID seqid.ID) {
item, found := items.Get(itemID.String())
if !found {
panic("item not found: " + itemID.String())
}

for _, catID := range item.(*Item).Categories {
if cat, found := categories.Get(catID.String()); found {
cat.(*Category).items.Remove(itemID.String())
}
}

items.Remove(itemID.String())

std.Emit("ItemDeleted", "id", itemID.String())
}

func addCategory(name, description string) seqid.ID {
category := &Category{
ID: nextCategoryID.Next(),
Name: name,
Description: description,
CreatedAt: time.Now(),
items: avl.NewTree(),
}

categories.Set(category.ID.String(), category)

std.Emit("CategoryAdded",
"id", category.ID.String(),
"name", name,
)

return category.ID
}

func updateCategory(categoryID seqid.ID, name, description string) {
category, found := categories.Get(categoryID.String())
if !found {
panic("category not found: " + categoryID.String())
}

c := category.(*Category)

if name != "" {
c.Name = name
}
if description != "" {
c.Description = description
}

std.Emit("CategoryUpdated",
"id", categoryID.String(),
"name", c.Name,
"description", c.Description,
)
}

func deleteCategory(categoryID seqid.ID) {
category, found := categories.Get(categoryID.String())
if !found {
panic("category not found: " + categoryID.String())
}

category.(*Category).items.Iterate("", "", func(itemID string, value any) bool {
if item, ok := value.(*Item); ok {
newCategories := make([]seqid.ID, 0)
for _, catID := range item.Categories {
if catID != categoryID {
newCategories = append(newCategories, catID)
}
}
item.Categories = newCategories
}
return false
})

categories.Remove(categoryID.String())

std.Emit("CategoryDeleted", "id", categoryID.String())
}
Loading
Loading