Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
jhernandezb committed Jan 25, 2024
1 parent f743824 commit e515627
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 32 deletions.
17 changes: 10 additions & 7 deletions contracts/minters/vending-minter-merkle-wl/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ use sg_std::{StargazeMsgWrapper, GENESIS_MINT_START_TIME, NATIVE_DENOM};
use sg_whitelist::msg::{
ConfigResponse as WhitelistConfigResponse, HasMemberResponse, QueryMsg as WhitelistQueryMsg,
};
use whitelist_mtree::msg::QueryMsg as WhitelistMtreeQueryMsg;
use sha2::{Digest, Sha256};
use shuffle::{fy::FisherYates, shuffler::Shuffler};
use std::convert::TryInto;
use url::Url;
use vending_factory::msg::{ParamsResponse, VendingMinterCreateMsg};
use vending_factory::state::VendingMinterParams;
use whitelist_mtree::msg::QueryMsg as WhitelistMtreeQueryMsg;

pub type Response = cosmwasm_std::Response<StargazeMsgWrapper>;
pub type SubMsg = cosmwasm_std::SubMsg<StargazeMsgWrapper>;
Expand Down Expand Up @@ -489,7 +489,9 @@ pub fn execute_mint_sender(

// If there is no active whitelist right now, check public mint
// Check if after start_time
if is_public_mint(deps.as_ref(), &info, proof_hashes)? && (env.block.time < config.extension.start_time) {
if is_public_mint(deps.as_ref(), &info, proof_hashes)?
&& (env.block.time < config.extension.start_time)
{
return Err(ContractError::BeforeMintStartTime {});
}

Expand All @@ -504,7 +506,11 @@ pub fn execute_mint_sender(

// Check if a whitelist exists and not ended
// Sender has to be whitelisted to mint
fn is_public_mint(deps: Deps, info: &MessageInfo, proof_hashes: Option<Vec<String>>) -> Result<bool, ContractError> {
fn is_public_mint(
deps: Deps,
info: &MessageInfo,
proof_hashes: Option<Vec<String>>,
) -> Result<bool, ContractError> {
let config = CONFIG.load(deps.storage)?;

// If there is no whitelist, there's only a public mint
Expand Down Expand Up @@ -554,13 +560,10 @@ fn is_public_mint(deps: Deps, info: &MessageInfo, proof_hashes: Option<Vec<Strin
Ok(false)
}


fn is_merkle_tree_wl(wl_config_res: &WhitelistConfigResponse) -> bool {
wl_config_res.member_limit == 0 &&
wl_config_res.num_members == 0
wl_config_res.member_limit == 0 && wl_config_res.num_members == 0
}


pub fn execute_mint_to(
deps: DepsMut,
env: Env,
Expand Down
2 changes: 1 addition & 1 deletion contracts/minters/vending-minter-merkle-wl/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct InstantiateMsg {
#[cw_serde]
pub enum ExecuteMsg {
Mint {
proof_hashes: Option<Vec<String>>
proof_hashes: Option<Vec<String>>,
},
SetWhitelist {
whitelist: String,
Expand Down
4 changes: 2 additions & 2 deletions contracts/whitelists/whitelist-merkletree/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod interface;
pub mod validators;
pub mod crypto;
pub mod interface;
pub mod utils;
pub mod validators;
16 changes: 11 additions & 5 deletions contracts/whitelists/whitelist-merkletree/src/helpers/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
use cosmwasm_std::{HexBinary, StdResult, StdError};
use cosmwasm_std::{HexBinary, StdError, StdResult};

pub fn valid_hash_string(hash_string: &String) -> StdResult<()> {
let hex_res = HexBinary::from_hex(hash_string.as_str());
if hex_res.is_err() {
return Err(cosmwasm_std::StdError::InvalidHex { msg: hash_string.to_string() });
return Err(cosmwasm_std::StdError::InvalidHex {
msg: hash_string.to_string(),
});
}

let hex_binary = hex_res.unwrap();

let decoded = hex_binary.to_array::<32>();

if decoded.is_err() {
return Err(cosmwasm_std::StdError::InvalidDataSize { expected: 32, actual: hex_binary.len() as u64 })
return Err(cosmwasm_std::StdError::InvalidDataSize {
expected: 32,
actual: hex_binary.len() as u64,
});
}
Ok(())
}
Expand All @@ -22,7 +27,8 @@ pub fn verify_merkle_root(merkle_root: &String) -> StdResult<()> {

pub fn string_to_byte_slice(string: &String) -> StdResult<[u8; 32]> {
let mut byte_slice = [0; 32];
hex::decode_to_slice(string, &mut byte_slice)
.map_err(|_| StdError::GenericErr { msg: "Couldn't decode hash string".to_string() })?;
hex::decode_to_slice(string, &mut byte_slice).map_err(|_| StdError::GenericErr {
msg: "Couldn't decode hash string".to_string(),
})?;
Ok(byte_slice)
}
12 changes: 5 additions & 7 deletions contracts/whitelists/whitelist-merkletree/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub struct InstantiateMsg {
pub admins_mutable: bool,
}


#[cw_serde]
pub enum ExecuteMsg {
UpdateStartTime(Timestamp),
Expand Down Expand Up @@ -56,7 +55,10 @@ pub enum QueryMsg {
#[returns(IsActiveResponse)]
IsActive {},
#[returns(HasMemberResponse)]
HasMember { member: String, proof_hashes: Vec<String> },
HasMember {
member: String,
proof_hashes: Vec<String>,
},
#[returns(ConfigResponse)]
Config {},
#[returns(AdminListResponse)]
Expand All @@ -69,16 +71,14 @@ pub enum QueryMsg {
#[returns(MerkleRootResponse)]
MerkleRoot {},
#[returns(MerkleTreeURIResponse)]
MerkleTreeURI {}
MerkleTreeURI {},
}


#[cw_serde]
pub struct HasMemberResponse {
pub has_member: bool,
}


#[cw_serde]
pub struct HasEndedResponse {
pub has_ended: bool,
Expand All @@ -99,7 +99,6 @@ pub struct MintPriceResponse {
pub mint_price: Coin,
}


#[cw_serde]
pub struct ConfigResponse {
pub num_members: u32,
Expand All @@ -111,7 +110,6 @@ pub struct ConfigResponse {
pub is_active: bool,
}


#[cw_serde]
pub struct MerkleRootResponse {
pub merkle_root: String,
Expand Down
4 changes: 2 additions & 2 deletions contracts/whitelists/whitelist-merkletree/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod unit_tests;
pub mod hasher;
pub mod test_helpers;
pub mod hasher;
pub mod unit_tests;
2 changes: 1 addition & 1 deletion test-suite/src/common_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ pub mod helpers;
pub mod msg;
pub mod setup_accounts_and_block;
pub mod setup_collection_whitelist;
pub mod setup_whitelist_merkletree;
pub mod setup_minter;
pub mod setup_whitelist_merkletree;
pub mod templates;
3 changes: 1 addition & 2 deletions test-suite/src/common_setup/contract_boxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub fn contract_collection_whitelist() -> Box<dyn Contract<StargazeMsgWrapper>>
Box::new(contract)
}


pub fn contract_open_edition_minter() -> Box<dyn Contract<StargazeMsgWrapper>> {
let contract = ContractWrapper::new(
open_edition_minter::contract::execute,
Expand Down Expand Up @@ -148,4 +147,4 @@ pub fn contract_whitelist_merkletree() -> Box<dyn Contract<StargazeMsgWrapper>>
whitelist_mtree::contract::query,
);
Box::new(contract)
}
}
5 changes: 2 additions & 3 deletions test-suite/src/common_setup/setup_whitelist_merkletree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn setup_whitelist_mtree_contract(
creator: &Addr,
whitelist_code_id: Option<u64>,
denom: Option<&str>,
merkle_root: String
merkle_root: String,
) -> Addr {
let whitelist_code_id = match whitelist_code_id {
Some(value) => value,
Expand All @@ -25,7 +25,6 @@ pub fn setup_whitelist_mtree_contract(
None => NATIVE_DENOM,
};


let msg = WhitelistInstantiateMsg {
start_time: Timestamp::from_nanos(GENESIS_MINT_START_TIME + 100),
end_time: Timestamp::from_nanos(GENESIS_MINT_START_TIME + 10_000_000),
Expand All @@ -34,7 +33,7 @@ pub fn setup_whitelist_mtree_contract(
admins: vec![creator.to_string()],
admins_mutable: true,
merkle_root,
merkle_tree_uri: None
merkle_tree_uri: None,
};
router
.instantiate_contract(
Expand Down
2 changes: 1 addition & 1 deletion test-suite/src/whitelist_merkletree.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod tests;
mod tests;
2 changes: 1 addition & 1 deletion test-suite/src/whitelist_merkletree/tests.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod integration_tests;
mod integration_tests;

0 comments on commit e515627

Please sign in to comment.