light_sdk/cpi/mod.rs
1//!
2//!
3//! To create, update, or close compressed accounts,
4//! programs need to invoke the light system program via cross program invocation (cpi).
5//!
6//! ```ignore
7//! declare_id!("2tzfijPBGbrR5PboyFUFKzfEoLTwdDSHUjANCw929wyt");
8//! pub const LIGHT_CPI_SIGNER: CpiSigner =
9//! derive_light_cpi_signer!("2tzfijPBGbrR5PboyFUFKzfEoLTwdDSHUjANCw929wyt");
10//!
11//! let light_cpi_accounts = CpiAccounts::new(
12//! ctx.accounts.fee_payer.as_ref(),
13//! ctx.remaining_accounts,
14//! crate::LIGHT_CPI_SIGNER,
15//! )
16//! .map_err(ProgramError::from)?;
17//!
18//! let (address, address_seed) = derive_address(
19//! &[b"compressed", name.as_bytes()],
20//! &address_tree_info.get_tree_pubkey(&light_cpi_accounts)?,
21//! &crate::ID,
22//! );
23//! let new_address_params = address_tree_info.into_new_address_params_packed(address_seed);
24//!
25//! let mut my_compressed_account = LightAccount::<'_, MyCompressedAccount>::new_init(
26//! &crate::ID,
27//! Some(address),
28//! output_tree_index,
29//! );
30//!
31//! my_compressed_account.name = name;
32//! my_compressed_account.nested = NestedData::default();
33//!
34//! let cpi_inputs = CpiInputs::new_with_address(
35//! proof,
36//! // add compressed accounts to create, update or close here
37//! vec![my_compressed_account
38//! .to_account_info()
39//! .map_err(ProgramError::from)?],
40//! // add new addresses here
41//! // (existing addresses are part of the account info and must not be added here)
42//! vec![new_address_params],
43//! );
44//!
45//! cpi_inputs
46//! .invoke_light_system_program(light_cpi_accounts)
47//! .map_err(ProgramError::from)?;
48//! ```
49
50mod accounts;
51#[cfg(feature = "small_ix")]
52mod accounts_small_ix;
53mod invoke;
54
55pub use accounts::*;
56#[cfg(feature = "small_ix")]
57pub use accounts_small_ix::*;
58pub use invoke::*;
59/// Derives cpi signer and bump to invoke the light system program at compile time.
60pub use light_sdk_macros::derive_light_cpi_signer;
61/// Contains program id, derived cpi signer, and bump,
62pub use light_sdk_types::CpiSigner;