solana_workflow/instructions/
create_mission.rs

1use anchor_lang::prelude::*;
2
3use crate::pda::*;
4
5#[derive(Accounts)]
6#[instruction(mission_id: u64, vote_data_id: u64)]
7pub struct CreateMission<'info> {
8    #[account(mut)]
9    pub user: Signer<'info>,
10    #[account(
11        init_if_needed, 
12        payer = user, 
13        space=1000,
14        seeds=[b"mission", user.key().as_ref(), &mission_id.to_le_bytes()], 
15        bump
16    )]
17    pub mission: Account<'info, Mission>,
18    #[account(
19        init_if_needed, 
20        payer = user, 
21        space=1000,
22        seeds=[b"vote_data", mission.key().as_ref(), &vote_data_id.to_le_bytes(), &[0]], 
23        bump
24    )]
25    /// CHECK:
26    pub vote_data: Account<'info, VoteData>,
27    pub system_program: Program<'info, System>,
28}
29
30pub fn create_mission(
31    ctx: Context<CreateMission>,
32    workflow_id: u64,
33    mission_id: u64,
34    title: String,
35    content: String,
36    current_vote_data: Pubkey,
37    checkpoint_id: u16,
38    vote_data_id: u64,
39) -> Result<()> {
40    let mission = &mut ctx.accounts.mission;
41    Mission::create(
42        mission,
43        workflow_id,
44        mission_id,
45        title,
46        content,
47        current_vote_data,
48    )?;
49    
50    let vote_data = &mut ctx.accounts.vote_data;
51    // cpi to vote_machine
52    vote_data.checkpoint_id = checkpoint_id;
53    vote_data.id = vote_data_id;
54
55    // for to create variable
56    Ok(())
57}