Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
matijamarjanovic authored Oct 15, 2024
2 parents ed62d9a + 679301a commit 4bb6072
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
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()
}

0 comments on commit 4bb6072

Please sign in to comment.