Skip to content

chore: try using cross() in examples #4155

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

Closed
wants to merge 1 commit into from
Closed
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
171 changes: 0 additions & 171 deletions examples/gno.land/r/leon/hof/datasource_test.gno

This file was deleted.

158 changes: 80 additions & 78 deletions examples/gno.land/r/leon/hof/hof.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"gno.land/p/demo/pausable"
"gno.land/p/demo/seqid"
"gno.land/p/moul/addrset"
"gno.land/r/leon/config"
)

const (
Expand Down Expand Up @@ -58,13 +57,15 @@ func init() {
itemsSortedByDownvotes: avl.NewTree(),
}

Ownable = ownable.NewWithAddress(config.OwnableMain.Owner()) // OrigSendOwnable?
Pausable = pausable.NewFromOwnable(Ownable)
//Ownable = ownable.NewWithAddress(config.OwnableMain.Owner()) // OrigSendOwnable?
//Pausable = pausable.NewFromOwnable(Ownable)
}

// Register registers your realm to the Hall of Fame
// Should be called from within code
func Register(title, description string) {
crossing()

if Pausable.IsPaused() {
return
}
Expand Down Expand Up @@ -111,81 +112,82 @@ func Register(title, description string) {
std.Emit("Registration")
}

func Upvote(pkgpath string) {
rawItem, ok := exhibition.items.Get(pkgpath)
if !ok {
panic(ErrNoSuchItem)
}

item := rawItem.(*Item)
caller := std.PreviousRealm().Address()

if item.upvote.Has(caller) {
panic(ErrDoubleUpvote)
}

if _, exists := exhibition.itemsSortedByUpvotes.Remove(getVoteSortKey(item.upvote.Size(), item.id)); !exists {
panic("error removing old upvote entry")
}

item.upvote.Add(caller)

exhibition.itemsSortedByUpvotes.Set(getVoteSortKey(item.upvote.Size(), item.id), item)
}

func Downvote(pkgpath string) {
rawItem, ok := exhibition.items.Get(pkgpath)
if !ok {
panic(ErrNoSuchItem)
}

item := rawItem.(*Item)
caller := std.PreviousRealm().Address()

if item.downvote.Has(caller) {
panic(ErrDoubleDownvote)
}

if _, exist := exhibition.itemsSortedByDownvotes.Remove(getVoteSortKey(item.downvote.Size(), item.id)); !exist {
panic("error removing old downvote entry")

}

item.downvote.Add(caller)

exhibition.itemsSortedByDownvotes.Set(getVoteSortKey(item.downvote.Size(), item.id), item)
}

func Delete(pkgpath string) {
if !Ownable.CallerIsOwner() {
panic(ownable.ErrUnauthorized)
}

i, ok := exhibition.items.Get(pkgpath)
if !ok {
panic(ErrNoSuchItem)
}

item := i.(*Item)
upvoteKey := getVoteSortKey(item.upvote.Size(), item.id)
downvoteKey := getVoteSortKey(item.downvote.Size(), item.id)

if _, removed := exhibition.items.Remove(pkgpath); !removed {
panic(ErrNoSuchItem)
}

if _, removed := exhibition.itemsSortedByUpvotes.Remove(upvoteKey); !removed {
panic(ErrNoSuchItem)
}

if _, removed := exhibition.itemsSortedByDownvotes.Remove(downvoteKey); !removed {
panic(ErrNoSuchItem)
}

if _, removed := exhibition.itemsSortedByCreation.Remove(getCreationSortKey(item.blockNum, item.id)); !removed {
panic(ErrNoSuchItem)
}
}
//
//func Upvote(pkgpath string) {
// rawItem, ok := exhibition.items.Get(pkgpath)
// if !ok {
// panic(ErrNoSuchItem)
// }
//
// item := rawItem.(*Item)
// caller := std.PreviousRealm().Address()
//
// if item.upvote.Has(caller) {
// panic(ErrDoubleUpvote)
// }
//
// if _, exists := exhibition.itemsSortedByUpvotes.Remove(getVoteSortKey(item.upvote.Size(), item.id)); !exists {
// panic("error removing old upvote entry")
// }
//
// item.upvote.Add(caller)
//
// exhibition.itemsSortedByUpvotes.Set(getVoteSortKey(item.upvote.Size(), item.id), item)
//}
//
//func Downvote(pkgpath string) {
// rawItem, ok := exhibition.items.Get(pkgpath)
// if !ok {
// panic(ErrNoSuchItem)
// }
//
// item := rawItem.(*Item)
// caller := std.PreviousRealm().Address()
//
// if item.downvote.Has(caller) {
// panic(ErrDoubleDownvote)
// }
//
// if _, exist := exhibition.itemsSortedByDownvotes.Remove(getVoteSortKey(item.downvote.Size(), item.id)); !exist {
// panic("error removing old downvote entry")
//
// }
//
// item.downvote.Add(caller)
//
// exhibition.itemsSortedByDownvotes.Set(getVoteSortKey(item.downvote.Size(), item.id), item)
//}
//
//func Delete(pkgpath string) {
// if !Ownable.CallerIsOwner() {
// panic(ownable.ErrUnauthorized)
// }
//
// i, ok := exhibition.items.Get(pkgpath)
// if !ok {
// panic(ErrNoSuchItem)
// }
//
// item := i.(*Item)
// upvoteKey := getVoteSortKey(item.upvote.Size(), item.id)
// downvoteKey := getVoteSortKey(item.downvote.Size(), item.id)
//
// if _, removed := exhibition.items.Remove(pkgpath); !removed {
// panic(ErrNoSuchItem)
// }
//
// if _, removed := exhibition.itemsSortedByUpvotes.Remove(upvoteKey); !removed {
// panic(ErrNoSuchItem)
// }
//
// if _, removed := exhibition.itemsSortedByDownvotes.Remove(downvoteKey); !removed {
// panic(ErrNoSuchItem)
// }
//
// if _, removed := exhibition.itemsSortedByCreation.Remove(getCreationSortKey(item.blockNum, item.id)); !removed {
// panic(ErrNoSuchItem)
// }
//}

func getVoteSortKey(votes int, id seqid.ID) string {
votesStr := strconv.Itoa(votes)
Expand Down
Loading
Loading