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

feat: improve p/ownable API #2330

Merged
merged 5 commits into from
Jun 13, 2024
Merged
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
16 changes: 16 additions & 0 deletions examples/gno.land/p/demo/ownable/ownable.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"std"
)

const OwnershipTransferEvent = "OwnershipTransfer"

// Ownable is meant to be used as a top-level object to make your contract ownable OR
// being embedded in a Gno object to manage per-object ownership.
type Ownable struct {
Expand Down Expand Up @@ -31,7 +33,13 @@ func (o *Ownable) TransferOwnership(newOwner std.Address) error {
return ErrInvalidAddress
}

prevOwner := o.owner
o.owner = newOwner
std.Emit(
OwnershipTransferEvent,
"from", string(prevOwner),
Kouteki marked this conversation as resolved.
Show resolved Hide resolved
"to", string(newOwner),
)
return nil
}

Expand All @@ -44,7 +52,15 @@ func (o *Ownable) DropOwnership() error {
return err
}

prevOwner := o.owner
o.owner = ""

std.Emit(
OwnershipTransferEvent,
thehowl marked this conversation as resolved.
Show resolved Hide resolved
"from", string(prevOwner),
"to", "",
)

return nil
}

Expand Down
Loading