pub fn execute_claim_tickets(
    mut deps: DepsMut,
    env: Env,
    info: MessageInfo,
    encoded_tickets: String,
) -> Result<Response, ContractError> {
    let config = CONFIG.load(deps.storage)?;
    let state = STATE.load(deps.storage)?;
    let pool = POOL.load(deps.storage)?;

    let depositor = info.sender.clone();
    let mut depositor_info: DepositorInfo = read_depositor_info(deps.storage, &depositor);

    // Get the aust exchange rate
    let aust_exchange_rate = query_exchange_rate(
        deps.as_ref(),
        config.anchor_contract.to_string(),
        env.block.height,
    )?
    .exchange_rate;

    // Validate that the lottery has not already started
    let current_lottery = read_lottery_info(deps.storage, state.current_lottery);
    if current_lottery.rand_round != 0 {
        return Err(ContractError::LotteryAlreadyStarted {});
    }

    // Propogate depositor ticket updates
    let number_of_new_tickets = handle_depositor_ticket_updates(
        deps.branch(),
        &env,
        &config,
        &pool,
        &depositor,
        &mut depositor_info,
        encoded_tickets,
        aust_exchange_rate,
        Uint256::zero(),
        Uint256::zero(),
    )?;

    // Update depositor and state information
    store_depositor_info(deps.storage, &depositor, depositor_info, env.block.height)?;

    // Save depositor and state information
    Ok(Response::new().add_attributes(vec![
        attr("action", "claim_tickets"),
        attr("depositor", info.sender.to_string()),
        attr("recipient", depositor.to_string()),
        attr("tickets", number_of_new_tickets.to_string()),
    ]))
}
// Deposit UST and get savings aust and tickets in return
Deposit UST and get savings aust and tickets in return
Deposit UST and get savings aust and tickets in return
pub fn execute_claim_tickets(
    mut deps: DepsMut,
    env: Env,
    info: MessageInfo,
    encoded_tickets: String,
) -> Result<Response, ContractError> {
    let config = CONFIG.load(deps.storage)?;
    let state = STATE.load(deps.storage)?;
    let pool = POOL.load(deps.storage)?;
    let depositor = info.sender.clone();
    let mut depositor_info: DepositorInfo = read_depositor_info(deps.storage, &depositor);
    // Get the aust exchange rate
    let aust_exchange_rate = query_exchange_rate(
        deps.as_ref(),
        config.anchor_contract.to_string(),
        env.block.height,
    )?
    .exchange_rate;
    // Validate that the lottery has not already started
    let current_lottery = read_lottery_info(deps.storage, state.current_lottery);
    if current_lottery.rand_round != 0 {
        return Err(ContractError::LotteryAlreadyStarted {});
    }
    // Propogate depositor ticket updates
    let number_of_new_tickets = handle_depositor_ticket_updates(
        deps.branch(),
        &env,
        &config,
        &pool,
        &depositor,
        &mut depositor_info,
        encoded_tickets,
        aust_exchange_rate,
        Uint256::zero(),
        Uint256::zero(),
    )?;
    // Update depositor and state information
    store_depositor_info(deps.storage, &depositor, depositor_info, env.block.height)?;
    // Save depositor and state information
    Ok(Response::new().add_attributes(vec![
        attr("action", "claim_tickets"),
        attr("depositor", info.sender.to_string()),
        attr("recipient", depositor.to_string()),
        attr("tickets", number_of_new_tickets.to_string()),
    ]))
}
pub fn execute_claim_tickets ( mut deps : DepsMut , env : Env , info : MessageInfo , encoded_tickets : String , ) -> Result < Response , ContractError > { let config = CONFIG . load ( deps . storage ) ? ; let state = STATE . load ( deps . storage ) ? ; let pool = POOL . load ( deps . storage ) ? ; let depositor = info . sender . clone ( ) ; let mut depositor_info : DepositorInfo = read_depositor_info ( deps . storage , & depositor ) ; // Get the aust exchange rate let aust_exchange_rate = query_exchange_rate ( deps . as_ref ( ) , config . anchor_contract . to_string ( ) , env . block . height , ) ? . exchange_rate ; // Validate that the lottery has not already started let current_lottery = read_lottery_info ( deps . storage , state . current_lottery ) ; if current_lottery . rand_round != 0 { return Err ( ContractError :: LotteryAlreadyStarted { } ) ; } // Propogate depositor ticket updates let number_of_new_tickets = handle_depositor_ticket_updates ( deps . branch ( ) , & env , & config , & pool , & depositor , & mut depositor_info , encoded_tickets , aust_exchange_rate , Uint256 :: zero ( ) , Uint256 :: zero ( ) , ) ? ; // Update depositor and state information store_depositor_info ( deps . storage , & depositor , depositor_info , env . block . height ) ? ; // Save depositor and state information Ok ( Response :: new ( ) . add_attributes ( vec ! [ attr ( " " " " ) attr ( " " info sender to_string ( ) ) attr ( " " depositor to_string ( ) ) attr ( " " number_of_new_tickets to_string ( ) ) ] ) ) }
Deposit UST and get savings aust and tickets in return
Deposit UST and get savings aust and tickets in return
deps
DepsMut
env
Env
info
MessageInfo
encoded_tickets
String
deps
DepsMut
env
Env
info
MessageInfo
encoded_tickets
String