gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + gno.land: a blockchain for timeless code and fair open-source.
https://gno.land/
Other
898 stars 374 forks source link

Add a way to fetch a realm object via package path #3164

Open leohhhn opened 2 days ago

leohhhn commented 2 days ago

Description

I want to be able to check if a certain pkgpath actually contains a realm (or a p/, maybe), from within Gno. To give a simple example, I would use it to check whether or not a user has created their home realm.

Proposed API: std.GetRealmAt(pkgpath string) *std.Realm

Usage:

rlm := std.GetRealmAt("gno.land/r/leon/home")
if rlm != nil {
    // exists
}

Could also be a way to say, automatically deposit coins in case a specific realm exists, like rewarding users who've deployed a realm to a specific pkgpath.

WDYT?

thehowl commented 2 days ago

the idea sounds good, I don't see any obvious reason why not to.

Maybe there could be a better name

leohhhn commented 2 days ago

RealmFromPkgPath? Also not sure what to do if a p/ is requested. Would be cool to check for it, but there is no Package object in Gno (and there will not be one), so not sure how to relay this info and have a good function name.

moul commented 2 days ago

Can we first:

notJoon commented 2 days ago

This pattern is frequently used in the Gnoswap contracts as well. it could help reduce code duplication. 👍

moul commented 1 day ago

Do you have links where we can check out some examples?

notJoon commented 11 hours ago

Do you have links where we can check out some examples?

@moul Sorry for the late answer. Actually, I had confused it with a different pattern. but still, I think it could be useful for other functions if it added.

https://github.com/gnoswap-labs/gnoswap/blob/main/_deploy/r/gnoswap/common/access.gno