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: introduce personal realms, add r/manfred/home #1138

Merged
merged 15 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
24 changes: 15 additions & 9 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# Gnolang examples

Folder contains Gnolang realms and libraries demos.
Share contracts here to improve engine testing, although it's not required.
Consider separate repository for contracts, but this may limit experience due to ongoing gnomod support work.
Main repository can't reference separate code, causing potential development issues.
This folder showcases Gnolang realms and library demos. These examples not only aid in engine testing but also provide a glimpse into the potential of Gnolang's capabilities.

While sharing contracts here can enhance engine testing, it's not mandatory. If considering a separate repository for contracts, be aware that this might restrict the experience due to the continuous efforts around `gno mod` support. A key point to note is that the main repository cannot reference separate code, which might pose developmental challenges.

## Personal Realms & Shared Content

**Prioritizing Shared Content:** As we expand our examples and use-cases, it's essential to prioritize shared content that benefits the broader community. These examples serve as a foundation and reference for all users.

**Accepting Personal Realms:** We're now open to accepting personal realms. However, with the vision of maintaining a streamlined and universally helpful main repository, personal realms should pave the way for others. They should act as exemplary models and encourage best practices.
moul marked this conversation as resolved.
Show resolved Hide resolved

**Recommended Approach:**
- Use `r/demo` and `p/demo` for generic examples and components that can be imported by others. These are meant to be easily referenced and utilized by the community.
- Personal realms are welcomed if they are easily maintainable with the Continuous Integration (CI) system. If a personal realm becomes cumbersome to maintain or doesn't align with the CI's checks, it might be relocated to a less prominent location or even removed.

## Usage

Our recommendation is to use the [gno](../gnovm/cmd/gno) utility to develop contracts locally before publishing them on-chain.
This approach offers a faster and streamlined workflow, along with additional debugging features.
Simply fork or create new contracts and refer to the Makefile.
Once everything looks good locally, you can then publish it on a localnet or testnet.
Our recommendation is to use the [gno](../gnovm/cmd/gno) utility to develop contracts locally before publishing them on-chain. This approach offers a faster and streamlined workflow, along with additional debugging features. Simply fork or create new contracts and refer to the Makefile. Once everything looks good locally, you can then publish it on a localnet or testnet.

See [`awesome-gno` tutorials](https://github.com/gnolang/awesome-gno#tutorials).
For further guidance and insights, please refer to the [`awesome-gno` tutorials](https://github.com/gnolang/awesome-gno#tutorials).
41 changes: 41 additions & 0 deletions examples/gno.land/r/manfred/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Manfred's Personal Realms on gno.land

## Introduction

Welcome to the root directory of Manfred's personal realms on `gno.land`. Each
realm within this directory serves a specific purpose and offers a glimpse into
Manfred's interests, projects, and more.

## ⚠️ Disclaimer

This is a very early iteration and is subject to change frequently. The
structure and content of these realms are still in the experimental phase. The
concept was inspired by Jae Kwon's idea to manage his to-do list in
`jaekwon/home`. If you're using or referencing these realms, be prepared for
regular updates and modifications.

## Structure

- `manfred/home`: This is the main realm where Manfred lists items and topics of
interest to him.
`manfred/config`: Configuration used by other realms.
- `manfred/...`: Coming soon.

## Usage

Each realm can be accessed and interacted with individually. Typically, realms
implement a `Render()` function which presents the main content or functionality
of that realm.

## Access Control

All realms in this directory have a built-in security check to ensure that only
Manfred can interact with the contents in a meaningful way. Unauthorized access
attempts might be able to see the content but will not be able to make
modifications or access certain functionalities.

## Contributions & Collaboration

These realms are personal by nature. If you've stumbled upon them and have
suggestions or want to collaborate on a particular topic, please reach out
directly to Manfred.
20 changes: 20 additions & 0 deletions examples/gno.land/r/manfred/config/config.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package config

import "std"

var addr = std.Address("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq")

func Addr() std.Address {
return addr
}

func UpdateAddr(newAddr std.Address) {
AssertIsAdmin()
addr = newAddr
moul marked this conversation as resolved.
Show resolved Hide resolved
}

func AssertIsAdmin() {
if std.GetOrigCaller() != addr {
panic("restricted area")
}
}
1 change: 1 addition & 0 deletions examples/gno.land/r/manfred/config/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/manfred/config
1 change: 1 addition & 0 deletions examples/gno.land/r/manfred/home/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/manfred/home
56 changes: 56 additions & 0 deletions examples/gno.land/r/manfred/home/home.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package home

import "gno.land/r/manfred/config"

var (
todos []string
status string
memeImgURL string
)

func init() {
todos = append(todos, "fill this todo list...")
status = "Online" // Initial status set to "Online"
memeImgURL = "https://i.imgflip.com/7ze8dc.jpg"
}

func Render(path string) string {
content := "# Manfred's (gn)home Dashboard\n\n"

content += "## Meme\n"
content += "![](" + memeImgURL + ")\n\n"

content += "## Status\n"
content += status + "\n\n"

content += "## Personal ToDo List\n"
for _, todo := range todos {
content += "- [ ] " + todo + "\n"
}
content += "\n"

// TODO: Implement a feature to list replies on r/boards on my posts
// TODO: Maybe integrate a calendar feature for upcoming events?

return content
}

func AddNewTodo(todo string) {
config.AssertIsAdmin()
todos = append(todos, todo)
}

func DeleteTodo(todoIndex int) {
config.AssertIsAdmin()
if todoIndex >= 0 && todoIndex < len(todos) {
// Remove the todo from the list by merging slices from before and after the todo
todos = append(todos[:todoIndex], todos[todoIndex+1:]...)
} else {
panic("Invalid todo index")
}
}

func UpdateStatus(newStatus string) {
config.AssertIsAdmin()
status = newStatus
}
19 changes: 19 additions & 0 deletions examples/gno.land/r/manfred/home/z1_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import "gno.land/r/manfred/home"

func main() {
println(home.Render(""))
}

// Output:
// # Manfred's (gn)home Dashboard
//
// ## Meme
// ![](https://i.imgflip.com/7ze8dc.jpg)
//
// ## Status
// Online
//
// ## Personal ToDo List
// - [ ] fill this todo list...
35 changes: 35 additions & 0 deletions examples/gno.land/r/manfred/home/z2_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"std"

"gno.land/r/manfred/home"
)

func main() {
std.TestSetOrigCaller("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq")
home.AddNewTodo("aaa")
home.AddNewTodo("bbb")
home.AddNewTodo("ccc")
home.AddNewTodo("ddd")
home.AddNewTodo("eee")
home.UpdateStatus("Lorem Ipsum")
home.DeleteTodo(3)
println(home.Render(""))
}

// Output:
// # Manfred's (gn)home Dashboard
//
// ## Meme
// ![](https://i.imgflip.com/7ze8dc.jpg)
//
// ## Status
// Lorem Ipsum
//
// ## Personal ToDo List
// - [ ] fill this todo list...
// - [ ] aaa
// - [ ] bbb
// - [ ] ddd
// - [ ] eee
Loading