pub fn snapshot_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())?;

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

    let current_seconds = env.block.time.seconds();
    let time_to_end = a_poll.end_time - current_seconds;

    if time_to_end > config.snapshot_period {
        return Err(StdError::generic_err("Cannot snapshot at this time"));
    }

    if a_poll.staked_amount.is_some() {
        return Err(StdError::generic_err("Snapshot has already occurred"));
    }

    // store the current staked amount for quorum calculation
    let state: State = state_store(deps.storage).load()?;

    let total_locked_balance = state.total_deposit + state.pending_voting_rewards;
    let staked_amount = load_token_balance(
        &deps.querier,
        deps.api.addr_humanize(&config.mirror_token)?.to_string(),
        &state.contract_addr,
    )?
    .checked_sub(total_locked_balance)?;

    a_poll.staked_amount = Some(staked_amount);

    poll_store(deps.storage).save(&poll_id.to_be_bytes(), &a_poll)?;

    Ok(Response::new().add_attributes(vec![
        attr("action", "snapshot_poll"),
        attr("poll_id", poll_id.to_string()),
        attr("staked_amount", staked_amount),
    ]))
}
/*
 * SnapshotPoll is used to take a snapshot of the staked amount for quorum calculation
 */
SnapshotPoll is used to take a snapshot of the staked amount for quorum calculation
SnapshotPoll is used to take a snapshot of the staked amount for quorum calculation
pub fn snapshot_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())?;
    if a_poll.status != PollStatus::InProgress {
        return Err(StdError::generic_err("Poll is not in progress"));
    }
    let current_seconds = env.block.time.seconds();
    let time_to_end = a_poll.end_time - current_seconds;
    if time_to_end > config.snapshot_period {
        return Err(StdError::generic_err("Cannot snapshot at this time"));
    }
    if a_poll.staked_amount.is_some() {
        return Err(StdError::generic_err("Snapshot has already occurred"));
    }
    // store the current staked amount for quorum calculation
    let state: State = state_store(deps.storage).load()?;
    let total_locked_balance = state.total_deposit + state.pending_voting_rewards;
    let staked_amount = load_token_balance(
        &deps.querier,
        deps.api.addr_humanize(&config.mirror_token)?.to_string(),
        &state.contract_addr,
    )?
    .checked_sub(total_locked_balance)?;
    a_poll.staked_amount = Some(staked_amount);
    poll_store(deps.storage).save(&poll_id.to_be_bytes(), &a_poll)?;
    Ok(Response::new().add_attributes(vec![
        attr("action", "snapshot_poll"),
        attr("poll_id", poll_id.to_string()),
        attr("staked_amount", staked_amount),
    ]))
}
pub fn snapshot_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 ( ) ) ? ; if a_poll . status != PollStatus :: InProgress { return Err ( StdError :: generic_err ( " " ) ) ; } let current_seconds = env . block . time . seconds ( ) ; let time_to_end = a_poll . end_time - current_seconds ; if time_to_end > config . snapshot_period { return Err ( StdError :: generic_err ( " " ) ) ; } if a_poll . staked_amount . is_some ( ) { return Err ( StdError :: generic_err ( " " ) ) ; } // store the current staked amount for quorum calculation let state : State = state_store ( deps . storage ) . load ( ) ? ; let total_locked_balance = state . total_deposit + state . pending_voting_rewards ; let staked_amount = load_token_balance ( & deps . querier , deps . api . addr_humanize ( & config . mirror_token ) ? . to_string ( ) , & state . contract_addr , ) ? . checked_sub ( total_locked_balance ) ? ; a_poll . staked_amount = Some ( staked_amount ) ; poll_store ( deps . storage ) . save ( & poll_id . to_be_bytes ( ) , & a_poll ) ? ; Ok ( Response :: new ( ) . add_attributes ( vec ! [ attr ( " " " " ) attr ( " " poll_id to_string ( ) ) attr ( " " staked_amount ) ] ) ) }
SnapshotPoll is used to take a snapshot of the staked amount for quorum calculation
SnapshotPoll is used to take a snapshot of the staked amount for quorum calculation
deps
DepsMut
env
Env
poll_id
u64
deps
DepsMut
env
Env
poll_id
u64