Skip to content

Instantly share code, notes, and snippets.

// Old code
pub fn test_ix<'info>(
ctx: Context<'_, '_, '_, 'info, TestIx<'info>>,
test1: u8,
test2: u16,
test3: u32,
) -> Result<()> {
msg!("test1 {}", test1);
msg!("test2 {}", test2);
msg!("test3 {}", test3);
// Old code
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(mut)]
wallet: Signer<'info>,
#[account(init, payer=wallet, space=100)]
foo_account: Account<'info, FooAccount>,
system_program: Program<'info, System>,
}
// Old code
pub fn test_ix<'info>(
_ctx: Context<'_, '_, '_, 'info, TestIx<'info>>,
) -> Result<()> {
Ok(())
}
// New code
pub fn test_ix<'info>(
_ctx: Context<'_, '_, '_, 'info, TestIx<'info>>,
// Old code
#[derive(Accounts)]
pub struct PrintAccounts<'info> {
foo_account: Account<'info, FooAccount>,
bar_account: Account<'info, BarAccount>,
}
// New code
#[derive(Accounts)]
pub struct PrintAccounts<'info> {
// Old code
pub fn print_accounts<'info>(
ctx: Context<'_, '_, '_, 'info, PrintAccounts<'info>>,
) -> Result<()> {
Ok(())
}
#[derive(Accounts)]
pub struct PrintAccounts<'info> {
foo_account: Account<'info, FooAccount>,
// Old code
#[derive(Accounts)]
pub struct TestIx<'info> {
account1: UncheckedAccount<'info>,
}
// New code
#[derive(Accounts)]
pub struct TestIx<'info> {
account1: UncheckedAccount<'info>,
// Old code
#[derive(Accounts)]
pub struct PrintAccounts<'info> {
foo_account: Account<'info, FooAccount>,
#[account(mut)]
bar_account: Account<'info, BarAccount>,
}
// New code
#[derive(Accounts)]
// Old code
pub fn test_ix<'info>(
ctx: Context<'_, '_, '_, 'info, TestIx<'info>>,
test1: Option<bool>,
test2: Option<bool>,
) -> Result<()> {
Ok(())
}
// New code
// Old code
#[derive(Accounts)]
pub struct PrintAccounts<'info> {
foo_account: Account<'info, FooAccount>,
bar_account: Account<'info, BarAccount>,
}
// New code
#[derive(Accounts)]
pub struct PrintAccounts<'info> {
// Old code
#[account]
pub struct FooAccount {
pubkey: Option<Pubkey>,
}
// New code
#[account]
pub struct FooAccount {
pubkey: Option<Pubkey>,