/// Detect whether a proposal is executed within `timeout`.
///
/// # Arguments
///
/// * `ctx`         - Fondue context
/// * `governance`  - Governance canister
/// * `proposal_id` - ID of a proposal to be executed
/// * `retry_delay` - Duration between polling attempts
/// * `timeout`     - Duration after which we give up (returning false)
///
/// Eventually returns whether the proposal has been executed.
Detect whether a proposal is executed within `timeout`.
Detect whether a proposal is executed within ` timeout ` .
pub async fn await_proposal_execution(
    ctx: &ic_fondue::pot::Context,
    governance: &Canister<'_>,
    proposal_id: ProposalId,
    retry_delay: Duration,
    timeout: Duration,
) -> bool {
    let mut i = 0usize;
    let start_time = std::time::Instant::now();
    loop {
        i += 1;
        info!(
            ctx.logger,
            "Attempt #{} of obtaining final execution status for {:?}", i, proposal_id
        );
        let proposal_info = get_proposal_info(governance, proposal_id)
            .await
            .unwrap_or_else(|| panic!("could not obtain proposal status"));
        match ProposalStatus::from_i32(proposal_info.status).unwrap() {
            ProposalStatus::Open => {
                // This proposal is still open
                info!(ctx.logger, "{:?} is open...", proposal_id,)
            }
            ProposalStatus::Adopted => {
                // This proposal is adopted but not yet executed
                info!(ctx.logger, "{:?} is adopted...", proposal_id,)
            }
            ProposalStatus::Executed => {
                // This proposal is already executed
                info!(ctx.logger, "{:?} has been executed.", proposal_id,);
                return true;
            }
            other_status => {
                // This proposal will not be executed
                info!(
                    ctx.logger,
                    "{:?} could not be adopted: {:?}", proposal_id, other_status
                );
                return false;
            }
        }
        if std::time::Instant::now()
            .duration_since(start_time)
            .gt(&timeout)
        {
            // Give up
            return false;
        } else {
            // Continue polling with delay
            sleep(retry_delay).await;
        }
    }
}
pub async fn await_proposal_execution ( ctx : & ic_fondue :: pot :: Context , governance : & Canister < ' _ > , proposal_id : ProposalId , retry_delay : Duration , timeout : Duration , ) -> bool { let mut i = 0usize ; let start_time = std :: time :: Instant :: now ( ) ; loop { i += 1 ; info ! ( ctx logger " " i proposal_id ) ; let proposal_info = get_proposal_info ( governance , proposal_id ) . await . unwrap_or_else ( | | panic ! ( " " ) ) ; match ProposalStatus :: from_i32 ( proposal_info . status ) . unwrap ( ) { ProposalStatus :: Open => { // This proposal is still open info ! ( ctx logger " " proposal_id ) } ProposalStatus :: Adopted => { // This proposal is adopted but not yet executed info ! ( ctx logger " " proposal_id ) } ProposalStatus :: Executed => { // This proposal is already executed info ! ( ctx logger " " proposal_id ) ; return true ; } other_status => { // This proposal will not be executed info ! ( ctx logger " " proposal_id other_status ) ; return false ; } } if std :: time :: Instant :: now ( ) . duration_since ( start_time ) . gt ( & timeout ) { // Give up return false ; } else { // Continue polling with delay sleep ( retry_delay ) . await ; } } }
Detect whether a proposal is executed within `timeout`.
Detect whether a proposal is executed within ` timeout ` .
ctx
&ic_fondue::pot::Context
governance
&Canister<'_>
proposal_id
ProposalId
retry_delay
Duration
timeout
Duration