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(mut)]
28        /// CHECK: The component to update
29        pub bolt_component: UncheckedAccount<'info>,
30        #[account()]
31        /// CHECK: The authority of the component
32        pub authority: Signer<'info>,
33        #[account(address = anchor_lang::solana_program::sysvar::instructions::id())]
34        /// CHECK: The instruction sysvar
35        pub instruction_sysvar_account: AccountInfo<'info>,
36    }
37
38    #[derive(Accounts)]
39    pub struct UpdateWithSession<'info> {
40        #[account(mut)]
41        /// CHECK: The component to update
42        pub bolt_component: UncheckedAccount<'info>,
43        #[account()]
44        /// CHECK: The authority of the component
45        pub authority: Signer<'info>,
46        #[account(address = anchor_lang::solana_program::sysvar::instructions::id())]
47        /// CHECK: The instruction sysvar
48        pub instruction_sysvar_account: AccountInfo<'info>,
49        #[account()]
50        /// CHECK: The session token
51        pub session_token: UncheckedAccount<'info>,
52    }
53}
54
55#[derive(Accounts)]
56pub struct Initialize<'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    #[account(address = anchor_lang::solana_program::sysvar::instructions::id())]
69    /// CHECK: The instruction sysvar
70    pub instruction_sysvar_account: AccountInfo<'info>,
71    pub system_program: Program<'info, System>,
72}
73
74#[derive(Accounts)]
75pub struct Destroy<'info> {
76    #[account()]
77    pub authority: Signer<'info>,
78    #[account(mut)]
79    /// CHECK: The receiver of the component
80    pub receiver: AccountInfo<'info>,
81    #[account()]
82    /// CHECK: The entity to destroy the component on
83    pub entity: AccountInfo<'info>,
84    #[account(mut)]
85    /// CHECK: The component to destroy
86    pub component: UncheckedAccount<'info>,
87    #[account()]
88    /// CHECK: The component program data
89    pub component_program_data: AccountInfo<'info>,
90    #[account(address = anchor_lang::solana_program::sysvar::instructions::id())]
91    /// CHECK: The instruction sysvar
92    pub instruction_sysvar_account: AccountInfo<'info>,
93    pub system_program: Program<'info, System>,
94}
95
96#[derive(InitSpace, AnchorSerialize, AnchorDeserialize, Default, Copy, Clone)]
97pub struct BoltMetadata {
98    pub authority: Pubkey,
99}
100
101#[cfg(feature = "cpi")]
102pub trait CpiContextBuilder<'info>: ToAccountMetas + ToAccountInfos<'info> + Sized {
103    fn build_cpi_context(
104        self,
105        program: AccountInfo<'info>,
106    ) -> CpiContext<'info, 'info, 'info, 'info, Self>;
107}
108
109#[cfg(feature = "cpi")]
110impl<'info> CpiContextBuilder<'info> for cpi::accounts::Update<'info> {
111    fn build_cpi_context(
112        self,
113        program: AccountInfo<'info>,
114    ) -> CpiContext<'info, 'info, 'info, 'info, Self> {
115        let cpi_program = program.to_account_info();
116        CpiContext::new(cpi_program, self)
117    }
118}
119
120#[cfg(feature = "cpi")]
121impl<'info> CpiContextBuilder<'info> for cpi::accounts::UpdateWithSession<'info> {
122    fn build_cpi_context(
123        self,
124        program: AccountInfo<'info>,
125    ) -> CpiContext<'info, 'info, 'info, 'info, Self> {
126        let cpi_program = program.to_account_info();
127        CpiContext::new(cpi_program, self)
128    }
129}