pub fn after_unbond_handler_instantiation(
    deps: DepsMut,
    response: MsgInstantiateContractResponse,
    events: Vec<Event>,
) -> VaultResult<Response> {
    let unbond_handler_contract = deps.api.addr_validate(response.get_contract_address())?;

    let event = events
        .iter()
        .find(|event| event_contains_attr(event, "action", "instantiate"))
        .ok_or_else(|| StdError::generic_err("cannot find `instantiate` event"))?;

    // get owner from event
    let owner_string = get_attribute_value_from_event(event, OWNER_KEY)?;
    let owner = deps.api.addr_validate(&owner_string)?;
    UNBOND_HANDLERS_ASSIGNED.save(deps.storage, owner.clone(), &unbond_handler_contract)?;

    // get expiration_time from event
    let expiration_time_string = get_attribute_value_from_event(event, EXPIRATION_TIME_KEY)?;
    let expiration_time = expiration_time_string.parse::<u64>()?;
    UNBOND_HANDLER_EXPIRATION_TIMES.save(
        deps.storage,
        unbond_handler_contract.clone(),
        &expiration_time,
    )?;

    // get data from the cache to execute the unbond operation after the unbond handler is created
    let unbond_data_cache_option = UNBOND_CACHE.may_load(deps.storage)?;
    if unbond_data_cache_option.is_none() {
        return Err(LunaVaultError::UnbondHandlerMissingDataCache {});
    }

    let unbond_data_cache =
        unbond_data_cache_option.ok_or(LunaVaultError::UnbondDataCacheError {})?;
    // make sure the cached owner corresponds to the one fetched from the instantiation msg
    let cached_owner = unbond_data_cache.clone().owner;
    if cached_owner != owner {
        return Err(LunaVaultError::UnbondHandlerMismatchingDataCache {});
    }

    // get luna amount from cache and send to unbond handler
    let luna_asset = unbond_data_cache.luna_asset;
    let send_luna_to_handler_msg =
        luna_asset.into_msg(&deps.querier, unbond_handler_contract.clone())?;

    // get bluna amount from cache and send to unbond handler
    let bluna_amount = unbond_data_cache.bluna_amount;
    let unbond_msg =
        unbond_bluna_with_handler_msg(deps.storage, bluna_amount, &unbond_handler_contract)?;

    // clear the unbond cache
    UNBOND_CACHE.remove(deps.storage);

    Ok(Response::new()
        .add_messages(vec![send_luna_to_handler_msg, unbond_msg])
        .add_attributes(vec![
            attr("action", "unbond_handler_instantiate"),
            attr("owner", owner_string),
            attr(
                "unbond_handler_contract",
                unbond_handler_contract.to_string(),
            ),
            attr("expiration_time", expiration_time_string),
        ]))
}
/// Executes after the unbond contract instantiation occurs successfully
/// Stores the new unbond handler information into the respective state items
Executes after the unbond contract instantiation occurs successfully
Stores the new unbond handler information into the respective state items
Executes after the unbond contract instantiation occurs successfully Stores the new unbond handler information into the respective state items
pub fn after_unbond_handler_instantiation(
    deps: DepsMut,
    response: MsgInstantiateContractResponse,
    events: Vec<Event>,
) -> VaultResult<Response> {
    let unbond_handler_contract = deps.api.addr_validate(response.get_contract_address())?;
    let event = events
        .iter()
        .find(|event| event_contains_attr(event, "action", "instantiate"))
        .ok_or_else(|| StdError::generic_err("cannot find `instantiate` event"))?;
    // get owner from event
    let owner_string = get_attribute_value_from_event(event, OWNER_KEY)?;
    let owner = deps.api.addr_validate(&owner_string)?;
    UNBOND_HANDLERS_ASSIGNED.save(deps.storage, owner.clone(), &unbond_handler_contract)?;
    // get expiration_time from event
    let expiration_time_string = get_attribute_value_from_event(event, EXPIRATION_TIME_KEY)?;
    let expiration_time = expiration_time_string.parse::<u64>()?;
    UNBOND_HANDLER_EXPIRATION_TIMES.save(
        deps.storage,
        unbond_handler_contract.clone(),
        &expiration_time,
    )?;
    // get data from the cache to execute the unbond operation after the unbond handler is created
    let unbond_data_cache_option = UNBOND_CACHE.may_load(deps.storage)?;
    if unbond_data_cache_option.is_none() {
        return Err(LunaVaultError::UnbondHandlerMissingDataCache {});
    }
    let unbond_data_cache =
        unbond_data_cache_option.ok_or(LunaVaultError::UnbondDataCacheError {})?;
    // make sure the cached owner corresponds to the one fetched from the instantiation msg
    let cached_owner = unbond_data_cache.clone().owner;
    if cached_owner != owner {
        return Err(LunaVaultError::UnbondHandlerMismatchingDataCache {});
    }
    // get luna amount from cache and send to unbond handler
    let luna_asset = unbond_data_cache.luna_asset;
    let send_luna_to_handler_msg =
        luna_asset.into_msg(&deps.querier, unbond_handler_contract.clone())?;
    // get bluna amount from cache and send to unbond handler
    let bluna_amount = unbond_data_cache.bluna_amount;
    let unbond_msg =
        unbond_bluna_with_handler_msg(deps.storage, bluna_amount, &unbond_handler_contract)?;
    // clear the unbond cache
    UNBOND_CACHE.remove(deps.storage);
    Ok(Response::new()
        .add_messages(vec![send_luna_to_handler_msg, unbond_msg])
        .add_attributes(vec![
            attr("action", "unbond_handler_instantiate"),
            attr("owner", owner_string),
            attr(
                "unbond_handler_contract",
                unbond_handler_contract.to_string(),
            ),
            attr("expiration_time", expiration_time_string),
        ]))
}
pub fn after_unbond_handler_instantiation ( deps : DepsMut , response : MsgInstantiateContractResponse , events : Vec < Event > , ) -> VaultResult < Response > { let unbond_handler_contract = deps . api . addr_validate ( response . get_contract_address ( ) ) ? ; let event = events . iter ( ) . find ( | event | event_contains_attr ( event , " " , " " ) ) . ok_or_else ( | | StdError :: generic_err ( " " ) ) ? ; // get owner from event let owner_string = get_attribute_value_from_event ( event , OWNER_KEY ) ? ; let owner = deps . api . addr_validate ( & owner_string ) ? ; UNBOND_HANDLERS_ASSIGNED . save ( deps . storage , owner . clone ( ) , & unbond_handler_contract ) ? ; // get expiration_time from event let expiration_time_string = get_attribute_value_from_event ( event , EXPIRATION_TIME_KEY ) ? ; let expiration_time = expiration_time_string . parse :: < u64 > ( ) ? ; UNBOND_HANDLER_EXPIRATION_TIMES . save ( deps . storage , unbond_handler_contract . clone ( ) , & expiration_time , ) ? ; // get data from the cache to execute the unbond operation after the unbond handler is created let unbond_data_cache_option = UNBOND_CACHE . may_load ( deps . storage ) ? ; if unbond_data_cache_option . is_none ( ) { return Err ( LunaVaultError :: UnbondHandlerMissingDataCache { } ) ; } let unbond_data_cache = unbond_data_cache_option . ok_or ( LunaVaultError :: UnbondDataCacheError { } ) ? ; // make sure the cached owner corresponds to the one fetched from the instantiation msg let cached_owner = unbond_data_cache . clone ( ) . owner ; if cached_owner != owner { return Err ( LunaVaultError :: UnbondHandlerMismatchingDataCache { } ) ; } // get luna amount from cache and send to unbond handler let luna_asset = unbond_data_cache . luna_asset ; let send_luna_to_handler_msg = luna_asset . into_msg ( & deps . querier , unbond_handler_contract . clone ( ) ) ? ; // get bluna amount from cache and send to unbond handler let bluna_amount = unbond_data_cache . bluna_amount ; let unbond_msg = unbond_bluna_with_handler_msg ( deps . storage , bluna_amount , & unbond_handler_contract ) ? ; // clear the unbond cache UNBOND_CACHE . remove ( deps . storage ) ; Ok ( Response :: new ( ) . add_messages ( vec ! [ send_luna_to_handler_msg unbond_msg ] ) . add_attributes ( vec ! [ attr ( " " " " ) attr ( " " owner_string ) attr ( " " unbond_handler_contract to_string ( ) ) attr ( " " expiration_time_string ) ] ) ) }
Executes after the unbond contract instantiation occurs successfully
Stores the new unbond handler information into the respective state items
Executes after the unbond contract instantiation occurs successfully Stores the new unbond handler information into the respective state items
deps
DepsMut
response
MsgInstantiateContractResponse
events
Vec<Event>
deps
DepsMut
response
MsgInstantiateContractResponse
events
Vec<Event>