fn validate_fee_params_get_messages(
    api: &dyn Api,
    info: &MessageInfo,
    config: &State,
) -> Result<FeeChargeResponse, ContractError> {
    // Determine if any funds sent are not of the correct denom
    let invalid_funds = info
        .funds
        .iter()
        .filter(|coin| coin.denom != FEE_DENOMINATION)
        .map(|coin| coin.denom.clone())
        .collect::<Vec<String>>();

    // If any funds are found that do not match the fee denom, exit prematurely to prevent
    // contract from siphoning random funds for no reason
    if !invalid_funds.is_empty() {
        return ContractError::InvalidFundsProvided {
            types: invalid_funds,
        }
        .to_result();
    }

    let nhash_fee_amount = fee_amount_from_string(&config.fee_amount)?;

    // Pull the nhash sent by verifying that only one fund sent is of the nhash variety
    let nhash_sent = match info
        .clone()
        .funds
        .into_iter()
        .find(|coin| coin.denom == FEE_DENOMINATION)
    {
        Some(coin) => coin.amount,
        None => {
            // If fees are required, then a coin of type FEE_DENOMINATION should be sent and the
            // absence of one is an error.  Otherwise, treat omission as purposeful definition of
            // zero money fronted for a fee
            if nhash_fee_amount > 0 {
                return ContractError::NoFundsProvidedForRegistration.to_result();
            } else {
                Uint128::zero()
            }
        }
    };

    // If the amount provided is too low, reject the request because the fee cannot be paid
    if nhash_sent.u128() < nhash_fee_amount {
        return ContractError::InsufficientFundsProvided {
            amount_provided: nhash_sent.u128(),
            amount_required: nhash_fee_amount,
        }
        .to_result();
    }

    // Pull the fee amount from the sender for name registration
    let fee_charge_message = if nhash_fee_amount > 0 {
        Some(CosmosMsg::Bank(BankMsg::Send {
            // The fee collection address is validated on contract instantiation, so there's no need to
            // define custom error messages here
            to_address: api.addr_validate(&config.fee_collection_address)?.into(),
            // The same goes for the fee_amount - it is guaranteed to pass this check
            amount: vec![coin(nhash_fee_amount, FEE_DENOMINATION)],
        }))
    } else {
        None
    };

    // The refund amount is == the total nhash sent - fee charged
    let fee_refund_amount = nhash_sent.u128() - nhash_fee_amount;

    // If more than the fee amount is sent, then respond with an additional message that sends the
    // excess back into the sender's account
    let fee_refund_message = if fee_refund_amount > 0 {
        Some(CosmosMsg::Bank(BankMsg::Send {
            to_address: info.sender.clone().into(),
            amount: vec![coin(fee_refund_amount, FEE_DENOMINATION)],
        }))
    } else {
        None
    };

    Ok(FeeChargeResponse {
        fee_charge_message,
        fee_refund_message,
        fee_refund_amount,
    })
}
/// Verifies that funds provided are correct and enough for a fee charge, and then constructs
/// provenance messages that will provide the correct output during the name registration process.
///
/// The validation performed is:
/// - Ensure no funds provided are of an incorrect denomination.
/// - Ensure that the provided funds sent are >= the fee charge for transactions
/// - Ensure that, if more funds are provided than are needed by for the fee, that the excess is caught and refunded
///
/// Returns:
/// - 1: The message to allocate provided funds to the fee collection account (None if the fee collection amount is instantiated as zero with the contract)
/// - 2: The message to refund the sender with any excess fees (None if the funds provided are exactly equal to the amount of fee required)
/// - 3: The amount refunded.  Will be zero if the perfect fund amount if sent.
/// - Various errors if funds provided are not enough or incorrectly formatted
Verifies that funds provided are correct and enough for a fee charge, and then constructs
provenance messages that will provide the correct output during the name registration process.

The validation performed is:
Ensure no funds provided are of an incorrect denomination.
Ensure that the provided funds sent are >= the fee charge for transactions
Ensure that, if more funds are provided than are needed by for the fee, that the excess is caught and refunded

