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

Validate denom and URL #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
98 changes: 87 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions contracts/cw721-piggy-bank/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ 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"
url = "2.2.2"
cw-denom = "2.0.2"
15 changes: 9 additions & 6 deletions contracts/cw721-piggy-bank/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::fmt::format;

use cosmwasm_std::{
entry_point, to_binary, BankMsg, Binary, Coin, Deps, DepsMut, Env, MessageInfo, Response,
StdError, StdResult, Uint128,
};
use cw_denom::UncheckedDenom;
pub use cw721_base::{
ContractError as BaseContractError, InstantiateMsg as BaseInstantiateMsg, MinterResponse,
};
use cw_utils::must_pay;
use url::Url;

use crate::{
msg::{Cw721Contract, ExecuteExt, ExecuteMsg, InstantiateMsg, MetadataExt, QueryExt, QueryMsg},
Expand All @@ -32,11 +32,14 @@ pub fn instantiate(
) -> StdResult<Response> {
cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

// TODO Validate denoms are formated correctly

// Validate denoms are formatted correctly
let unchecked_denom = UncheckedDenom::Native(msg.deposit_denom.clone());
let checked_denom = unchecked_denom.into_checked(deps.as_ref()).map_err(|_| StdError::generic_err("Invalid deposit denom"))?;

// Save config info
DEPOSIT_DENOM.save(deps.storage, &msg.deposit_denom)?;
// TODO validate base_url is a real url
DEPOSIT_DENOM.save(deps.storage, &checked_denom.to_string())?;
// validate base_url is a real url
Url::parse(&msg.base_url).map_err(|_| StdError::generic_err("Invalid base URL"))?;
BASE_URL.save(deps.storage, &msg.base_url)?;
MINT_PRICE.save(deps.storage, &msg.mint_price)?;
if let Some(max_nft_supply) = msg.max_nft_supply {
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw721-piggy-bank/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Coin, CustomMsg, Empty, Uint128};
use cosmwasm_std::{Coin, CustomMsg, Empty};

// 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).
Expand Down