Skip to content

Commit

Permalink
fix zero payments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjatosba committed Feb 17, 2024
1 parent 10fa4cb commit afb2b0f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
25 changes: 14 additions & 11 deletions contracts/minters/minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cosmwasm_std::{
to_json_binary, Addr, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, Order,
Response, StdResult, Uint128, WasmMsg,
};
use cw_utils::{maybe_addr, must_pay, nonpayable};
use cw_utils::{may_pay, maybe_addr, must_pay, nonpayable};
use minter_types::{generate_mint_message, CollectionDetails};
use omniflix_minter_factory::msg::QueryMsg::Params as QueryFactoryParams;
use omniflix_minter_factory::msg::{CreateMinterMsg, ParamsResponse};
Expand Down Expand Up @@ -338,7 +338,7 @@ pub fn execute_mint(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Respon
MINTED_TOKENS.save(deps.storage, info.sender.clone(), &user_details)?;

// Check the payment
let amount = must_pay(&info, &mint_price.denom)?;
let amount = may_pay(&info, &mint_price.denom)?;
// Exact amount must be paid
if amount != mint_price.amount {
return Err(ContractError::IncorrectPaymentAmount {
Expand Down Expand Up @@ -371,17 +371,20 @@ pub fn execute_mint(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Respon
)
.into();

// Create the Bank send message
let bank_msg: CosmosMsg = CosmosMsg::Bank(cosmwasm_std::BankMsg::Send {
to_address: payment_collector.into_string(),
amount: vec![Coin {
denom: mint_price.denom,
amount: mint_price.amount,
}],
});
if !mint_price.amount.is_zero() {
// Create the Bank send message
let bank_msg: CosmosMsg = CosmosMsg::Bank(cosmwasm_std::BankMsg::Send {
to_address: payment_collector.into_string(),
amount: vec![Coin {
denom: mint_price.denom,
amount: mint_price.amount,
}],
});

messages.push(bank_msg.clone());
}

messages.push(mint_msg.clone());
messages.push(bank_msg.clone());

let res = Response::new()
.add_messages(messages)
Expand Down
24 changes: 13 additions & 11 deletions contracts/minters/multi-mint-oem/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cosmwasm_std::{
to_json_binary, Addr, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo,
Response, StdResult, Timestamp, Uint128, WasmMsg,
};
use cw_utils::{maybe_addr, must_pay, nonpayable};
use cw_utils::{may_pay, maybe_addr, must_pay, nonpayable};
use minter_types::{generate_mint_message, CollectionDetails, Config, Token, UserDetails};
use multi_mint_open_edition_minter_types::QueryMsg;
use pauser::PauseState;
Expand Down Expand Up @@ -382,7 +382,8 @@ pub fn execute_mint(
minted_tokens.save(deps.storage, drop_id, info.sender.clone(), &user_details);

// Check the payment
let amount = must_pay(&info, &mint_price.denom)?;
// Can be set to zero so use may_pay
let amount = may_pay(&info, &mint_price.denom)?;
// Exact amount must be paid
if amount != mint_price.amount {
return Err(ContractError::IncorrectPaymentAmount {
Expand All @@ -408,17 +409,18 @@ pub fn execute_mint(
)
.into();

// Create the Bank send message
let bank_msg: CosmosMsg = CosmosMsg::Bank(cosmwasm_std::BankMsg::Send {
to_address: payment_collector.into_string(),
amount: vec![Coin {
denom: mint_price.denom,
amount: mint_price.amount,
}],
});
if !mint_price.amount.is_zero() {
let bank_msg: CosmosMsg = CosmosMsg::Bank(cosmwasm_std::BankMsg::Send {
to_address: payment_collector.into_string(),
amount: vec![Coin {
denom: mint_price.denom,
amount: mint_price.amount,
}],
});
messages.push(bank_msg.clone());
}

messages.push(mint_msg.clone());
messages.push(bank_msg.clone());

let res = Response::new()
.add_messages(messages)
Expand Down
23 changes: 12 additions & 11 deletions contracts/minters/open-edition-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cosmwasm_std::{
to_json_binary, Addr, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo,
Response, StdResult, Uint128, WasmMsg,
};
use cw_utils::{maybe_addr, must_pay, nonpayable};
use cw_utils::{may_pay, maybe_addr, must_pay, nonpayable};
use minter_types::{generate_mint_message, CollectionDetails, Config, Token, UserDetails};
use open_edition_minter_types::QueryMsg;
use pauser::PauseState;
Expand Down Expand Up @@ -316,7 +316,7 @@ pub fn execute_mint(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Respon
}

// Check the payment
let amount = must_pay(&info, &mint_price.denom)?;
let amount = may_pay(&info, &mint_price.denom)?;
// Exact amount must be paid
if amount != mint_price.amount {
return Err(ContractError::IncorrectPaymentAmount {
Expand Down Expand Up @@ -349,16 +349,17 @@ pub fn execute_mint(deps: DepsMut, env: Env, info: MessageInfo) -> Result<Respon
.into();

// Create the Bank send message
let bank_msg: CosmosMsg = CosmosMsg::Bank(cosmwasm_std::BankMsg::Send {
to_address: payment_collector.into_string(),
amount: vec![Coin {
denom: mint_price.denom,
amount: mint_price.amount,
}],
});

if !mint_price.amount.is_zero() {
let bank_msg: CosmosMsg = CosmosMsg::Bank(cosmwasm_std::BankMsg::Send {
to_address: payment_collector.into_string(),
amount: vec![Coin {
denom: mint_price.denom,
amount: mint_price.amount,
}],
});
messages.push(bank_msg.clone());
}
messages.push(mint_msg.clone());
messages.push(bank_msg.clone());

let res = Response::new()
.add_messages(messages)
Expand Down

0 comments on commit afb2b0f

Please sign in to comment.