pub fn snapshot_poll(deps: DepsMut, env: Env, poll_id: u64) -> Result<Response, ContractError> {
    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(ContractError::PollNotInProgress {});
    }

    let time_to_end = a_poll.end_height - env.block.height;

    if time_to_end > config.snapshot_period {
        return Err(ContractError::SnapshotHeight {});
    }

    if a_poll.staked_amount.is_some() {
        return Err(ContractError::SnapshotAlreadyOccurred {});
    }

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

    let staked_amount = query_token_balance(
        &deps.querier,
        deps.api.addr_humanize(&config.whale_token)?,
        deps.api.addr_humanize(&state.contract_addr)?,
    )?
    .checked_sub(state.total_deposit)?;

    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().as_str()),
        attr("staked_amount", staked_amount.to_string().as_str()),
    ]))
}
/// 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) -> Result<Response, ContractError> {
    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(ContractError::PollNotInProgress {});
    }
    let time_to_end = a_poll.end_height - env.block.height;
    if time_to_end > config.snapshot_period {
        return Err(ContractError::SnapshotHeight {});
    }
    if a_poll.staked_amount.is_some() {
        return Err(ContractError::SnapshotAlreadyOccurred {});
    }
    // store the current staked amount for quorum calculation
    let state: State = state_store(deps.storage).load()?;
    let staked_amount = query_token_balance(
        &deps.querier,
        deps.api.addr_humanize(&config.whale_token)?,
        deps.api.addr_humanize(&state.contract_addr)?,
    )?
    .checked_sub(state.total_deposit)?;
    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().as_str()),
        attr("staked_amount", staked_amount.to_string().as_str()),
    ]))
}
pub fn snapshot_poll ( deps : DepsMut , env : Env , poll_id : u64 ) -> Result < Response , ContractError > { 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 ( ContractError :: PollNotInProgress { } ) ; } let time_to_end = a_poll . end_height - env . block . height ; if time_to_end > config . snapshot_period { return Err ( ContractError :: SnapshotHeight { } ) ; } if a_poll . staked_amount . is_some ( ) { return Err ( ContractError :: SnapshotAlreadyOccurred { } ) ; } // store the current staked amount for quorum calculation let state : State = state_store ( deps . storage ) . load ( ) ? ; let staked_amount = query_token_balance ( & deps . querier , deps . api . addr_humanize ( & config . whale_token ) ? , deps . api . addr_humanize ( & state . contract_addr ) ? , ) ? . checked_sub ( state . total_deposit ) ? ; 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 ( ) as_str ( ) ) attr ( " " staked_amount to_string ( ) as_str ( ) ) ] ) ) }
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