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
Changes from 5 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
21 changes: 12 additions & 9 deletions examples/gno.land/r/leon/config/config.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
)

var (
main std.Address // leon's main address
backup std.Address // backup address
main std.Address // leon's main address
backup std.Address // backup address
ErrInvalidAddr = errors.New("config: invalid address")
ErrUnauthorized = errors.New("config: unauthorized")
)
leohhhn marked this conversation as resolved.
Show resolved Hide resolved

func init() {
Expand All @@ -24,7 +26,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 +39,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 +52,17 @@ 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")
if err := checkAuthorized(); err != nil {
panic(err)
}
}
Loading