Voting System
Objective
Logic
Mathematical Model
votes_yes = Σ NFT holdings of all "yes" voters
votes_no = Σ NFT holdings of all "no" votersAnchor Code
pub fn vote(ctx: Context<Vote>, proposal_id: u64, vote_yes: bool) -> Result<()> {
let nft_account = &ctx.accounts.nft_account;
let vote_weight = nft_account.amount;
if vote_yes {
ctx.accounts.proposal.votes_yes += vote_weight;
} else {
ctx.accounts.proposal.votes_no += vote_weight;
}
Ok(())
}
Security Notes
Last updated