Skip to content

Commit

Permalink
Merge pull request #74 from public-awesome/assoc-addy
Browse files Browse the repository at this point in the history
Optionally associate name with address / token_uri
  • Loading branch information
shanev authored Oct 16, 2022
2 parents 4676fa3 + 76e58b0 commit 16cff5c
Show file tree
Hide file tree
Showing 26 changed files with 521 additions and 277 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/marketplace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "name-marketplace"
version = "0.8.0"
version = "0.9.0"
authors = ["Shane Vitarana <s@noreply.publicawesome.com>"]
edition = "2021"
repository = "https://github.com/public-awesome/names"
Expand Down
2 changes: 1 addition & 1 deletion contracts/marketplace/schema/name-marketplace.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "name-marketplace",
"contract_version": "0.8.0",
"contract_version": "0.9.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
2 changes: 1 addition & 1 deletion contracts/name-minter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "name-minter"
version = "0.8.0"
version = "0.9.0"
authors = ["Shane Vitarana <s@noreply.publicawesome.com>"]
edition = "2021"

Expand Down
10 changes: 2 additions & 8 deletions contracts/name-minter/schema/name-minter.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "name-minter",
"contract_version": "0.8.0",
"contract_version": "0.9.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down Expand Up @@ -100,7 +100,7 @@
"additionalProperties": false
},
{
"description": "Mint a name for the sender or contract addresss If `contract` is given, name is minted for that contract address",
"description": "Mint a name and list on Stargaze Name Marketplace",
"type": "object",
"required": [
"mint_and_list"
Expand All @@ -112,12 +112,6 @@
"name"
],
"properties": {
"contract": {
"type": [
"string",
"null"
]
},
"name": {
"type": "string"
}
Expand Down
33 changes: 3 additions & 30 deletions contracts/name-minter/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
coin, to_binary, Addr, Coin, ContractInfoResponse, Deps, DepsMut, Env, MessageInfo, Reply,
SubMsg, WasmMsg,
coin, to_binary, Addr, Coin, DepsMut, Env, MessageInfo, Reply, SubMsg, WasmMsg,
};
use cw2::set_contract_version;
use cw721_base::MintMsg;
Expand Down Expand Up @@ -93,9 +92,7 @@ pub fn execute(
ExecuteMsg::UpdateWhitelist { whitelist } => {
execute_update_whitelsit(deps, info, whitelist)
}
ExecuteMsg::MintAndList { name, contract } => {
execute_mint_and_list(deps, info, name.trim(), contract)
}
ExecuteMsg::MintAndList { name } => execute_mint_and_list(deps, info, name.trim()),
}
}

Expand All @@ -116,7 +113,6 @@ pub fn execute_mint_and_list(
deps: DepsMut,
info: MessageInfo,
name: &str,
contract: Option<String>,
) -> Result<Response, ContractError> {
let sender = &info.sender.to_string();
let mut res = Response::new();
Expand All @@ -136,7 +132,6 @@ pub fn execute_mint_and_list(
}

validate_name(name, params.min_name_length, params.max_name_length)?;
validate_contract(deps.as_ref(), &info, &contract)?;

let price = validate_payment(name.len(), &info, params.base_price)?;
let community_pool_msg = create_fund_community_pool_msg(vec![price]);
Expand All @@ -147,7 +142,7 @@ pub fn execute_mint_and_list(
let msg = Sg721ExecuteMsg::Mint(MintMsg::<Metadata> {
token_id: name.to_string(),
owner: sender.to_string(),
token_uri: Some(contract.unwrap_or_else(|| sender.to_string())),
token_uri: None,
extension: Metadata {
bio: None,
profile_nft: None,
Expand Down Expand Up @@ -225,28 +220,6 @@ fn validate_payment(
Ok(coin(amount, NATIVE_DENOM))
}

/// Validate if the contract creator or admin is the sender
fn validate_contract(
deps: Deps,
info: &MessageInfo,
contract_addr: &Option<String>,
) -> Result<(), ContractError> {
let sender = &info.sender;

if let Some(contract) = contract_addr {
let res: ContractInfoResponse = deps.querier.query_wasm_contract_info(contract)?;
let admin = res.admin;
let creator = res.creator;

// If the sender is not the admin or creator, return an error
if admin.map_or(true, |a| &a != sender) && &creator != sender {
return Err(ContractError::UnauthorizedCreatorOrAdmin {});
}
}

Ok(())
}

fn invalid_char(c: char) -> bool {
let is_valid = c.is_digit(10) || c.is_ascii_lowercase() || (c == '-');
!is_valid
Expand Down
3 changes: 0 additions & 3 deletions contracts/name-minter/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ pub enum ContractError {
#[error("Name Minter: Unauthorized")]
Unauthorized {},

#[error("Unauthorized: Not contract creator or admin")]
UnauthorizedCreatorOrAdmin {},

#[error("Invalid reply ID")]
InvalidReplyID {},

Expand Down
Loading

0 comments on commit 16cff5c

Please sign in to comment.