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(examples): Define Ownable and Transferrable Interfaces #2198

Draft
wants to merge 81 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
c307de3
define Ownable and Transferrable Interface for custom
linhpn99 May 26, 2024
0853491
Update the affected packages
linhpn99 May 26, 2024
a2e5c69
rename fields
linhpn99 May 26, 2024
b206494
embed interface instead of implement
linhpn99 May 26, 2024
fe82cab
update
linhpn99 May 26, 2024
e457231
update
linhpn99 May 26, 2024
d0c12d8
wrong name
linhpn99 May 26, 2024
10a767e
Merge branch 'master' into OwnableInterface
linhpn99 May 26, 2024
00f4ef0
unused error
linhpn99 May 26, 2024
1b835d2
Merge branch 'OwnableInterface' of https://github.com/linhpn99/gno in…
linhpn99 May 26, 2024
0163f8d
make tidy
linhpn99 May 26, 2024
22b8e27
make tidy again
linhpn99 May 26, 2024
deb9a29
Merge branch 'master' into OwnableInterface
linhpn99 May 26, 2024
9a34da6
Merge branch 'master' into OwnableInterface
linhpn99 May 27, 2024
3f2c0e1
Merge branch 'master' into OwnableInterface
linhpn99 May 27, 2024
c6ef120
remove helper pkg
linhpn99 May 27, 2024
cc9cf58
Merge branch 'master' into OwnableInterface
linhpn99 May 27, 2024
b04aadc
owner to transferrable
linhpn99 May 27, 2024
07ca903
Merge branch 'OwnableInterface' of https://github.com/linhpn99/gno in…
linhpn99 May 27, 2024
3b0a77c
tmp
linhpn99 May 27, 2024
8bd5ec9
tmp
linhpn99 May 27, 2024
2249f42
change to TestSetOrigCaller
linhpn99 May 27, 2024
8a8d39c
Merge branch 'master' into OwnableInterface
linhpn99 May 28, 2024
d51c88d
Merge branch 'master' into OwnableInterface
linhpn99 May 28, 2024
6764208
Merge branch 'master' into OwnableInterface
linhpn99 May 28, 2024
5d6dd97
Merge branch 'master' into OwnableInterface
linhpn99 May 29, 2024
5010520
Merge branch 'master' into OwnableInterface
linhpn99 May 29, 2024
f66a0f8
Merge branch 'master' into OwnableInterface
linhpn99 May 30, 2024
ce717f6
use TestSetRealm instead
linhpn99 May 30, 2024
c987e5e
Merge branch 'master' into OwnableInterface
linhpn99 May 31, 2024
2da9e4a
Merge branch 'master' into OwnableInterface
linhpn99 Jun 1, 2024
e162f4d
Merge branch 'master' into OwnableInterface
linhpn99 Jun 3, 2024
cceecb3
Merge branch 'master' into OwnableInterface
linhpn99 Jun 3, 2024
b71df38
Merge branch 'master' into OwnableInterface
linhpn99 Jun 6, 2024
0f36ba5
Merge branch 'master' into OwnableInterface
linhpn99 Jun 8, 2024
525449d
Merge branch 'master' into OwnableInterface
linhpn99 Jun 11, 2024
3c459fc
refactor code after manfred's review
linhpn99 Jun 11, 2024
4e51027
missing changes
linhpn99 Jun 11, 2024
6f97dfe
return interface
linhpn99 Jun 11, 2024
a6ca8bc
return interface
linhpn99 Jun 11, 2024
4765f37
update
linhpn99 Jun 11, 2024
3d19623
update
linhpn99 Jun 11, 2024
f5fe77e
rename
linhpn99 Jun 11, 2024
8bd3ac0
fixed all
linhpn99 Jun 12, 2024
a3dad4c
fixed all
linhpn99 Jun 12, 2024
0e7f9d5
fix pausable
linhpn99 Jun 12, 2024
e2aadeb
solve conflict
linhpn99 Jun 13, 2024
6fd4c2b
wrong delete
linhpn99 Jun 13, 2024
6f007f2
Merge branch 'master' into OwnableInterface
linhpn99 Jun 13, 2024
6173b88
Merge branch 'master' into OwnableInterface
linhpn99 Jun 14, 2024
0cc00c4
update from master
linhpn99 Jun 14, 2024
1dbe711
Merge branch 'master' into OwnableInterface
linhpn99 Jun 17, 2024
0fcb041
Merge branch 'master' into OwnableInterface
linhpn99 Jun 17, 2024
104140f
Merge branch 'master' into OwnableInterface
linhpn99 Jun 19, 2024
86beac8
Merge branch 'master' into OwnableInterface
linhpn99 Jun 19, 2024
97d4b8e
Merge branch 'master' into OwnableInterface
linhpn99 Jun 19, 2024
2bd3f5f
Merge branch 'master' into OwnableInterface
linhpn99 Jun 25, 2024
1fb8a5d
Merge branch 'master' into OwnableInterface
linhpn99 Jun 26, 2024
05c8f72
Merge branch 'master' into OwnableInterface
linhpn99 Jun 27, 2024
b6dec1e
Merge branch 'master' into OwnableInterface
linhpn99 Jul 3, 2024
0c2e674
Merge branch 'master' into OwnableInterface
linhpn99 Jul 3, 2024
bc3f796
Merge branch 'master' into OwnableInterface
linhpn99 Jul 4, 2024
88b7481
fix CI
linhpn99 Jul 4, 2024
daafb62
Merge branch 'master' into OwnableInterface
linhpn99 Jul 4, 2024
9fa9d29
Merge branch 'master' into OwnableInterface
linhpn99 Jul 5, 2024
15cd55e
Merge branch 'master' into OwnableInterface
linhpn99 Jul 5, 2024
9754165
Merge branch 'master' into OwnableInterface
linhpn99 Jul 6, 2024
f537530
Merge branch 'master' into OwnableInterface
linhpn99 Jul 6, 2024
d1bea90
Merge branch 'master' into OwnableInterface
linhpn99 Jul 8, 2024
efafea7
use interface instead
linhpn99 Jul 8, 2024
8ad4405
Merge branch 'master' into OwnableInterface
linhpn99 Jul 8, 2024
5326931
Merge branch 'master' into OwnableInterface
linhpn99 Jul 9, 2024
04d4b75
Merge branch 'master' into OwnableInterface
linhpn99 Jul 9, 2024
17b7b7e
Merge branch 'master' into OwnableInterface
linhpn99 Jul 14, 2024
05e9a7b
Merge branch 'master' into OwnableInterface
moul Jul 14, 2024
fd450a1
Merge branch 'master' into OwnableInterface
linhpn99 Jul 14, 2024
73f9ddb
Merge branch 'master' into OwnableInterface
linhpn99 Jul 20, 2024
9eb51d4
Merge branch 'master' into OwnableInterface
linhpn99 Jul 22, 2024
22c98f6
Merge branch 'master' into OwnableInterface
linhpn99 Aug 1, 2024
b987650
Merge branch 'master' into OwnableInterface
linhpn99 Aug 10, 2024
26d7f83
resolve conflict
linhpn99 Sep 21, 2024
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
6 changes: 3 additions & 3 deletions examples/gno.land/p/demo/memeland/memeland.gno
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type Post struct {
}