The message to allocate provided funds to the fee collection account (None if the fee collection amount is instantiated as zero with the contract)
2: The message to refund the sender with any excess fees (None if the funds provided are exactly equal to the amount of fee required)
3: The amount refunded.  Will be zero if the perfect fund amount if sent.
Various errors if funds provided are not enough or incorrectly formatted
Verifies that funds provided are correct and enough for a fee charge and then constructs provenance messages that will provide the correct output during the name registration process . The validation performed is : Ensure no funds provided are of an incorrect denomination . Ensure that the provided funds sent are > = the fee charge for transactions Ensure that if more funds are provided than are needed by for the fee that the excess is caught and refunded The message to allocate provided funds to the fee collection account ( None if the fee collection amount is instantiated as zero with the contract ) 2 : The message to refund the sender with any excess fees ( None if the funds provided are exactly equal to the amount of fee required ) 3 : The amount refunded . Will be zero if the perfect fund amount if sent . Various errors if funds provided are not enough or incorrectly formatted
fn validate_fee_params_get_messages(
    api: &dyn Api,
    info: &MessageInfo,
    config: &State,
) -> Result<FeeChargeResponse, ContractError> {
    // Determine if any funds sent are not of the correct denom
    let invalid_funds = info
        .funds
        .iter()
        .filter(|coin| coin.denom != FEE_DENOMINATION)
        .map(|coin| coin.denom.clone())
        .collect::<Vec<String>>();
    // If any funds are found that do not match the fee denom, exit prematurely to prevent
    // contract from siphoning random funds for no reason
    if !invalid_funds.is_empty() {
        return ContractError::InvalidFundsProvided {
            types: invalid_funds,
        }
        .to_result();
    }
    let nhash_fee_amount = fee_amount_from_string(&config.fee_amount)?;
    // Pull the nhash sent by verifying that only one fund sent is of the nhash variety
    let nhash_sent = match info
        .clone()
        .funds
        .into_iter()
        .find(|coin| coin.denom == FEE_DENOMINATION)
    {
        Some(coin) => coin.amount,
        None => {
            // If fees are required, then a coin of type FEE_DENOMINATION should be sent and the
            // absence of one is an error.  Otherwise, treat omission as purposeful definition of
            // zero money fronted for a fee
            if nhash_fee_amount > 0 {
                return ContractError::NoFundsProvidedForRegistration.to_result();
            } else {
                Uint128::zero()
            }
        }
    };
    // If the amount provided is too low, reject the request because the fee cannot be paid
    if nhash_sent.u128() < nhash_fee_amount {
        return ContractError::InsufficientFundsProvided {
            amount_provided: nhash_sent.u128(),
            amount_required: nhash_fee_amount,
        }
        .to_result();
    }
    // Pull the fee amount from the sender for name registration
    let fee_charge_message = if nhash_fee_amount > 0 {
        Some(CosmosMsg::Bank(BankMsg::Send {
            // The fee collection address is validated on contract instantiation, so there's no need to
            // define custom error messages here
            to_address: api.addr_validate(&config.fee_collection_address)?.into(),
            // The same goes for the fee_amount - it is guaranteed to pass this check
            amount: vec![coin(nhash_fee_amount, FEE_DENOMINATION)],
        }))
    } else {
        None
    };
    // The refund amount is == the total nhash sent - fee charged
    let fee_refund_amount = nhash_sent.u128() - nhash_fee_amount;
    // If more than the fee amount is sent, then respond with an additional message that sends the
    // excess back into the sender's account
    let fee_refund_message = if fee_refund_amount > 0 {
        Some(CosmosMsg::Bank(BankMsg::Send {
            to_address: info.sender.clone().into(),
            amount: vec![coin(fee_refund_amount, FEE_DENOMINATION)],
        }))
    } else {
        None
    };
    Ok(FeeChargeResponse {
        fee_charge_message,
        fee_refund_message,
        fee_refund_amount,
    })
}
fn validate_fee_params_get_messages ( api : & dyn Api , info : & MessageInfo , config : & State , ) -> Result < FeeChargeResponse , ContractError > { // Determine if any funds sent are not of the correct denom let invalid_funds = info . funds . iter ( ) . filter ( | coin | coin . denom != FEE_DENOMINATION ) . map ( | coin | coin . denom . clone ( ) ) . collect :: < Vec < String > > ( ) ; // If any funds are found that do not match the fee denom, exit prematurely to prevent // contract from siphoning random funds for no reason if ! invalid_funds . is_empty ( ) { return ContractError :: InvalidFundsProvided { types : invalid_funds , } . to_result ( ) ; } let nhash_fee_amount = fee_amount_from_string ( & config . fee_amount ) ? ; // Pull the nhash sent by verifying that only one fund sent is of the nhash variety let nhash_sent = match info . clone ( ) . funds . into_iter ( ) . find ( | coin | coin . denom == FEE_DENOMINATION ) { Some ( coin ) => coin . amount , None => { // If fees are required, then a coin of type FEE_DENOMINATION should be sent and the // absence of one is an error.  Otherwise, treat omission as purposeful definition of // zero money fronted for a fee if nhash_fee_amount > 0 { return ContractError :: NoFundsProvidedForRegistration . to_result ( ) ; } else { Uint128 :: zero ( ) } } } ; // If the amount provided is too low, reject the request because the fee cannot be paid if nhash_sent . u128 ( ) < nhash_fee_amount { return ContractError :: InsufficientFundsProvided { amount_provided : nhash_sent . u128 ( ) , amount_required : nhash_fee_amount , } . to_result ( ) ; } // Pull the fee amount from the sender for name registration let fee_charge_message = if nhash_fee_amount > 0 { Some ( CosmosMsg :: Bank ( BankMsg :: Send { // The fee collection address is validated on contract instantiation, so there's no need to // define custom error messages here to_address : api . addr_validate ( & config . fee_collection_address ) ? . into ( ) , // The same goes for the fee_amount - it is guaranteed to pass this check amount : vec ! [ coin ( nhash_fee_amount FEE_DENOMINATION ) ] , } ) ) } else { None } ; // The refund amount is == the total nhash sent - fee charged let fee_refund_amount = nhash_sent . u128 ( ) - nhash_fee_amount ; // If more than the fee amount is sent, then respond with an additional message that sends the // excess back into the sender's account let fee_refund_message = if fee_refund_amount > 0 { Some ( CosmosMsg :: Bank ( BankMsg :: Send { to_address : info . sender . clone ( ) . into ( ) , amount : vec ! [ coin ( fee_refund_amount FEE_DENOMINATION ) ] , } ) ) } else { None } ; Ok ( FeeChargeResponse { fee_charge_message , fee_refund_message , fee_refund_amount , } ) }
Verifies that funds provided are correct and enough for a fee charge, and then constructs
provenance messages that will provide the correct output during the name registration process.
Verifies that funds provided are correct and enough for a fee charge and then constructs provenance messages that will provide the correct output during the name registration process .
api
&dyn Api
info
&MessageInfo
config
&State