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

Add better UX for checking if a Gno address is mathematically valid #1298

Closed
leohhhn opened this issue Oct 26, 2023 · 3 comments · Fixed by #1303
Closed

Add better UX for checking if a Gno address is mathematically valid #1298

leohhhn opened this issue Oct 26, 2023 · 3 comments · Fixed by #1303
Assignees

Comments

@leohhhn
Copy link
Contributor

leohhhn commented Oct 26, 2023

Description

Currently, the way to check if an address is valid in Gno is calling std.DecodeBech32. I propose a small addition to the std library; a wrapper function around std.DecodeBech32. This will make the common operation of checking the validity of an address much nicer from the devX perspective.

@leohhhn leohhhn self-assigned this Oct 26, 2023
@thehowl
Copy link
Member

thehowl commented Oct 26, 2023

func (Address) Valid() bool is probably a reasonable API (so it can be checked with if addr.Valid() simply)

@leohhhn
Copy link
Contributor Author

leohhhn commented Oct 26, 2023

@thehowl

Correct me if I'm wrong, or I am not understanding something correctly, but to me it seems that the issue with that approach is that DecodeBech32 doesn't exist on the same level as the Address type. DecodeBech32 is defined here, while the Address type is defined at Gno level (if you can say it that way), here. The solution I see now is to put the validity check function in the std library, right next to DecodeBech32.

@thehowl
Copy link
Member

thehowl commented Oct 26, 2023

it is currently that way, but that is changing with #859. after that is merged, we can have it very easily

moul added a commit that referenced this issue Oct 28, 2023
## Description

This PR adds a simple `Valid()` check to the Address type. It is there
to prevent most human errors, and doesn't actually validate the math
behind bech32 (for now) - it relies only on the length of the address.

Running `gno test .` will run the unit test for the `Valid()` function.
Closes: #1298 

<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
- [ ] 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>

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: moul <94029+moul@users.noreply.github.com>
gfanton pushed a commit to gfanton/gno that referenced this issue Nov 9, 2023
## Description

This PR adds a simple `Valid()` check to the Address type. It is there
to prevent most human errors, and doesn't actually validate the math
behind bech32 (for now) - it relies only on the length of the address.

Running `gno test .` will run the unit test for the `Valid()` function.
Closes: gnolang#1298 

<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
- [ ] 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>

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: moul <94029+moul@users.noreply.github.com>
moul added a commit to moul/gno that referenced this issue Nov 14, 2023
## Description

This PR adds a simple `Valid()` check to the Address type. It is there
to prevent most human errors, and doesn't actually validate the math
behind bech32 (for now) - it relies only on the length of the address.

Running `gno test .` will run the unit test for the `Valid()` function.
Closes: gnolang#1298 

<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
- [ ] 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>

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: moul <94029+moul@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

2 participants