-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_poll.rs
52 lines (45 loc) · 1.2 KB
/
start_poll.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use anchor_lang::prelude::*;
use crate::{Member, Poll, Project, MEMBER_SEED, POLL_SEED};
#[derive(Accounts)]
#[instruction(pull_request: u32)]
pub struct StartPoll<'info> {
#[account(mut)]
pub user: Signer<'info>,
pub project: Account<'info, Project>,
#[account(
seeds = [
MEMBER_SEED.as_bytes(),
project.key().as_ref(),
user.key().as_ref(),
],
bump = member.bump
)]
pub member: Account<'info, Member>,
#[account(
init,
payer = user,
space = Poll::INIT_SPACE + 8,
seeds = [
POLL_SEED.as_bytes(),
pull_request.to_le_bytes().as_ref(),
project.key().as_ref(),
],
bump
)]
pub poll: Account<'info, Poll>,
pub system_program: Program<'info, System>,
}
impl<'info> StartPoll<'info> {
pub fn start_poll(&mut self, pull_request: u32, close_time: u64) -> Result<()> {
self.poll.set_inner(Poll {
user: self.user.key(),
pull_request,
project: self.project.key(),
votes: 0,
close_time,
rejections: 0,
bump: self.poll.bump,
});
Ok(())
}
}