bolt_component/
lib.rs

1use anchor_lang::prelude::*;
2
3declare_id!("CmP2djJgABZ4cRokm4ndxuq6LerqpNHLBsaUv2XKEJua");
4
5#[program]
6pub mod bolt_component {
7    use super::*;
8
9    pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {
10        Ok(())
11    }
12
13    pub fn destroy(_ctx: Context<Destroy>) -> Result<()> {
14        Ok(())
15    }
16
17    pub fn update(_ctx: Context<Update>, _data: Vec<u8>) -> Result<()> {
18        Ok(())
19    }
20
21    pub fn update_with_session(_ctx: Context<UpdateWithSession>, _data: Vec<u8>) -> Result<()> {
22        Ok(())
23    }
24
25    #[derive(Accounts)]
26    pub struct Update<'info> {
27        #[account()]
28        pub cpi_auth: Signer<'info>,
29        #[account(mut)]
30        /// CHECK: The component to update
31        pub bolt_component: UncheckedAccount<'info>,
32        #[account()]
33        /// CHECK: The authority of the component
34        pub authority: Signer<'info>,
35    }
36
37    #[derive(Accounts)]
38    pub struct UpdateWithSession<'info> {
39        #[account()]
40        pub cpi_auth: Signer<'info>,
41        #[account(mut)]
42        /// CHECK: The component to update
43        pub bolt_component: UncheckedAccount<'info>,
44        #[account()]
45        /// CHECK: The authority of the component
46        pub authority: Signer<'info>,
47        #[account()]
48        /// CHECK: The session token
49        pub session_token: UncheckedAccount<'info>,
50    }
51}
52
53#[derive(Accounts)]
54pub struct Initialize<'info> {
55    #[account()]
56    pub cpi_auth: Signer<'info>,
57    #[account(mut)]
58    pub payer: Signer<'info>,
59    #[account(mut)]
60    /// CHECK: The component to initialize
61    pub data: UncheckedAccount<'info>,
62    #[account()]
63    /// CHECK: A generic entity account
64    pub entity: AccountInfo<'info>,
65    #[account()]
66    /// CHECK: The authority of the component
67    pub authority: AccountInfo<'info>,
68    pub system_program: Program<'info, System>,
69}
70
71#[derive(Accounts)]
72pub struct Destroy<'info> {
73    #[account()]
74    pub cpi_auth: Signer<'info>,
75    #[account()]
76    pub authority: Signer<'info>,
77    #[account(mut)]
78    /// CHECK: The receiver of the component
79    pub receiver: AccountInfo<'info>,
80    #[account()]
81    /// CHECK: The entity to destroy the component on
82    pub entity: AccountInfo<'info>,
83    #[account(mut)]
84    /// CHECK: The component to destroy
85    pub component: UncheckedAccount<'info>,
86    #[account()]
87    /// CHECK: The component program data
88    pub component_program_data: AccountInfo<'info>,
89    pub system_program: Program<'info, System>,
90}
91
92#[derive(InitSpace, AnchorSerialize, AnchorDeserialize, Default, Copy, Clone)]
93pub struct BoltMetadata {
94    pub authority: Pubkey,
95}
96
97#[cfg(feature = "cpi")]
98pub trait CpiContextBuilder<'a, 'b, 'c, 'info>:
99    ToAccountMetas + ToAccountInfos<'info> + Sized
100{
101    fn build_cpi_context(
102        self,
103        program: AccountInfo<'info>,
104        signer_seeds: &'a [&'b [&'c [u8]]],
105    ) -> CpiContext<'a, 'b, 'c, 'info, Self>;
106}
107
108#[cfg(feature = "cpi")]
109impl<'a, 'b, 'c, 'info> CpiContextBuilder<'a, 'b, 'c, 'info> for cpi::accounts::Update<'info> {
110    fn build_cpi_context(
111        self,
112        program: AccountInfo<'info>,
113        signer_seeds: &'a [&'b [&'c [u8]]],
114    ) -> CpiContext<'a, 'b, 'c, 'info, Self> {
115        let cpi_program = program.to_account_info();
116        CpiContext::new_with_signer(cpi_program, self, signer_seeds)
117    }
118}
119
120#[cfg(feature = "cpi")]
121impl<'a, 'b, 'c, 'info> CpiContextBuilder<'a, 'b, 'c, 'info>
122    for cpi::accounts::UpdateWithSession<'info>
123{
124    fn build_cpi_context(
125        self,
126        program: AccountInfo<'info>,
127        signer_seeds: &'a [&'b [&'c [u8]]],
128    ) -> CpiContext<'a, 'b, 'c, 'info, Self> {
129        let cpi_program = program.to_account_info();
130        CpiContext::new_with_signer(cpi_program, self, signer_seeds)
131    }
132}