Skip to content

Commit

Permalink
feat: introduce personal realms, add r/manfred/home (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
moul authored Nov 23, 2023
1 parent c72a31e commit ebe47db
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 9 deletions.
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.

**Personal Realms Inclusion:** We're open to personal realms, but they must exemplify best practices and inspire others. To maintain our repository's organization, we may decline some realms. If so, consider uploading onchain and keeping source code separately. For higher acceptance odds, offer useful or original examples.

**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
}

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
3 changes: 3 additions & 0 deletions examples/gno.land/r/manfred/home/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module gno.land/r/manfred/home

require gno.land/r/manfred/config v0.0.0-latest
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

0 comments on commit ebe47db

Please sign in to comment.