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

chore(examples): modify pausable #3628

Merged
merged 5 commits into from
Feb 2, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: make ownable working with not fully initialized
Signed-off-by: moul <[email protected]>
moul committed Feb 2, 2025
commit ea58f549c67c08cba5ae40d22333b872d46967a5
18 changes: 14 additions & 4 deletions examples/gno.land/p/demo/ownable/ownable.gno
Original file line number Diff line number Diff line change
@@ -65,18 +65,28 @@ func (o *Ownable) DropOwnership() error {
}

// Owner returns the owner address from Ownable
func (o Ownable) Owner() std.Address {
func (o *Ownable) Owner() std.Address {
if o == nil {
return std.Address("")
}
return o.owner
}

// CallerIsOwner checks if the caller of the function is the Realm's owner
func (o Ownable) CallerIsOwner() bool {
func (o *Ownable) CallerIsOwner() bool {
if o == nil {
return false
}
return std.PrevRealm().Addr() == o.owner
}

// AssertCallerIsOwner panics if the caller is not the owner
func (o Ownable) AssertCallerIsOwner() {
if std.PrevRealm().Addr() != o.owner {
func (o *Ownable) AssertCallerIsOwner() {
if o == nil {
panic(ErrUnauthorized)
}
caller := std.PrevRealm().Addr()
if caller != o.owner {
panic(ErrUnauthorized)
}
}