From 78d97bf3691c29bd4c4181d409d7e563defaccbf Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 10 Oct 2024 15:53:27 +0200 Subject: [PATCH 1/5] foix --- examples/gno.land/r/leon/config/config.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gno.land/r/leon/config/config.gno b/examples/gno.land/r/leon/config/config.gno index cbc1e537e3f..5578431259a 100644 --- a/examples/gno.land/r/leon/config/config.gno +++ b/examples/gno.land/r/leon/config/config.gno @@ -50,7 +50,7 @@ func SetBackup(a std.Address) error { func checkAuthorized() error { caller := std.PrevRealm().Addr() - if caller != main || caller != backup { + if caller != main && caller != backup { return errors.New("config: unauthorized") } From e8afab737111557a3e035f9b84bb0b3942940462 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 10 Oct 2024 16:00:37 +0200 Subject: [PATCH 2/5] fix assert --- examples/gno.land/r/leon/config/config.gno | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/gno.land/r/leon/config/config.gno b/examples/gno.land/r/leon/config/config.gno index 5578431259a..a4391b78720 100644 --- a/examples/gno.land/r/leon/config/config.gno +++ b/examples/gno.land/r/leon/config/config.gno @@ -58,8 +58,7 @@ func checkAuthorized() error { } func AssertAuthorized() { - caller := std.PrevRealm().Addr() - if caller != main || caller != backup { - panic("config: unauthorized") + if err := checkAuthorized(); err != nil { + panic(err) } } From 1b404e90887bdf05c75413a97ea61ff917691815 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 10 Oct 2024 16:05:30 +0200 Subject: [PATCH 3/5] add errs --- examples/gno.land/r/leon/config/config.gno | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/gno.land/r/leon/config/config.gno b/examples/gno.land/r/leon/config/config.gno index a4391b78720..272b50fbbd3 100644 --- a/examples/gno.land/r/leon/config/config.gno +++ b/examples/gno.land/r/leon/config/config.gno @@ -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") ) func init() { @@ -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 { @@ -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 { @@ -51,7 +53,7 @@ func SetBackup(a std.Address) error { func checkAuthorized() error { caller := std.PrevRealm().Addr() if caller != main && caller != backup { - return errors.New("config: unauthorized") + return ErrUnauthorized } return nil From 8a820165f781e9b1902db73aa3960b38be915a08 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Thu, 10 Oct 2024 16:11:31 +0200 Subject: [PATCH 4/5] readability --- examples/gno.land/r/leon/config/config.gno | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/gno.land/r/leon/config/config.gno b/examples/gno.land/r/leon/config/config.gno index 272b50fbbd3..4e553c65f64 100644 --- a/examples/gno.land/r/leon/config/config.gno +++ b/examples/gno.land/r/leon/config/config.gno @@ -52,7 +52,9 @@ func SetBackup(a std.Address) error { func checkAuthorized() error { caller := std.PrevRealm().Addr() - if caller != main && caller != backup { + isAuthorized := caller == main || caller == backup + + if !isAuthorized { return ErrUnauthorized } From 538f211efd0aa17f8aa77030c3ea2079de724161 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Tue, 15 Oct 2024 19:29:49 +0200 Subject: [PATCH 5/5] update config --- examples/gno.land/r/leon/config/config.gno | 15 +++++---------- examples/gno.land/r/leon/home/home.gno | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/examples/gno.land/r/leon/config/config.gno b/examples/gno.land/r/leon/config/config.gno index 4e553c65f64..bc800ec8263 100644 --- a/examples/gno.land/r/leon/config/config.gno +++ b/examples/gno.land/r/leon/config/config.gno @@ -6,10 +6,11 @@ import ( ) var ( - main std.Address // leon's main address - backup std.Address // backup address - ErrInvalidAddr = errors.New("config: invalid address") - ErrUnauthorized = errors.New("config: unauthorized") + 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() { @@ -60,9 +61,3 @@ func checkAuthorized() error { return nil } - -func AssertAuthorized() { - if err := checkAuthorized(); err != nil { - panic(err) - } -} diff --git a/examples/gno.land/r/leon/home/home.gno b/examples/gno.land/r/leon/home/home.gno index 1f6a07e8959..ba688792a4c 100644 --- a/examples/gno.land/r/leon/home/home.gno +++ b/examples/gno.land/r/leon/home/home.gno @@ -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 } @@ -119,3 +125,7 @@ func renderMillipede() string { return out } + +func isAuthorized(addr std.Address) bool { + return addr == config.Address() || addr == config.Backup() +}