pub fn execute_poll(deps: DepsMut, env: Env, poll_id: u64) -> StdResult<Response> {
    let config: Config = config_read(deps.storage).load()?;
    let mut a_poll: Poll = poll_store(deps.storage).load(&poll_id.to_be_bytes())?;

    let (is_fast_track, admin_msg) =
        match poll_additional_params_read(deps.storage).load(&poll_id.to_be_bytes()) {
            Ok(params) => match params.admin_action {
                Some(action) => match action {
                    PollAdminAction::ExecuteMigrations { .. } => (true, Some(to_binary(&action)?)),
                    _ => (false, Some(to_binary(&action)?)),
                },
                _ => (false, None),
            },
            _ => (false, None),
        };

    if a_poll.status != PollStatus::Passed {
        return Err(StdError::generic_err("Poll is not in passed status"));
    }

    let current_seconds = env.block.time.seconds();
    if !is_fast_track && a_poll.end_time + config.effective_delay > current_seconds {
        return Err(StdError::generic_err("Effective delay has not expired"));
    }

    poll_indexer_store(deps.storage, &PollStatus::Passed).remove(&poll_id.to_be_bytes());
    poll_indexer_store(deps.storage, &PollStatus::Executed).save(&poll_id.to_be_bytes(), &true)?;

    a_poll.status = PollStatus::Executed;
    poll_store(deps.storage).save(&poll_id.to_be_bytes(), &a_poll)?;

    // if is not possible to create a poll with both admin_msg and execute_data, only one per poll
    let execute_msg: CosmosMsg = if let Some(execute_data) = a_poll.execute_data {
        CosmosMsg::Wasm(WasmMsg::Execute {
            contract_addr: deps.api.addr_humanize(&execute_data.contract)?.to_string(),
            msg: execute_data.msg,
            funds: vec![],
        })
    } else if let Some(admin_msg) = admin_msg {
        match from_binary(&admin_msg)? {
            PollAdminAction::UpdateConfig { .. } => CosmosMsg::Wasm(WasmMsg::Execute {
                contract_addr: env.contract.address.to_string(),
                msg: admin_msg,
                funds: vec![],
            }),
            _ => CosmosMsg::Wasm(WasmMsg::Execute {
                contract_addr: deps.api.addr_humanize(&config.admin_manager)?.to_string(),
                msg: admin_msg,
                funds: vec![],
            }),
        }
    } else {
        return Err(StdError::generic_err("The poll does not have execute_data"));
    };

    // the execution will reply in case of failure, to mark the poll as failed
    let execute_submsg = SubMsg {
        msg: execute_msg,
        gas_limit: Some(config.poll_gas_limit),
        id: POLL_EXECUTE_REPLY_ID,
        reply_on: ReplyOn::Error,
    };

    store_tmp_poll_id(deps.storage, a_poll.id)?;

    Ok(Response::new()
        .add_submessage(execute_submsg)
        .add_attributes(vec![
            attr("action", "execute_poll"),
            attr("poll_id", poll_id.to_string()),
        ]))
}
/*
 * Execute a msg of passed poll.
 */
