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 the ability to call exposed struct methods on realm variables #1045

Open
gfanton opened this issue Aug 10, 2023 · 3 comments
Open

Add the ability to call exposed struct methods on realm variables #1045

gfanton opened this issue Aug 10, 2023 · 3 comments

Comments

@gfanton
Copy link
Member

gfanton commented Aug 10, 2023

Description

It would be beneficial to have the ability to call exposed struct methods on realm variables. This enhancement could be particularly useful for larger realms looking to better organize and categorize their code. Coupled with indexing on the helper page (as shown here), we could come closer to adopting a documentation style similar to that of Golang.

@gfanton gfanton changed the title Had The Ability To Call Exposed Struct Methods on Realm Variables Had the ability to call exposed struct methods on realm variables Aug 10, 2023
@moul
Copy link
Member

moul commented Aug 10, 2023

Absolutely loving it!

We can already call exposed struct methods by making a new contract:

import "gno.land/r/realmfoo"

func Bar() {
    realmfoo.Baz.Lorem()
}

I'm thinking of enhancing gnokey maketx call to support dots in endpoints: gnokey maketx call -pkgaddr gno.land/r/realmfoo -method Baz.Lorem.

I'm also keen on grouped struct methods in generated documentation. It'll help with a structured approach for admin tasks, making it less noisy for newcomers.

Just a heads up, I'm working indirectly on this in #1001. If it gets accepted, it'll cover a small part of your proposal.

@gfanton gfanton changed the title Had the ability to call exposed struct methods on realm variables Add the ability to call exposed struct methods on realm variables Aug 11, 2023
@moul
Copy link
Member

moul commented Aug 15, 2023

Btw, could be cool to use a single arg like gno.land/r/realmfoo.Baz.Lorem instead of -pkgaddr and -method.

Maybe for the #1017.

@moul
Copy link
Member

moul commented Sep 8, 2023

Regarding issue #1042, it's essential to establish secure best practices and design patterns.

For calls such as gno.land/r/realmfoo.Baz.Lorem, we might prefer using func Baz() bazInstance { return baz } over the simpler var Baz bazInstance.
This approach warrants further examination. Afterward, we can either utilize a linter or restrict the VM from exposing structures directly.

By integrating solutions like Gnoffee (#1092), we aim to maintain code readability while enhancing security.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🌟 Wanted for Launch
Development

No branches or pull requests

3 participants