-
Notifications
You must be signed in to change notification settings - Fork 384
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
feat: grc20 registry #1072
Conversation
Signed-off-by: Norman Meier <[email protected]>
#974 has been merged. Is this PR still relevant? |
it can be but I know some other contributors opened other versions of that |
I will revisit |
registry.Set(caller, token) | ||
} | ||
|
||
func Get(pkgPath string) (grc20.IGRC20, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func Get(pkgPath string) (grc20.IGRC20, bool) { | |
func Get(pkgPath string) grc20.IGRC20 { |
bool is not needed, != nil
is enough.
} | ||
return coin, true | ||
} | ||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this check.
s := "# GRC20 Registry\n\n" + | ||
"## Registered Tokens\n\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") |
There was a problem hiding this comment.
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 :)
func Register(token grc20.IGRC20) { | ||
caller := std.PrevRealm().PkgPath() | ||
registry.Set(caller, token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func Get(pkgPath string) (grc20.IGRC20, bool) { | |
func Get(key string) (grc20.IGRC20, bool) { |
forked your PR here -> #2516 |
Closing in favor of #2516 |
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...
BREAKING CHANGE: xxx
message was included in the description