light_sdk/
legacy.rs

1//! Legacy types re-imported from programs which should be removed as soon as
2//! possible.
3
4use light_compressed_account::instruction_data::{
5    compressed_proof::CompressedProof,
6    cpi_context::CompressedCpiContext,
7    data::{NewAddressParamsPacked, OutputCompressedAccountWithPackedContext},
8    invoke_cpi::InstructionDataInvokeCpi,
9};
10
11use crate::AccountInfo;
12
13/// Helper function to create data for creating a single PDA.
14pub fn create_cpi_inputs_for_new_account(
15    proof: CompressedProof,
16    new_address_params: NewAddressParamsPacked,
17    compressed_pda: OutputCompressedAccountWithPackedContext,
18    cpi_context: Option<CompressedCpiContext>,
19) -> InstructionDataInvokeCpi {
20    InstructionDataInvokeCpi {
21        proof: Some(proof),
22        new_address_params: vec![new_address_params],
23        relay_fee: None,
24        input_compressed_accounts_with_merkle_context: vec![],
25        output_compressed_accounts: vec![compressed_pda],
26        compress_or_decompress_lamports: None,
27        is_compress: false,
28        cpi_context,
29    }
30}
31
32pub trait InvokeAccounts<'info> {
33    fn get_registered_program_pda(&self) -> &AccountInfo<'info>;
34    fn get_noop_program(&self) -> &AccountInfo<'info>;
35    fn get_account_compression_authority(&self) -> &AccountInfo<'info>;
36    fn get_account_compression_program(&self) -> &AccountInfo<'info>;
37    fn get_system_program(&self) -> AccountInfo<'info>;
38    fn get_compressed_sol_pda(&self) -> Option<&AccountInfo<'info>>;
39    fn get_compression_recipient(&self) -> Option<&AccountInfo<'info>>;
40}
41
42pub trait LightSystemAccount<'info> {
43    fn get_light_system_program(&self) -> AccountInfo<'info>;
44}
45
46pub trait SignerAccounts<'info> {
47    fn get_fee_payer(&self) -> AccountInfo<'info>;
48    fn get_authority(&self) -> &AccountInfo<'info>;
49}
50
51// Only used within the systemprogram
52pub trait InvokeCpiContextAccountMut<'info> {
53    fn get_cpi_context_account_mut(&mut self) -> &mut Option<AccountInfo<'info>>;
54}
55
56pub trait InvokeCpiContextAccount<'info> {
57    fn get_cpi_context_account(&self) -> Option<&AccountInfo<'info>>;
58}
59
60pub trait InvokeCpiAccounts<'info> {
61    fn get_invoking_program(&self) -> AccountInfo<'info>;
62}
63
64pub trait LightTraits<'info>:
65    InvokeAccounts<'info>
66    + LightSystemAccount<'info>
67    + SignerAccounts<'info>
68    + InvokeCpiContextAccount<'info>
69    + InvokeCpiAccounts<'info>
70{
71}
72
73impl<'info, T> LightTraits<'info> for T where
74    T: InvokeAccounts<'info>
75        + LightSystemAccount<'info>
76        + SignerAccounts<'info>
77        + InvokeCpiContextAccount<'info>
78        + InvokeCpiAccounts<'info>
79{
80}