// Transfer dcc from sender to recipient. Both accounts must either be member accounts, or
// have the required kyc attributes.
Transfer dcc from sender to recipient. Both accounts must either be member accounts, or
have the required kyc attributes.
Transfer dcc from sender to recipient . Both accounts must either be member accounts or have the required kyc attributes .
fn try_transfer(
    deps: DepsMut,
    info: MessageInfo,
    amount: Uint128,
    recipient: String,
) -> Result<Response<ProvenanceMsg>, ContractError> {
    // Ensure no funds were sent
    if !info.funds.is_empty() {
        return Err(contract_err("bank sends are not allowed in dcc transfer"));
    }
    // Ensure amount is non-zero.
    if amount.is_zero() {
        return Err(contract_err("invalid transfer amount"));
    }
    // Validate address
    let recipient = deps.api.addr_validate(&recipient)?;
    // Read state
    let state = config_read(deps.storage).load()?;
    // Ensure the sender holds at least the indicated amount of dcc.
    let balance = deps
        .querier
        .query_balance(info.sender.clone(), &state.dcc_denom)?;
    if balance.amount < amount {
        return Err(contract_err("insufficient dcc balance in transfer"));
    }
    // Ensure accounts have the required kyc attrs if they aren't members.
    let members = members_read(deps.storage);
    if members.may_load(recipient.as_bytes())?.is_none() {
        ensure_attributes(deps.as_ref(), recipient.clone(), state.kyc_attrs.clone())?;
    }
    if members.may_load(info.sender.as_bytes())?.is_none() {
        ensure_attributes(deps.as_ref(), info.sender.clone(), state.kyc_attrs)?;
    }
    // Transfer the dcc
    let res = Response::new()
        .add_message(transfer_marker_coins(
            amount.u128(),
            &state.dcc_denom,
            recipient.clone(),
            info.sender.clone(),
        )?)
        .add_attribute("action", "transfer")
        .add_attribute("amount", amount)
        .add_attribute("denom", &state.dcc_denom)
        .add_attribute("sender", info.sender)
        .add_attribute("recipient", recipient);
    Ok(res)
}
fn try_transfer ( deps : DepsMut , info : MessageInfo , amount : Uint128 , recipient : 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 ( " " ) ) ; } // Validate address let recipient = deps . api . addr_validate ( & recipient ) ? ; // Read state let state = config_read ( deps . storage ) . load ( ) ? ; // Ensure the sender holds at least the indicated amount of dcc. let balance = deps . querier . query_balance ( info . sender . clone ( ) , & state . dcc_denom ) ? ; if balance . amount < amount { return Err ( contract_err ( " " ) ) ; } // Ensure accounts have the required kyc attrs if they aren't members. let members = members_read ( deps . storage ) ; if members . may_load ( recipient . as_bytes ( ) ) ? . is_none ( ) { ensure_attributes ( deps . as_ref ( ) , recipient . clone ( ) , state . kyc_attrs . clone ( ) ) ? ; } if members . may_load ( info . sender . as_bytes ( ) ) ? . is_none ( ) { ensure_attributes ( deps . as_ref ( ) , info . sender . clone ( ) , state . kyc_attrs ) ? ; } // Transfer the dcc let res = Response :: new ( ) . add_message ( transfer_marker_coins ( amount . u128 ( ) , & state . dcc_denom , recipient . clone ( ) , info . sender . clone ( ) , ) ? ) . add_attribute ( " " , " " ) . add_attribute ( " " , amount ) . add_attribute ( " " , & state . dcc_denom ) . add_attribute ( " " , info . sender ) . add_attribute ( " " , recipient ) ; Ok ( res ) }
Transfer dcc from sender to recipient.
Transfer dcc from sender to recipient .
deps
DepsMut
info
MessageInfo
amount
Uint128
recipient
String