fn try_mint(
    deps: DepsMut,
    info: MessageInfo,
    amount: Uint128,
    address: Option<String>,
) -> Result<Response<ProvenanceMsg>, ContractError> {
    // Ensure no funds were sent
    if !info.funds.is_empty() {
        return Err(contract_err("no funds should be sent during mint"));
    }

    // Ensure amount is non-zero.
    if amount.is_zero() {
        return Err(contract_err("invalid mint amount"));
    }

    // Load membership for message sender.
    let key = info.sender.as_bytes();
    let mut member = members(deps.storage).load(key)?;

    // Validate that amount doesn't push supply over max
    if amount + member.supply > member.max_supply {
        return Err(contract_err("max supply exceeded"));
    }

    // Update reserve supply.
    member.supply += amount;
    members(deps.storage).save(key, &member)?;

    // Mint reserve
    let mut res = Response::new().add_message(mint_marker_supply(amount.u128(), &member.denom)?);

    // Mint dcc if the withdraw address was provided.
    let state = config_read(deps.storage).load()?;
    if address.is_some() {
        res = res.add_message(mint_marker_supply(amount.u128(), &state.dcc_denom)?);
    }

    // Add wasm event attributes
    res = res
        .add_attribute("action", "mint")
        .add_attribute("member_id", &member.id)
        .add_attribute("amount", amount)
        .add_attribute("denom", &member.denom);

    // Withdraw either dcc or reserve token.
    match address {
        None => {
            // Withdraw minted reserve tokens to the member account.
            res = res
                .add_message(withdraw_coins(
                    &member.denom,
                    amount.u128(),
                    &member.denom,
                    info.sender.clone(),
                )?)
                .add_attribute("withdraw_denom", &member.denom)
                .add_attribute("withdraw_address", info.sender);
        }
        Some(a) => {
            // When withdrawing dcc tokens to a non-member account, ensure the recipient has the
            // required kyc attributes.
            let address = deps.api.addr_validate(&a)?;
            if address != info.sender {
                ensure_attributes(deps.as_ref(), address.clone(), state.kyc_attrs)?;
            }
            // Withdraw minted dcc tokens to the provided account.
            res = res
                .add_message(withdraw_coins(
                    &state.dcc_denom,
                    amount.u128(),
                    &state.dcc_denom,
                    address.clone(),
                )?)
                .add_attribute("withdraw_denom", &state.dcc_denom)
                .add_attribute("withdraw_address", address);
        }
    };
    Ok(res)
}
// Increase the reserve supply of a member.
// If an address is provided, mint dcc tokens and withdraw there.
Increase the reserve supply of a member.
If an address is provided, mint dcc tokens and withdraw there.
Increase the reserve supply of a member . If an address is provided mint dcc tokens and withdraw there .
fn try_mint(
    deps: DepsMut,
    info: MessageInfo,
    amount: Uint128,
    address: Option<String>,
) -> Result<Response<ProvenanceMsg>, ContractError> {
    // Ensure no funds were sent
    if !info.funds.is_empty() {
        return Err(contract_err("no funds should be sent during mint"));
    }
    // Ensure amount is non-zero.
    if amount.is_zero() {
        return Err(contract_err("invalid mint amount"));
    }
    // Load membership for message sender.
    let key = info.sender.as_bytes();
    let mut member = members(deps.storage).load(key)?;
    // Validate that amount doesn't push supply over max
    if amount + member.supply > member.max_supply {
        return Err(contract_err("max supply exceeded"));
    }
    // Update reserve supply.
    member.supply += amount;
    members(deps.storage).save(key, &member)?;
    // Mint reserve
    let mut res = Response::new().add_message(mint_marker_supply(amount.u128(), &member.denom)?);
    // Mint dcc if the withdraw address was provided.
    let state = config_read(deps.storage).load()?;
    if address.is_some() {
        res = res.add_message(mint_marker_supply(amount.u128(), &state.dcc_denom)?);
    }
    // Add wasm event attributes
    res = res
        .add_attribute("action", "mint")
        .add_attribute("member_id", &member.id)
        .add_attribute("amount", amount)
        .add_attribute("denom", &member.denom);
    // Withdraw either dcc or reserve token.
    match address {
        None => {
            // Withdraw minted reserve tokens to the member account.
            res = res
                .add_message(withdraw_coins(
                    &member.denom,
                    amount.u128(),
                    &member.denom,
                    info.sender.clone(),
                )?)
                .add_attribute("withdraw_denom", &member.denom)
                .add_attribute("withdraw_address", info.sender);
        }
        Some(a) => {
            // When withdrawing dcc tokens to a non-member account, ensure the recipient has the
            // required kyc attributes.
            let address = deps.api.addr_validate(&a)?;
            if address != info.sender {
                ensure_attributes(deps.as_ref(), address.clone(), state.kyc_attrs)?;
            }
            // Withdraw minted dcc tokens to the provided account.
            res = res
                .add_message(withdraw_coins(
                    &state.dcc_denom,
                    amount.u128(),
                    &state.dcc_denom,
                    address.clone(),
                )?)
                .add_attribute("withdraw_denom", &state.dcc_denom)
                .add_attribute("withdraw_address", address);
        }
    };
    Ok(res)
}
fn try_mint ( deps : DepsMut , info : MessageInfo , amount : Uint128 , address : Option < String > , ) -> Result < Response < ProvenanceMsg > , ContractError > { // Ensure no funds were sent if ! info . funds . is_empty ( ) { return Err ( contract_err ( " " ) ) ; } // Ensure amount is non-zero. if amount . is_zero ( ) { return Err ( contract_err ( " " ) ) ; } // Load membership for message sender. let key = info . sender . as_bytes ( ) ; let mut member = members ( deps . storage ) . load ( key ) ? ; // Validate that amount doesn't push supply over max if amount + member . supply > member . max_supply { return Err ( contract_err ( " " ) ) ; } // Update reserve supply. member . supply += amount ; members ( deps . storage ) . save ( key , & member ) ? ; // Mint reserve let mut res = Response :: new ( ) . add_message ( mint_marker_supply ( amount . u128 ( ) , & member . denom ) ? ) ; // Mint dcc if the withdraw address was provided. let state = config_read ( deps . storage ) . load ( ) ? ; if address . is_some ( ) { res = res . add_message ( mint_marker_supply ( amount . u128 ( ) , & state . dcc_denom ) ? ) ; } // Add wasm event attributes res = res . add_attribute ( " " , " " ) . add_attribute ( " " , & member . id ) . add_attribute ( " " , amount ) . add_attribute ( " " , & member . denom ) ; // Withdraw either dcc or reserve token. match address { None => { // Withdraw minted reserve tokens to the member account. res = res . add_message ( withdraw_coins ( & member . denom , amount . u128 ( ) , & member . denom , info . sender . clone ( ) , ) ? ) . add_attribute ( " " , & member . denom ) . add_attribute ( " " , info . sender ) ; } Some ( a ) => { // When withdrawing dcc tokens to a non-member account, ensure the recipient has the // required kyc attributes. let address = deps . api . addr_validate ( & a ) ? ; if address != info . sender { ensure_attributes ( deps . as_ref ( ) , address . clone ( ) , state . kyc_attrs ) ? ; } // Withdraw minted dcc tokens to the provided account. res = res . add_message ( withdraw_coins ( & state . dcc_denom , amount . u128 ( ) , & state . dcc_denom , address . clone ( ) , ) ? ) . add_attribute ( " " , & state . dcc_denom ) . add_attribute ( " " , address ) ; } } ; Ok ( res ) }
Increase the reserve supply of a member.
Increase the reserve supply of a member .
deps
DepsMut
info
MessageInfo
amount
Uint128
address
Option<String>
deps
DepsMut
info
MessageInfo
amount
Uint128
address
Option<String>