type Memeland struct {
*ownable.Ownable
*ownable.DefaultOwnable
linhpn99 marked this conversation as resolved.
Show resolved Hide resolved
Posts []*Post
MemeCounter seqid.ID
}

func NewMemeland() *Memeland {
return &Memeland{
Ownable: ownable.New(),
Posts: make([]*Post, 0),
DefaultOwnable: ownable.New(),
Posts: make([]*Post, 0),
}
}

Expand Down
31 changes: 22 additions & 9 deletions examples/gno.land/p/demo/ownable/ownable.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,33 @@ import (
"std"
)

// 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 {
// Ownable defines an interface that requires a method to get the owner's address
Copy link
Member

@moul moul Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is just adding noise.

type Ownable interface {
Owner() std.Address
}

// Transferrable embeds Ownable, indicating that an object can transfer ownership
type Transferrable interface {
Ownable

TransferOwnership(newOwner std.Address) error
moul marked this conversation as resolved.
Show resolved Hide resolved
}

// DefaultOwnable provides a basic implementation of ownership functionality
// It can be used as a top-level object to make a contract ownable or embedded within
// another object to manage per-object ownership.
type DefaultOwnable struct {
linhpn99 marked this conversation as resolved.
Show resolved Hide resolved
owner std.Address
}

func New() *Ownable {
return &Ownable{
func New() *DefaultOwnable {
return &DefaultOwnable{
owner: std.GetOrigCaller(),
}
}

// TransferOwnership transfers ownership of the Ownable struct to a new address
func (o *Ownable) TransferOwnership(newOwner std.Address) error {
func (o *DefaultOwnable) TransferOwnership(newOwner std.Address) error {
err := o.CallerIsOwner()
if err != nil {
return err
Expand All @@ -34,7 +47,7 @@ func (o *Ownable) TransferOwnership(newOwner std.Address) error {
// DropOwnership removes the owner, effectively disabling any owner-related actions
// Top-level usage: disables all only-owner actions/functions,
// Embedded usage: behaves like a burn functionality, removing the owner from the struct
func (o *Ownable) DropOwnership() error {
func (o *DefaultOwnable) DropOwnership() error {
err := o.CallerIsOwner()
if err != nil {
return err
Expand All @@ -45,13 +58,13 @@ func (o *Ownable) DropOwnership() error {
}

// CallerIsOwner checks if the caller of the function is the Realm's owner
func (o *Ownable) CallerIsOwner() error {
func (o *DefaultOwnable) CallerIsOwner() error {
linhpn99 marked this conversation as resolved.
Show resolved Hide resolved
if std.GetOrigCaller() == o.owner {
return nil
}
return ErrUnauthorized
}

func (o *Ownable) Owner() std.Address {
func (o *DefaultOwnable) Owner() std.Address {
return o.owner
}
12 changes: 6 additions & 6 deletions examples/gno.land/p/demo/pausable/pausable.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ package pausable
import "gno.land/p/demo/ownable"

type Pausable struct {
*ownable.Ownable
*ownable.DefaultOwnable
linhpn99 marked this conversation as resolved.
Show resolved Hide resolved
paused bool
}

// New returns a new Pausable struct with non-paused state as default
func New() *Pausable {
return &Pausable{
Ownable: ownable.New(),
paused: false,
DefaultOwnable: ownable.New(),
paused: false,
}
}

// NewFromOwnable is the same as New, but with a pre-existing top-level ownable
func NewFromOwnable(ownable *ownable.Ownable) *Pausable {
func NewFromOwnable(ownable *ownable.DefaultOwnable) *Pausable {
return &Pausable{
Ownable: ownable,
paused: false,
DefaultOwnable: ownable,
paused: false,
}
}

Expand Down
Loading