-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grc20,foo20): lazily resolve username in grc20 (and foo20) (#145)
* chore(grc20): lazily resolve username Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com> * chore: function renaming Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com> * chore: switch to string instead of std.Address for input types on grc20 and foo20 Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com> * initial commit showing direction * chore: fixup Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com> * chore: fixup Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com> Co-authored-by: Jae Kwon <jae@tendermint.com>
- Loading branch information
Showing
5 changed files
with
71 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package users | ||
|
||
import "std" | ||
|
||
type AddressOrName string | ||
|
||
func (aon AddressOrName) IsName() bool { | ||
return aon != "" && aon[0] == '@' | ||
} | ||
|
||
func (aon AddressOrName) GetName() (string, bool) { | ||
if len(aon) >= 2 && aon[0] == '@' { | ||
return string(aon[1:]), true | ||
} | ||
return "", false | ||
} | ||
|
||
func (aon AddressOrName) Resolve() std.Address { | ||
name, isName := aon.GetName() | ||
if isName { | ||
user := GetUserByName(name) | ||
return user.address | ||
} else { | ||
return std.Address(aon) // TODO check validity | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters