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: grc20 registry #1072

Closed
wants to merge 1 commit into from
Closed

Conversation

n0izn0iz
Copy link
Contributor

@n0izn0iz n0izn0iz commented Aug 25, 2023

This is a contract that allows to get a GRC20 user interface from a realm pkg path
It's an example of the registry pattern that allows to dynamically access realms interfaces

Caveat: this depends on #974 being fixed, if this would be merged now, it would steal ownership of the foo20 token object and make it unusable

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.

Signed-off-by: Norman Meier <norman@berty.tech>
@Kouteki
Copy link
Contributor

Kouteki commented Jul 5, 2024

#974 has been merged. Is this PR still relevant?

@n0izn0iz
Copy link
Contributor Author

n0izn0iz commented Jul 5, 2024

it can be but I know some other contributors opened other versions of that
#1275

@n0izn0iz
Copy link
Contributor Author

n0izn0iz commented Jul 5, 2024

I will revisit

registry.Set(caller, token)
}

func Get(pkgPath string) (grc20.IGRC20, bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func Get(pkgPath string) (grc20.IGRC20, bool) {
func Get(pkgPath string) grc20.IGRC20 {

bool is not needed, != nil is enough.

}
return coin, true
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a MustGet(pkgPath string) grc20.IGRC20 that panics if not found.

if !ok {
return nil, false
}
coin, ok := coinI.(grc20.IGRC20)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is unnecessary, protected by Register.

func Render(path string) string {
s := "# GRC20 Registry\n\n" +
"## Registered Tokens\n\n"
registry.Iterate("", "", func(pkgPath string, tokenI interface{}) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a todo comment to add pagination.

if ok {
s += "- [" + token.GetName() + " (" + pkgPath + ")](" + pkgWebPath + ")\n"
} else {
s += "- [internal error: registered object is not a GRC20 token (" + pkgPath + ")](" + pkgWebPath + ")\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this check.

Comment on lines +31 to +32
s := "# GRC20 Registry\n\n" +
"## Registered Tokens\n\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
s := "# GRC20 Registry\n\n" +
"## Registered Tokens\n\n"
s := "# GRC20 Registry\n\n"

concise output.

Register(coin)
regCoin, ok := Get(realmAddr)
if !ok {
t.Fatal("expected to find coin")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can now use uassert if you want more concise tests :)

Comment on lines +13 to +15
func Register(token grc20.IGRC20) {
caller := std.PrevRealm().PkgPath()
registry.Set(caller, token)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func Register(token grc20.IGRC20) {
caller := std.PrevRealm().PkgPath()
registry.Set(caller, token)
func Register(optKey string, token grc20.IGRC20) {
rlmPath := std.PrevRealm().PkgPath()
if optKey != "" {
rlmPath += "." + optKey
}
registry.Set(optKey, token)

To support registering several tokens from the same contract.

registry.Set(caller, token)
}

func Get(pkgPath string) (grc20.IGRC20, bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func Get(pkgPath string) (grc20.IGRC20, bool) {
func Get(key string) (grc20.IGRC20, bool) {

@moul moul mentioned this pull request Jul 5, 2024
@moul
Copy link
Member

moul commented Jul 5, 2024

forked your PR here -> #2516

@n0izn0iz
Copy link
Contributor Author

Closing in favor of #2516

@n0izn0iz n0izn0iz closed this Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: ✅ Done
Status: 🌟 Wanted for Launch
Development

Successfully merging this pull request may close these issues.

3 participants