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
use {
    super::platform_gate_fn,
    crate::{constants::Action, state::*},
    anchor_lang::prelude::*,
};

#[derive(Accounts)]
pub struct PlatformGate<'info> {
    #[account(mut)]
    pub project: Account<'info, Project>,
    #[account()]
    pub authority: Signer<'info>,
    #[account(mut)]
    pub payer: Signer<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub vault: AccountInfo<'info>,
    #[account(mut)]
    pub delegate_authority: Option<Account<'info, DelegateAuthority>>,
    pub system_program: Program<'info, System>,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
pub struct PlatformGateArgs<'info> {
    pub action: Action<'info>,
    pub service: Option<(u8, Pubkey)>,
}

pub fn platform_gate<'info>(ctx: Context<PlatformGate>, args: PlatformGateArgs) -> Result<()> {
    platform_gate_fn(
        args.action,
        args.service,
        &ctx.accounts.project,
        ctx.accounts.authority.key(),
        ctx.accounts.payer.to_account_info(),
        ctx.accounts.vault.to_account_info(),
        &ctx.accounts.delegate_authority,
        ctx.accounts.system_program.to_account_info(),
    )
}