# CW Ownable
Utility for controlling ownership of [CosmWasm](https://github.com/CosmWasm/cosmwasm) smart contracts.
## How to use
Initialize the owner during instantiation using the `initialize_owner` method provided by this crate:
```rust
use cosmwasm_std::{entry_point, DepsMut, Env, MessageInfo, Response};
use abstract_std::objects::ownership::OwnershipError;
#[entry_point]
pub fn instantiate(
deps: DepsMut,
env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response<Empty>, OwnershipError> {
cw_gov_ownable::initialize_owner(deps.storage, deps.api, msg.owner.as_deref())?;
Ok(Response::new())
}
```
Insert a new variant, `UpdateOwnership` to the ExecuteMsg enum:
```rust
#[cw_serde]
enum ExecuteMsg {
UpdateOwnership(cw_gov_ownable::Action),
Foo {},
Bar {},
}
```
Where `Action` can be one of three:
- Propose to transfer the contract's ownership to another account
- Accept the proposed ownership transfer
- Renounce the ownership, permanently setting the contract's owner to vacant
Handle the messages using the `update_ownership` function provided by this crate:
```rust
use cosmwasm_std::{entry_point, DepsMut, Env, MessageInfo, Response};
use abstract_std::objects::ownership::{update_ownership, OwnershipError};
#[entry_point]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, OwnershipError> {
match msg {
ExecuteMsg::UpdateOwnership(action) => {
update_ownership(deps, &env.block, &info.sender, action)?;
}
_ => unimplemneted!(),
}
Ok(Response::new())
}
```
Insert a new variant to the QueryMsg, `Ownership`:
```rust
#[cw_serde]
#[derive(QueryResponses)]
enum QueryMsg {
#[returns(Ownership<String>)]
Ownership {},
#[returns(FooResponse)]
Foo {},
#[returns(BarResponse)]
Bar {},
}
```
Handle the message using the `get_ownership` function provided by this module:
```rust
use cosmwasm_std::{entry_point, Deps, Env, Binary};
use abstract_std::objects::ownership::get_ownership;
#[entry_point]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Ownership {} => to_binary(&get_ownership(deps.storage)?),
_ => unimplemented!(),
}
}
```
## Edge cases
### NFT governance type
In case NFT contract does not return owner of `owner_of`, ownership will act as renounced. For example NFT got burned or something happened with NFT contract.
## License
Contents of this crate at or prior to version `0.5.0` are published under [GNU Affero General Public License v3](https://github.com/steak-enjoyers/cw-plus-plus/blob/9c8fcf1c95b74dd415caf5602068c558e9d16ecc/LICENSE) or later; contents after the said version are published under [Apache-2.0](../../LICENSE) license.