Skip to content

Commit

Permalink
zero funds check in mint
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtyshab committed May 30, 2024
1 parent a6f965a commit 1283a29
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions cw-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,17 @@ pub fn execute_mint(
} else {
return Err(ContractError::InvalidFundsReceived {});
};
let send_msg: CosmosMsg = BankMsg::Send {
to_address: relayer_associated_addr.to_string(),
amount: vec![coin(mint_fund_amount, SUPPORTED_DENOM)],
}
.into();
let send_msg: Option<CosmosMsg> = if mint_fund_amount > 0 {
Some(
BankMsg::Send {
to_address: relayer_associated_addr.to_string(),
amount: vec![coin(mint_fund_amount, SUPPORTED_DENOM)],
}
.into(),
)
} else {
None
};

let mint_attempt = MintAttempt::new(deps, recipient.to_string(), quantity, mint_fund_amount)?;
let mint_approval_msg = wasm_execute(
Expand All @@ -125,14 +131,17 @@ pub fn execute_mint(
)?
.into();

Ok(Response::new()
.add_messages(vec![send_msg, mint_approval_msg])
.add_attributes(vec![
("action", "mint"),
("recipient", &recipient),
("quantity", &quantity.to_string()),
("funds", &mint_fund_amount.to_string()),
]))
let mut msgs = vec![mint_approval_msg];
if let Some(send_msg) = send_msg {
msgs.push(send_msg);
}

Ok(Response::new().add_messages(msgs).add_attributes(vec![
("action", "mint"),
("recipient", &recipient),
("quantity", &quantity.to_string()),
("funds", &mint_fund_amount.to_string()),
]))
}

#[entry_point]
Expand Down

0 comments on commit 1283a29

Please sign in to comment.