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

Allow cw-ownable for multiple ownerships in one contract #21

Closed
wants to merge 5 commits into from

Conversation

taitruong
Copy link
Contributor

Referring to #17, there has been recent request also by Stargaze team, which forked repo and refactored cw-ownable. For detailed explanations see PR on public awesome repo here: public-awesome#1

For simplicity pasting description here as well:
All the logic has been moved to new Struct OwnershipStore. cw-ownable package is still a singleton:

/// Storage constant for the contract's ownership
pub const OWNERSHIP_KEY: &str = "ownership";
pub const OWNERSHIP: OwnershipStore = OwnershipStore::new(OWNERSHIP_KEY);

all existing functions now using new store struct:

pub fn initialize_owner(
    storage: &mut dyn Storage,
    api: &dyn Api,
    owner: Option<&str>,
) -> StdResult<Ownership<Addr>> {
    OWNERSHIP.initialize_owner(storage, api, owner)
}

pub fn is_owner(store: &dyn Storage, addr: &Addr) -> StdResult<bool> {
    OWNERSHIP.is_owner(store, addr)
}

pub fn assert_owner(store: &dyn Storage, sender: &Addr) -> Result<(), OwnershipError> {
    OWNERSHIP.assert_owner(store, sender)
}

pub fn update_ownership(
    deps: DepsMut,
    block: &BlockInfo,
    sender: &Addr,
    action: Action,
) -> Result<Ownership<Addr>, OwnershipError> {
    OWNERSHIP.update_ownership(deps, block, sender, action)
}

pub fn get_ownership(storage: &dyn Storage) -> StdResult<Ownership<Addr>> {
    OWNERSHIP.get_ownership(storage)
}

So contract using cw-ownable still uses above functions like initialize_owner (100% backward compatile). But this PR allows cw-ownable for defining another storage. So if contract needs another ownership-like store, OwnershipStore can be used.

Example: collection contract need to distince between owner (aka minter) and creator. Here minter is allowed to mint NFTs, whilst creator is able to update collection info like name, symbol, royalties, description, collection pfp etc.
This is planned for upcoming new cw721-base release. So this PR allows contract defining creator like this:

pub const CREATOR: OwnershipStore = OwnershipStore::new("creator");

…singleton. But can be re-use e.g. by defining `CREATOR: OwnershipStore = OwnershipStore::new("creator")`
@taitruong
Copy link
Contributor Author

@larry0x pls have a look at this PR. Imo allows cw-ownable being used for more use cases.

@Malkhedkar-web

This comment was marked as spam.

@PFC-developer
Copy link

hey @larry0x any chance of getting this merged? it's needed for cw-nft's to go back to this version

@taitruong
Copy link
Contributor Author

closing this, since it has been merged by #25

@taitruong taitruong closed this Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants