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): forms #2 #3

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

feat(examples): forms #2 #3

wants to merge 225 commits into from

Conversation

agherasie
Copy link
Owner

@agherasie agherasie commented Jan 15, 2025

Sorry for the long hiatus which caused gnolang#2604 to close, I moved to South Korea this year for a university exchange program and kind of let this PR collect dust.


As part of the student contributor program, I attempted to create a new example realm that allows the creation and submission of forms on gno !

Features

  • Form Creation: Create new forms with specified titles, descriptions, and fields.
    CreateForm(...)
  • Form Submission: Submit answers to forms.
    SubmitForm(...)
  • Form Retrieval: Retrieve existing forms and their submissions.
    GetForms(...), GetFormByID(...), GetAnswer(...)
  • Form Deadline: Set a precise time range during which a form can be interacted with.

Field Types

The system supports the following field types:

type example
string {"label": "Name", "fieldType": "string", "required": true}
number {"label": "Age", "fieldType": "number", "required": true}
boolean {"label": "Is Student?", "fieldType": "boolean", "required": false}
choice `{"label": "Favorite Food", "fieldType": "[Pizza
multi-choice `{"label": "Hobbies", "fieldType": "{Reading

Demo

The external repo where the initial development took place and where you can find the frontend is here.

The web app itself is hosted here

And the most recent test4 version of the contract is forms2


Screenshots :

gnoweb Render() image
a form response in the web interface image
creating a form in the web interface image

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

agherasie and others added 26 commits July 16, 2024 19:59
thehowl and others added 30 commits March 3, 2025 23:33
This would panic at runtime due to a missed condition in
TypedValue.GetLength.
Hi Gnomes ,
This is my home page. it was difficult to be creative 😅 , so i did what
i can do
### Home :
I put some informations about me 

![Screenshot 2025-01-09 at 21 14
20](https://github.com/user-attachments/assets/6da7926f-7b89-4363-83b0-83d103232f10)

### World kitchen :
I'm passionate about cooking, so I've set up a page for those who want
to share their national culinary specialties or just their favorite
recipes, since there are so many nationalities in `gno` community.

![Screenshot 2025-01-09 at 21 22
54](https://github.com/user-attachments/assets/f82b543e-43c4-47ac-8bab-4fe2874378a3)

feel free to add your recipes ;)

![Screenshot 2025-01-09 at 21 35
17](https://github.com/user-attachments/assets/1773522b-0b5a-431d-b8af-12ab6dc1c96e)

@leohhhn

---------

Co-authored-by: Leon Hudak <[email protected]>
Co-authored-by: mous1985 <[email protected]>
This is a home realm. 

@michelleellen kindly asked me if I wanted to create a
r/grepsuzette/home so here it is :)

---------

Co-authored-by: grepsuzette <[email protected]>
Co-authored-by: Leon Hudak <[email protected]>
closes gnolang#2944 and gnolang#3863 
<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
…#3861)

This used to return a weird panic, now it correctly panics with a nil
pointer dereference.

Extracted from gnolang#3847.

---------

Co-authored-by: ltzmaxwell <[email protected]>
This PR ensures that when we recover inside of testing.gno, we then
print also the resulting stracktrace, using a special function.
gnolang#3852)

Imaginary values are not supported in Gno. Found by fuzzing and
compatibility checks between Go and Gno

```go
package main

const (
	Nj = 0i
)
```
## Description

The pager was not being reset upon post resetting the app.
…lang#3875)

- only show the types in the parameters and results for functions,
matching go's reflect.Type.String
- match field list to go's

extracted from gnolang#3847.

This blocks gnolang#3847 because for
simplicity, we use the type String() methods for syntaxes like `%#v` and
`%T` which show the type. Making these match Go's avoids us modifying
some types, and I think it's a nice addition in making us more
consistent with Go.
We have developed two packages: `accesscontrol` and `timelock` inspired
by openzeppelin contracts. These packages were created in collaboration
with @mous1985 , @DIGIX666 , and myself.

The `accesscontrol` package was primarily designed to support the
development of the `timelock` package, but it can also be used
independently for many other use cases.

### Features

#### Accesscontrol

The `accesscontrol` package provides a library for managing roles and
permissions within Gno. It allows for the creation, assignment, and
management of roles with specific administrative privileges, ensuring
that only authorized accounts can perform certain actions.

#### Timelock

The `timelock` package offers a library for scheduling, canceling, and
executing time-locked operations in Gno. It ensures that operations are
only carried out after a specified delay and provides mechanisms to
manage and verify the status of these operations. The creation of the
`accesscontrol` package was necessary to provide role and permission
management required for the administrative tasks of `timelock`.

### Use Cases

#### Accesscontrol

- Realm Administration Management: Create administrator roles to manage
realms and assign or revoke roles as needed.
- Role-Based Access Control (RBAC): Implement an RBAC system to control
who can access which resources and perform which actions within a Gno
dApp.
- Security and Compliance: Use roles to ensure that only authorized
individuals can perform critical actions, helping to meet security and
compliance regulations.

#### Timelock

- Delayed Transactions: Schedule transactions or actions to be executed
at a specific future time.
- Asset Locking: Implement asset locking mechanisms where users must
wait for a certain period before they can access or move assets.
- Task Automation: Automate periodic or conditional tasks using specific
time delays.

These examples of use cases are not exhaustive, and many other things
are possible with these packages.

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Co-authored-by: théo dub <[email protected]>
Co-authored-by: mous1985 <[email protected]>
Co-authored-by: Mustapha <[email protected]>
Co-authored-by: deelawn <[email protected]>
Co-authored-by: Thox <[email protected]>
Co-authored-by: DIGIX666 <[email protected]>
Co-authored-by: Manfred Touron <[email protected]>
Co-authored-by: Morgan <[email protected]>
Co-authored-by: Morgan <[email protected]>
…handling (gnolang#3835)

This PR refactors the `generateBreadcrumbPaths` function to provide a
consistent model for handling breadcrumb parts extracted from the URL
path, arguments, and query parameters. The changes include:

- **Consistent Extraction of Parts:**
The existing logic that splits the URL path into parts remains
unchanged. However, the root (`p` / `r`) part is not clickable anymore
since we don't have any content here for now. It also fixes the HTML
list with proper ending tags and Aria attributes/elements.

- **New Argument Parts (ArgParts):**
Instead of storing all arguments as a single string, we now split the
url.Args value (i.e., the part after the `:`) into individual segments.
These segments are processed similarly to the path parts, with
cumulative URLs generated for each segment. This provides a more
granular and consistent breadcrumb structure.

- **Query Parameters Handling:**
Query parameters (after the `?`) are iterated over and added to a new
Queries slice. Since iterating over an empty map is safe, no additional
condition is required here.

- **Update query value on click from input:**
By clicking on the query from the breadcrumb, it becomes possible to
edit the value quickly.
 
- **Fixing breadcrumb special characters in the input box**
Enable `EncodeNoEscape` in the `EncodeURL` functions in order to remove
escaped chars.

## Captures
### Before
<img width="907" alt="Capture d’écran 2025-03-04 à 23 50 16"
src="https://github.com/user-attachments/assets/7fb6c6a8-cc15-4caa-80e2-cd6eae20cea2"
/>
<img width="908" alt="Capture d’écran 2025-03-04 à 23 50 55"
src="https://github.com/user-attachments/assets/b9870915-e90a-4af1-b12e-bd387715e629"
/>
<img width="907" alt="Capture d’écran 2025-03-05 à 00 27 16"
src="https://github.com/user-attachments/assets/6ee3c9fb-a762-4c1c-bcd0-05e3278bb0f0"
/>




### After

<img width="907" alt="Capture d’écran 2025-03-04 à 23 46 56"
src="https://github.com/user-attachments/assets/b5442c99-9259-4c45-8019-bc55e9e979aa"
/>
<img width="908" alt="Capture d’écran 2025-03-04 à 23 43 06"
src="https://github.com/user-attachments/assets/8e4f6002-fbc7-45d8-8e7c-23b394fd5108"
/>
<img width="908" alt="Capture d’écran 2025-03-04 à 23 43 30"
src="https://github.com/user-attachments/assets/e3194167-f65b-4806-90de-d2e7d32c60f1"
/>
<img width="907" alt="Capture d’écran 2025-03-05 à 01 05 20"
src="https://github.com/user-attachments/assets/fde2457c-081a-4c83-948a-ff125f10b60f"
/>
From issue : gnolang#2489

I found an issue with the code segment parsing arguments from the
request that did not support base64 encoding, so I implemented logic to
handle it. If there are any inconsistencies, please share the opinion

![Screenshot from 2024-07-06
12-00-09](https://github.com/gnolang/gno/assets/167175638/a4a0304d-10e0-41cc-abbc-d82a81301847)


<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Co-authored-by: Morgan Bazalgette <[email protected]>
Co-authored-by: Miloš Živković <[email protected]>
…#3886)

close: gnolang#2763 .

This PR addresses the nil pointer issue, also fix the `redeclaration`
issue by @thehowl .
`filetest` is a special case, , `redeclaration` is still permitted in
filetest files(e.g. z_0_filetest, z_1_filetest...) for `convenience`.

---------

Co-authored-by: Morgan Bazalgette <[email protected]>
Continues gnolang#3855 by @leohhhn 
The changes were great, and I kept most of the good content (thank you).
However, this PR slightly shifted the direction by making the `docs/`
folder more focused on GitHub, Markdown, and the project, rather than
Docusaurus, the website, or global documentation. In the future, we may
create a more comprehensive documentation website, but for now, we want
the `docs/` folder to be efficient and centered around the project.
Ideally, it should be the only resource we invest energy in. However, I
can easily envision supplementing it with external resources, such as
blog posts or another repository with non-project documentation.
Alternative view: leohhhn#2

- [x] Reorganize by personas (`builders/`, `users/`) and maintain a
`references/` section for metadata.
- [x] Remove items that do not belong in the `docs/` of this repository
(e.g., intro to blockchain).
- [x] Remove unusual numbers in titles, likely intended for Docusaurus.
- [x] Merge related content, such as combining `stdlibs/*` into
`stdlibs.md`.
- [x] Simplify `Makefile` and make it consistent with the other folders.
- [x] Simplify introduced `.github/workflows`.
- [x] Conduct a quick proofreading.
- [x] Fix links.
- [x] Removed docusaurus, can be discussed in an upcoming PR.
[1be1a3a](gnolang@1be1a3a)
- [x] Removed content that should belong to somewhere else, such as
other README.md files.

---------

Signed-off-by: moul <[email protected]>
Co-authored-by: leohhhn <[email protected]>
Co-authored-by: sw360cab <[email protected]>
Co-authored-by: Leon Hudak <[email protected]>
Co-authored-by: Morgan Bazalgette <[email protected]>
The purpose of this package is to support a data store where multiple
collection based storages could be defined.

Each named storage defines a collection of records where each record can
optionally and by default have any number of user defined fields, which
can be constrained to a pre defined set of fields by using a schema
definition.

The implementation is a layer on top of `p/moul/collection`.

Example of `datastore` package usage:

```go
package main

import (
	ds "gno.land/p/jeronimoalbi/datastore"
)

func main() {
	var db ds.Datastore

	// Define a unique case insensitive index for user emails
	emailIdx := ds.NewIndex("email", func(r ds.Record) string {
		return r.MustGet("email").(string)
	}).Unique().CaseInsensitive()

	// Create a new storage for user records
	storage := db.CreateStorage("users", ds.WithIndex(emailIdx))

	// Add a user with a single "email" field
	u := storage.NewRecord()
	u.Set("email", "[email protected]")

	// Save to assing user ID and update index(es)
	u.Save()
	println("Records =", storage.Size())

	// Find the user by email
	print("Search by Email ... ")
	record, found := storage.Get(emailIdx.Name(), "[email protected]")
	if !found {
		panic("record by email not found")
	}

	println("ID =", record.ID())

	// Find user by ID
	print("Search by ID ... ")
	record, found = storage.GetByID(u.ID())
	if !found {
		panic("record by ID not found")
	}

	email := record.MustGet("email").(string)
	println("Email =", email)

	// Delete the user from the storage and update index(es)
	storage.Delete(u.ID())
	println("Records =", storage.Size())
}

// Output:
// Records = 1
// Search by Email ... ID = 1
// Search by ID ... Email = [email protected]
// Records = 0
```
…lang#3854)

Fixes gnolang#3240

One-line fix for realms not having independent states when tested
together.
This PR:
- add dismissed review state support to the bot:
gnolang@90cdc51
(requested here:
gnolang#3238 (comment))
- add gnoweb codeowners to the config:
gnolang@f0001cc
(requested here:
gnolang#3238 (comment))

Note: It might be cleaner in the future to create codeowner teams for
different parts of the codebase (e.g. a `gnoweb-codeowners` team for
`gfanton` and `alexiscolin`) rather than manually listing each user in
the config. Something to think about.
This PR removes `fmt` from being implemented using NativeValue /
NativeType, and implements a mostly pure-Gno implementation which uses
an initial, rudimentary implementation of Gno reflection for `fmt`.

This PR is ready for review, but some of its related work has been
broken out in separate PR to aid reviewing and create atomic PRs.

- Blocks gnolang#3677
- Relates to gnolang#1361
- Depends on gnolang#3861
- Depends on gnolang#3862 
- Depends on gnolang#3875

## Summary of changes

### addition of `gnovm/tests/stdlibs/fmt`

The main addition is of this set of files, which comprises the bulk of
the added lines of this PR. Most of this is a copy of Go's `fmt`.
Changes are mostly in `errors.gno` and `format.gno` - the other files
are left mostly intact.

At the end of `print.gno`, there is an added section containing a set of
native functions which form the "reflection" needed to implement the
`fmt` package in a manner that is similar to Go's. The implementation is
not meant to be a public API and is meant to serve initially only for
usage by `fmt`; we can use this as sketch to then implement a proper
`reflect` package.

Attention in reviewing should mostly go to this `print.gno` and its
`print.go` counterpart, especially for any missed cases or potential
bugs.

### addition of `gnovm/tests/stdlibs/os`

Complementary to the above, to avoid some problems that were arising due
to the handling of os.Stdin, Stdout and Stderr, I also removed the
NativeValue / NativeType in `os` and replaced them with a native binding
alternative.

To avoid having both an `Output` and `ErrorOutput` on the machine, this
package supports an additional method on the `Machine.Output`,
`StderrWrite`, which is implemented by writers who wish to differentiate
between the two.

### other

- `gnovm/pkg/test`
	- added support for `StderrWrite` in its writers
	- removed native values for `os`  and `fmt`
- combine `stdin`, `stdout`, `stderr` into a single `output` parameter
in the related functions.
- `gnovm/pkg/gnolang`
- support testing `gnovm/tests/stdlibs`, by only testing stdlibs that
exist there and not in the official stdlibs.
- `gnovm/cmd/gno`
	- fix tests which needed the `fmt` package.
- `gnovm/tests/files`
- most changed tests are result of the improved functionality of the
`fmt` package, allowing for instance to show declared types correctly.
- `gnovm/stdlibs/bufio`
	- due to the removal of `os.Stdin`, this example had to be changed.
- `misc/genstd`
- added a flag `-skip-init-order` when creating it could cause problems,
like the testing stdlibs; fixed a bug when using `TypedValue`.
This is a continuation of gnolang#3176.

It breaks the params struct into fields and stores them in
<module>:_:<fieldname>. All parameters are of the form <module>:<name>
or <module>:<realm/_/*>:<name>. A colon is used rather than a period/dot
because it's ambiguous with realm domains.

std.SetParam is realm-local only, limited and safe.
sys/params.SetSysParam is arbitrary and global. Need to make sure it's
only importable by r/sys/params, but I think we said we'd do this with
"internal" or something. Maybe for a followup PR.

The ParamsKeeper is divided into prefix spaces, `pk.WithModule("bank")`
for example, and that is passed into the BankKeeper, that way the
BankKeeper only has access to the bank:* param space. "language
capabilities" security. But the VMKeeper needs to the root ParamsKeeper
because it needs to be able to modify anything via r/sys/params.

I got rid of the .type suffix of param keys. It's less safe right now
but we can add type safety to this later. You *can* and *must* use the
type suffix from toml for certain types though; "strings" which
represent []strings must be suffixed by .strings, because toml only
gives []interface{}{}.

---------

Co-authored-by: piux2 <[email protected]>
Co-authored-by: Manfred Touron <[email protected]>
Co-authored-by: Morgan <[email protected]>
## Description

Adds a simple package to make your Gno errors match your realm path.

Go wizards tell me if I'm doing something wrong 🙏
## Description

Addresses: gnolang#2827 

This PR refactors the current `r/demo/users` & `r/sys/users` system in
accordance to the issue mentioned above. Below is the high-level
overview of the new system.

It also makes a small change to the `p/demo/releases` lib.

## `r/gnoland/users/v1`

- Fully replaces `r/demo/users`
- Is the main entry point for users looking to register a name, create
an alias (rename themselves), or delete their username
- Implements allowed username pattern checks as per the issue gnolang#2827
- Is pausable by GovDAO, contains no other administration functionality
- Contains a nice UI/render for users (please suggest improvements) -
see bottom
- Uses `r/demo/profile` for displaying extra information about a user
(to be moved to `r/nt/profiles` or `r/gnoland/profiles`)
- @jaekwon's request: add payment in GNOT for registration ✅

## `r/sys/users`

- Namespace check moved to `r/sys/names`
- Contains the address/name <> user stores, to which only whitelisted
realms can write
- Contains resolver functions & other useful getters
- Is callable only by whitelisted realms, such as `r/gnoland/users/v1`,
etc.
-  Whitelist is fully managed by GovDAO (after gnolang#3523 was resolved)

## `r/sys/names`
- Namespace checking functionality moved here (from `r/sys/users`),
added tests, as discussed with @moul
- ~Verify function now only upgradeable with a GovDAO prop instead of
previously being ownable~ verify func upgrateability removed, as we'll
just deploy a `r/sys/names/vX` when we need to, as discussed with @moul
- ~Verify functionality is now not pausable and on by default, as per
discussions with @moul. This means Portal Loop will need to be patched
upon merging this PR, as many txs will fail due to not having proper
namespace permissions.~ The namespace verify functionality is off by
default, but should be enabled in genesis via `r/sys/names.Enable()`.
The Portal Loop will indeed need to be patched if we enable this
functionality.

## `Keeper` & genesis params
- Updated the VM keeper to call `r/sys/names` for the namespace check
instead of `r/sys/users`
- Updated params to load `r/sys/names`, which the keeper will call

### `r/gnoland/users/v1`

![Screenshot 2025-01-17 at 01 10
56](https://github.com/user-attachments/assets/b824c2aa-29b3-4497-99bf-689b7f49cb4a)

## `r/gnoland/users`

Currently this is the "releases" page for the user registration systems
(example data):

<img width="1287" alt="Screenshot 2025-02-03 at 12 19 28"
src="https://github.com/user-attachments/assets/0407b21d-4457-48af-80f4-b0ef10649337"
/>

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
</details>

---------

Co-authored-by: Morgan <[email protected]>
Co-authored-by: Manfred Touron <[email protected]>
## Description

Master is red because CI didn't catch VM tests related to `r/demo/users`
in gnolang#3166

This PR fixes this and also fixes some other leftover occurrences of
`r/demo/users`.

cc @thehowl this is another `examples/` dep that should probably be
removed.

---------

Co-authored-by: Morgan Bazalgette <[email protected]>
In order to allow gnoteam images to be served through CSP, this PR adds
the dedicated domain https://assets.gnoteam.com/ to the rules. In
addition to https://gnolang.github.io/, which is used for the blog
system, gnoteam assets will also be used for general purposes, ensuring
secure and consistent asset delivery.
Fixes gnolang#3831.

Adds type checking as a step before executing a package's tests.
\+ fix the underlying bug in cmd/gno that was causing the failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.