diff --git a/contracts/cw721-template/Cargo.toml b/contracts/cw721-template/Cargo.toml index f5573a4d1..810881315 100644 --- a/contracts/cw721-template/Cargo.toml +++ b/contracts/cw721-template/Cargo.toml @@ -25,3 +25,4 @@ cw721 = "0.17.0" cw721-base = { version = "0.17.0", features = ["library"] } schemars = "0.8.11" serde = { version = "1.0.152", default-features = false, features = ["derive"] } +thiserror = "1.0.30" diff --git a/contracts/cw721-template/README.md b/contracts/cw721-template/README.md index 88a1934b6..f614e3255 100644 --- a/contracts/cw721-template/README.md +++ b/contracts/cw721-template/README.md @@ -26,12 +26,6 @@ Go to the folder in which you want to place it and run: cargo generate --git https://github.com/CosmWasm/cw-nfts.git --name PROJECT_NAME ``` -For cloning a minimal NFT contract without example code for extensions: - -```sh -cargo generate --git https://github.com/CosmWasm/cw-nfts.git --name PROJECT_NAME -d minimal=true -``` - **Older Versions** Pass version as branch flag: diff --git a/contracts/cw721-template/cargo-generate.toml b/contracts/cw721-template/cargo-generate.toml index 2dfcf91d1..51bf25720 100644 --- a/contracts/cw721-template/cargo-generate.toml +++ b/contracts/cw721-template/cargo-generate.toml @@ -3,9 +3,3 @@ # This is needed when files contains curly brackets as in `v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}`. # The files will be copied 1:1 to the target project. To avoid shipping them completely add them to `.genignore`. exclude = ["test_generate.sh", "cargo-generate.toml"] - -[placeholders.minimal] -type = "bool" -prompt = """The full template includes more example code on how to extend a basic cw721 contract. This is useful -if you are new to writing CosmWasm NFT contracts. Would you like the minimal template instead?""" -default = false diff --git a/contracts/cw721-template/src/lib.rs b/contracts/cw721-template/src/lib.rs index c931e2939..06633406d 100644 --- a/contracts/cw721-template/src/lib.rs +++ b/contracts/cw721-template/src/lib.rs @@ -1,15 +1,13 @@ -{% unless minimal %}use cosmwasm_schema::cw_serde; -{% endunless %}use cosmwasm_std::{% unless minimal %}{CustomMsg, {% endunless %}Empty{% unless minimal %}}{% endunless %}; -pub use cw721_base::{ContractError, InstantiateMsg, MinterResponse}; +use cosmwasm_schema::cw_serde; +use cosmwasm_std::{CustomMsg, Empty, StdError}; +pub use cw721_base::{InstantiateMsg, MinterResponse}; +use thiserror::Error; // Version info for migration const CONTRACT_NAME: &str = "crates.io:{{project-name}}"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); -{% if minimal %}pub type Cw721Contract<'a> = cw721_base::Cw721Contract<'a, Empty, Empty, Empty, Empty>; - -pub type ExecuteMsg = cw721_base::ExecuteMsg; -pub type QueryMsg = cw721_base::QueryMsg;{% else %}// Implements extended on-chain metadata, by default cw721 NFTs only store a +// Implements extended on-chain metadata, by default cw721 NFTs only store a // token_uri, which is a URL to off-chain metadata (same as ERC721). #[cw_serde] #[derive(Default)] @@ -41,7 +39,18 @@ pub type ExecuteMsg = cw721_base::ExecuteMsg; // The query message type for this contract. // If you don't need the QueryExt extension, you can use the // `Empty` type. -pub type QueryMsg = cw721_base::QueryMsg;{% endif %} +pub type QueryMsg = cw721_base::QueryMsg; + +/// Custom errors for this contract, add additional errors here. +#[derive(Error, Debug, PartialEq)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + /// This inherits from cw721-base::ContractError to handle the base contract errors + #[error("{0}")] + Cw721Error(#[from] cw721_base::ContractError), +} #[cfg(not(feature = "library"))] pub mod entry { @@ -71,8 +80,7 @@ pub mod entry { info: MessageInfo, msg: ExecuteMsg, ) -> Result { - {% if minimal %}// Use the default cw721-base implementation - Cw721Contract::default().execute(deps, env, info, msg){% else %}match msg { + match msg { // Optionally override the default cw721-base behavior // ExecuteMsg::Burn { token_id } => unimplemented!(), @@ -83,14 +91,15 @@ pub mod entry { }, // Use the default cw721-base implementation - _ => Cw721Contract::default().execute(deps, env, info, msg), - }{% endif %} + _ => Cw721Contract::default() + .execute(deps, env, info, msg) + .map_err(Into::into), + } } #[entry_point] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { - {% if minimal %}// Use default cw721-base query implementation - Cw721Contract::default().query(deps, env, msg){% else %}match msg { + match msg { // Optionally override a default cw721-base query // QueryMsg::Minter {} => unimplemented!(), QueryMsg::Extension { msg } => match msg { @@ -99,7 +108,7 @@ pub mod entry { // Use default cw721-base query implementation _ => Cw721Contract::default().query(deps, env, msg), - }{% endif %} + } } }