Execute a msg of passed poll.
Execute a msg of passed poll .
pub fn execute_poll(deps: DepsMut, env: Env, poll_id: u64) -> StdResult<Response> {
    let config: Config = config_read(deps.storage).load()?;
    let mut a_poll: Poll = poll_store(deps.storage).load(&poll_id.to_be_bytes())?;
    let (is_fast_track, admin_msg) =
        match poll_additional_params_read(deps.storage).load(&poll_id.to_be_bytes()) {
            Ok(params) => match params.admin_action {
                Some(action) => match action {
                    PollAdminAction::ExecuteMigrations { .. } => (true, Some(to_binary(&action)?)),
                    _ => (false, Some(to_binary(&action)?)),
                },
                _ => (false, None),
            },
            _ => (false, None),
        };
    if a_poll.status != PollStatus::Passed {
        return Err(StdError::generic_err("Poll is not in passed status"));
    }
    let current_seconds = env.block.time.seconds();
    if !is_fast_track && a_poll.end_time + config.effective_delay > current_seconds {
        return Err(StdError::generic_err("Effective delay has not expired"));
    }
    poll_indexer_store(deps.storage, &PollStatus::Passed).remove(&poll_id.to_be_bytes());
    poll_indexer_store(deps.storage, &PollStatus::Executed).save(&poll_id.to_be_bytes(), &true)?;
    a_poll.status = PollStatus::Executed;
    poll_store(deps.storage).save(&poll_id.to_be_bytes(), &a_poll)?;
    // if is not possible to create a poll with both admin_msg and execute_data, only one per poll
    let execute_msg: CosmosMsg = if let Some(execute_data) = a_poll.execute_data {
        CosmosMsg::Wasm(WasmMsg::Execute {
            contract_addr: deps.api.addr_humanize(&execute_data.contract)?.to_string(),
            msg: execute_data.msg,
            funds: vec![],
        })
    } else if let Some(admin_msg) = admin_msg {
        match from_binary(&admin_msg)? {
            PollAdminAction::UpdateConfig { .. } => CosmosMsg::Wasm(WasmMsg::Execute {
                contract_addr: env.contract.address.to_string(),
                msg: admin_msg,
                funds: vec![],
            }),
            _ => CosmosMsg::Wasm(WasmMsg::Execute {
                contract_addr: deps.api.addr_humanize(&config.admin_manager)?.to_string(),
                msg: admin_msg,
                funds: vec![],
            }),
        }
    } else {
        return Err(StdError::generic_err("The poll does not have execute_data"));
    };
    // the execution will reply in case of failure, to mark the poll as failed
    let execute_submsg = SubMsg {
        msg: execute_msg,
        gas_limit: Some(config.poll_gas_limit),
        id: POLL_EXECUTE_REPLY_ID,
        reply_on: ReplyOn::Error,
    };
    store_tmp_poll_id(deps.storage, a_poll.id)?;
    Ok(Response::new()
        .add_submessage(execute_submsg)
        .add_attributes(vec![
            attr("action", "execute_poll"),
            attr("poll_id", poll_id.to_string()),
        ]))
}
pub fn execute_poll ( deps : DepsMut , env : Env , poll_id : u64 ) -> StdResult < Response > { let config : Config = config_read ( deps . storage ) . load ( ) ? ; let mut a_poll : Poll = poll_store ( deps . storage ) . load ( & poll_id . to_be_bytes ( ) ) ? ; let ( is_fast_track , admin_msg ) = match poll_additional_params_read ( deps . storage ) . load ( & poll_id . to_be_bytes ( ) ) { Ok ( params ) => match params . admin_action { Some ( action ) => match action { PollAdminAction :: ExecuteMigrations { .. } => ( true , Some ( to_binary ( & action ) ? ) ) , _ => ( false , Some ( to_binary ( & action ) ? ) ) , } , _ => ( false , None ) , } , _ => ( false , None ) , } ; if a_poll . status != PollStatus :: Passed { return Err ( StdError :: generic_err ( " " ) ) ; } let current_seconds = env . block . time . seconds ( ) ; if ! is_fast_track && a_poll . end_time + config . effective_delay > current_seconds { return Err ( StdError :: generic_err ( " " ) ) ; } poll_indexer_store ( deps . storage , & PollStatus :: Passed ) . remove ( & poll_id . to_be_bytes ( ) ) ; poll_indexer_store ( deps . storage , & PollStatus :: Executed ) . save ( & poll_id . to_be_bytes ( ) , & true ) ? ; a_poll . status = PollStatus :: Executed ; poll_store ( deps . storage ) . save ( & poll_id . to_be_bytes ( ) , & a_poll ) ? ; // if is not possible to create a poll with both admin_msg and execute_data, only one per poll let execute_msg : CosmosMsg = if let Some ( execute_data ) = a_poll . execute_data { CosmosMsg :: Wasm ( WasmMsg :: Execute { contract_addr : deps . api . addr_humanize ( & execute_data . contract ) ? . to_string ( ) , msg : execute_data . msg , funds : vec ! [ ] , } ) } else if let Some ( admin_msg ) = admin_msg { match from_binary ( & admin_msg ) ? { PollAdminAction :: UpdateConfig { .. } => CosmosMsg :: Wasm ( WasmMsg :: Execute { contract_addr : env . contract . address . to_string ( ) , msg : admin_msg , funds : vec ! [ ] , } ) , _ => CosmosMsg :: Wasm ( WasmMsg :: Execute { contract_addr : deps . api . addr_humanize ( & config . admin_manager ) ? . to_string ( ) , msg : admin_msg , funds : vec ! [ ] , } ) , } } else { return Err ( StdError :: generic_err ( " " ) ) ; } ; // the execution will reply in case of failure, to mark the poll as failed let execute_submsg = SubMsg { msg : execute_msg , gas_limit : Some ( config . poll_gas_limit ) , id : POLL_EXECUTE_REPLY_ID , reply_on : ReplyOn :: Error , } ; store_tmp_poll_id ( deps . storage , a_poll . id ) ? ; Ok ( Response :: new ( ) . add_submessage ( execute_submsg ) . add_attributes ( vec ! [ attr ( " " " " ) attr ( " " poll_id to_string ( ) ) ] ) ) }
Execute a msg of passed poll.
Execute a msg of passed poll .
deps
DepsMut
env
Env
poll_id
u64
deps
DepsMut
env
Env
poll_id
u64