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

fix(r/leon/config): fix config bug #2934

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions examples/gno.land/r/leon/config/config.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
var (
main std.Address // leon's main address
backup std.Address // backup address

ErrInvalidAddr = errors.New("leon's config: invalid address")
ErrUnauthorized = errors.New("leon's config: unauthorized")
)

func init() {
Expand All @@ -24,7 +27,7 @@ func Backup() std.Address {

func SetAddress(a std.Address) error {
if !a.IsValid() {
return errors.New("config: invalid address")
return ErrInvalidAddr
}

if err := checkAuthorized(); err != nil {
Expand All @@ -37,7 +40,7 @@ func SetAddress(a std.Address) error {

func SetBackup(a std.Address) error {
if !a.IsValid() {
return errors.New("config: invalid address")
return ErrInvalidAddr
}

if err := checkAuthorized(); err != nil {
Expand All @@ -50,16 +53,11 @@ func SetBackup(a std.Address) error {

func checkAuthorized() error {
caller := std.PrevRealm().Addr()
if caller != main || caller != backup {
return errors.New("config: unauthorized")
isAuthorized := caller == main || caller == backup

if !isAuthorized {
return ErrUnauthorized
}

return nil
}

func AssertAuthorized() {
caller := std.PrevRealm().Addr()
if caller != main || caller != backup {
panic("config: unauthorized")
}
}
14 changes: 12 additions & 2 deletions examples/gno.land/r/leon/home/home.gno
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ TODO import r/gh
}

func UpdatePFP(url, caption string) {
config.AssertAuthorized()
if !isAuthorized(std.PrevRealm().Addr()) {
panic(config.ErrUnauthorized)
}

pfp = url
pfpCaption = caption
}

func UpdateAboutMe(col1, col2 string) {
config.AssertAuthorized()
if !isAuthorized(std.PrevRealm().Addr()) {
panic(config.ErrUnauthorized)
}

abtMe[0] = col1
abtMe[1] = col2
}
Expand Down Expand Up @@ -119,3 +125,7 @@ func renderMillipede() string {

return out
}

func isAuthorized(addr std.Address) bool {
return addr == config.Address() || addr == config.Backup()
}
Loading