Skip to content

Commit

Permalink
Merge pull request #152 from arkprotocol/optional_minter
Browse files Browse the repository at this point in the history
#151 make minter optional
  • Loading branch information
shanev committed Jan 19, 2024
2 parents 2bd814b + 49eb912 commit 378ae39
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 32 deletions.
6 changes: 4 additions & 2 deletions contracts/cw2981-royalties/schema/cw2981-royalties.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
"title": "InstantiateMsg",
"type": "object",
"required": [
"minter",
"name",
"symbol"
],
"properties": {
"minter": {
"description": "The minter is the only one who can create new NFTs. This is designed for a base NFT that is controlled by an external program or contract. You will likely replace this with custom logic in custom NFTs",
"type": "string"
"type": [
"string",
"null"
]
},
"name": {
"description": "Name of the NFT contract",
Expand Down
8 changes: 4 additions & 4 deletions contracts/cw2981-royalties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod tests {
let init_msg = InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
minter: CREATOR.to_string(),
minter: None,
withdraw_address: None,
};
entry::instantiate(deps.as_mut(), mock_env(), info.clone(), init_msg).unwrap();
Expand Down Expand Up @@ -170,7 +170,7 @@ mod tests {
let init_msg = InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
minter: CREATOR.to_string(),
minter: None,
withdraw_address: None,
};
entry::instantiate(deps.as_mut(), mock_env(), info.clone(), init_msg).unwrap();
Expand Down Expand Up @@ -201,7 +201,7 @@ mod tests {
let init_msg = InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
minter: CREATOR.to_string(),
minter: None,
withdraw_address: None,
};
entry::instantiate(deps.as_mut(), mock_env(), info.clone(), init_msg).unwrap();
Expand Down Expand Up @@ -242,7 +242,7 @@ mod tests {
let init_msg = InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
minter: CREATOR.to_string(),
minter: None,
withdraw_address: None,
};
entry::instantiate(deps.as_mut(), mock_env(), info.clone(), init_msg).unwrap();
Expand Down
6 changes: 4 additions & 2 deletions contracts/cw721-base/schema/cw721-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
"title": "InstantiateMsg",
"type": "object",
"required": [
"minter",
"name",
"symbol"
],
"properties": {
"minter": {
"description": "The minter is the only one who can create new NFTs. This is designed for a base NFT that is controlled by an external program or contract. You will likely replace this with custom logic in custom NFTs",
"type": "string"
"type": [
"string",
"null"
]
},
"name": {
"description": "Name of the NFT contract",
Expand Down
4 changes: 2 additions & 2 deletions contracts/cw721-base/src/contract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn setup_contract(deps: DepsMut<'_>) -> Cw721Contract<'static, Extension, Empty,
let msg = InstantiateMsg {
name: CONTRACT_NAME.to_string(),
symbol: SYMBOL.to_string(),
minter: String::from(MINTER),
minter: Some(String::from(MINTER)),
withdraw_address: None,
};
let info = mock_info("creator", &[]);
Expand All @@ -41,7 +41,7 @@ fn proper_instantiation() {
let msg = InstantiateMsg {
name: CONTRACT_NAME.to_string(),
symbol: SYMBOL.to_string(),
minter: String::from(MINTER),
minter: Some(String::from(MINTER)),
withdraw_address: Some(String::from(MINTER)),
};
let info = mock_info("creator", &[]);
Expand Down
9 changes: 6 additions & 3 deletions contracts/cw721-base/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
&self,
deps: DepsMut,
_env: Env,
_info: MessageInfo,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response<C>, ContractError> {
let contract_info = ContractInfoResponse {
Expand All @@ -32,10 +32,13 @@ where
};
self.contract_info.save(deps.storage, &contract_info)?;

cw_ownable::initialize_owner(deps.storage, deps.api, Some(&msg.minter))?;
let owner = match msg.minter {
Some(owner) => deps.api.addr_validate(&owner)?,
None => info.sender,
};
cw_ownable::initialize_owner(deps.storage, deps.api, Some(owner.as_ref()))?;

if let Some(address) = msg.withdraw_address {
let owner = deps.api.addr_validate(&msg.minter)?;
self.set_withdraw_address(deps, &owner, address)?;
}

Expand Down
32 changes: 31 additions & 1 deletion contracts/cw721-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ mod tests {
InstantiateMsg {
name: "".into(),
symbol: "".into(),
minter: "larry".into(),
minter: Some("other".into()),
withdraw_address: None,
},
)
.unwrap();

let minter = cw_ownable::get_ownership(deps.as_ref().storage)
.unwrap()
.owner
.map(|a| a.into_string());
assert_eq!(minter, Some("other".to_string()));

let version = cw2::get_contract_version(deps.as_ref().storage).unwrap();
assert_eq!(
version,
Expand All @@ -124,4 +130,28 @@ mod tests {
},
);
}

#[test]
fn proper_owner_initialization() {
let mut deps = mock_dependencies();

entry::instantiate(
deps.as_mut(),
mock_env(),
mock_info("owner", &[]),
InstantiateMsg {
name: "".into(),
symbol: "".into(),
minter: None,
withdraw_address: None,
},
)
.unwrap();

let minter = cw_ownable::get_ownership(deps.as_ref().storage)
.unwrap()
.owner
.map(|a| a.into_string());
assert_eq!(minter, Some("owner".to_string()));
}
}
2 changes: 1 addition & 1 deletion contracts/cw721-base/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct InstantiateMsg {
/// The minter is the only one who can create new NFTs.
/// This is designed for a base NFT that is controlled by an external program
/// or contract. You will likely replace this with custom logic in custom NFTs
pub minter: String,
pub minter: Option<String>,

pub withdraw_address: Option<String>,
}
Expand Down
6 changes: 4 additions & 2 deletions contracts/cw721-expiration/schema/cw721-expiration.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"type": "object",
"required": [
"expiration_days",
"minter",
"name",
"symbol"
],
Expand All @@ -21,7 +20,10 @@
},
"minter": {
"description": "The minter is the only one who can create new NFTs. This is designed for a base NFT that is controlled by an external program or contract. You will likely replace this with custom logic in custom NFTs",
"type": "string"
"type": [
"string",
"null"
]
},
"name": {
"description": "Name of the NFT contract",
Expand Down
4 changes: 2 additions & 2 deletions contracts/cw721-expiration/src/contract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn setup_contract(deps: DepsMut<'_>, expiration_days: u16) -> Cw721ExpirationCon
expiration_days,
name: CONTRACT_NAME.to_string(),
symbol: SYMBOL.to_string(),
minter: String::from(MINTER),
minter: Some(String::from(MINTER)),
withdraw_address: None,
};
let info = mock_info("creator", &[]);
Expand All @@ -47,7 +47,7 @@ fn proper_instantiation() {
expiration_days: 1,
name: CONTRACT_NAME.to_string(),
symbol: SYMBOL.to_string(),
minter: String::from(MINTER),
minter: Some(String::from(MINTER)),
withdraw_address: None,
};
let info = mock_info("creator", &[]);
Expand Down
4 changes: 2 additions & 2 deletions contracts/cw721-expiration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mod tests {
expiration_days: 0,
name: "".into(),
symbol: "".into(),
minter: "mrt".into(),
minter: Some("mrt".into()),
withdraw_address: None,
},
)
Expand All @@ -102,7 +102,7 @@ mod tests {
expiration_days: 1,
name: "".into(),
symbol: "".into(),
minter: "mrt".into(),
minter: Some("mrt".into()),
withdraw_address: None,
},
)
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw721-expiration/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct InstantiateMsg {
/// The minter is the only one who can create new NFTs.
/// This is designed for a base NFT that is controlled by an external program
/// or contract. You will likely replace this with custom logic in custom NFTs
pub minter: String,
pub minter: Option<String>,

pub withdraw_address: Option<String>,
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/cw721-fixed-price/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const INSTANTIATE_TOKEN_REPLY_ID: u64 = 1;
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
env: Env,
_env: Env,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn instantiate(
msg: to_json_binary(&Cw721InstantiateMsg {
name: msg.name.clone(),
symbol: msg.symbol,
minter: env.contract.address.to_string(),
minter: None,
withdraw_address: msg.withdraw_address,
})?,
funds: vec![],
Expand Down Expand Up @@ -228,7 +228,7 @@ mod tests {
msg: to_json_binary(&Cw721InstantiateMsg {
name: msg.name.clone(),
symbol: msg.symbol.clone(),
minter: MOCK_CONTRACT_ADDR.to_string(),
minter: None,
withdraw_address: None,
})
.unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
"title": "InstantiateMsg",
"type": "object",
"required": [
"minter",
"name",
"symbol"
],
"properties": {
"minter": {
"description": "The minter is the only one who can create new NFTs. This is designed for a base NFT that is controlled by an external program or contract. You will likely replace this with custom logic in custom NFTs",
"type": "string"
"type": [
"string",
"null"
]
},
"name": {
"description": "Name of the NFT contract",
Expand Down
4 changes: 2 additions & 2 deletions contracts/cw721-metadata-onchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ mod tests {
InstantiateMsg {
name: "".into(),
symbol: "".into(),
minter: "larry".into(),
minter: None,
withdraw_address: None,
},
)
Expand All @@ -112,7 +112,7 @@ mod tests {
let init_msg = InstantiateMsg {
name: "SpaceShips".to_string(),
symbol: "SPACE".to_string(),
minter: CREATOR.to_string(),
minter: None,
withdraw_address: None,
};
contract
Expand Down
6 changes: 4 additions & 2 deletions contracts/cw721-non-transferable/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"title": "InstantiateMsg",
"type": "object",
"required": [
"minter",
"name",
"symbol"
],
Expand All @@ -15,7 +14,10 @@
]
},
"minter": {
"type": "string"
"type": [
"string",
"null"
]
},
"name": {
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw721-non-transferable/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct InstantiateMsg {
pub admin: Option<String>,
pub name: String,
pub symbol: String,
pub minter: String,
pub minter: Option<String>,
pub withdraw_address: Option<String>,
}

Expand Down

0 comments on commit 378ae39

Please sign in to comment.