Skip to content

Commit ced4942

Browse files
committed
Merge remote-tracking branch 'origin/anchor-free-functions'
2 parents e760c2a + ba3f793 commit ced4942

106 files changed

Lines changed: 1478 additions & 1499 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

basics/account-data/anchor/programs/anchor-program-example/src/instructions/create.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{constants::ANCHOR_DISCRIMINATOR_SIZE, state::AddressInfo};
22
use anchor_lang::prelude::*;
33

44
#[derive(Accounts)]
5-
pub struct CreateAddressInfo<'info> {
5+
pub struct CreateAddressInfoAccountConstraints<'info> {
66
#[account(mut)]
77
payer: Signer<'info>,
88

@@ -15,14 +15,14 @@ pub struct CreateAddressInfo<'info> {
1515
system_program: Program<'info, System>,
1616
}
1717

18-
pub fn create_address_info(
19-
ctx: Context<CreateAddressInfo>,
18+
pub fn handle_create_address_info(
19+
context: Context<CreateAddressInfoAccountConstraints>,
2020
name: String,
2121
house_number: u8,
2222
street: String,
2323
city: String,
2424
) -> Result<()> {
25-
*ctx.accounts.address_info = AddressInfo {
25+
*context.accounts.address_info = AddressInfo {
2626
name,
2727
house_number,
2828
street,

basics/account-data/anchor/programs/anchor-program-example/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ pub mod account_data_anchor_program {
1212
use super::*;
1313

1414
pub fn create_address_info(
15-
ctx: Context<CreateAddressInfo>,
15+
context: Context<CreateAddressInfoAccountConstraints>,
1616
name: String,
1717
house_number: u8,
1818
street: String,
1919
city: String,
2020
) -> Result<()> {
21-
create::create_address_info(ctx, name, house_number, street, city)
21+
create::handle_create_address_info(context, name, house_number, street, city)
2222
}
2323
}

basics/checking-accounts/anchor/programs/anchor-program-example/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ declare_id!("ECWPhR3rJbaPfyNFgphnjxSEexbTArc7vxD8fnW6tgKw");
66
pub mod checking_account_program {
77
use super::*;
88

9-
pub fn check_accounts(_ctx: Context<CheckingAccounts>) -> Result<()> {
9+
pub fn check_accounts(_context: Context<CheckingAccountsAccountConstraints>) -> Result<()> {
1010
Ok(())
1111
}
1212
}
1313

1414
// Account validation in Anchor is done using the types and constraints specified in the #[derive(Accounts)] structs
1515
// This is a simple example and does not include all possible constraints and types
1616
#[derive(Accounts)]
17-
pub struct CheckingAccounts<'info> {
17+
pub struct CheckingAccountsAccountConstraints<'info> {
1818
payer: Signer<'info>, // checks account is signer
1919

2020
/// CHECK: No checks performed, example of an unchecked account

basics/close-account/anchor/programs/close-account/src/instructions/close_user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ pub struct CloseUserContext<'info> {
1818
pub user_account: Account<'info, UserState>,
1919
}
2020

21-
pub fn close_user(_ctx: Context<CloseUserContext>) -> Result<()> {
21+
pub fn handle_close_user(_context: Context<CloseUserContext>) -> Result<()> {
2222
Ok(())
2323
}

basics/close-account/anchor/programs/close-account/src/instructions/create_user.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ pub struct CreateUserContext<'info> {
2020
pub system_program: Program<'info, System>,
2121
}
2222

23-
pub fn create_user(ctx: Context<CreateUserContext>, name: String) -> Result<()> {
24-
*ctx.accounts.user_account = UserState {
25-
bump: ctx.bumps.user_account,
26-
user: ctx.accounts.user.key(),
23+
pub fn handle_create_user(context: Context<CreateUserContext>, name: String) -> Result<()> {
24+
*context.accounts.user_account = UserState {
25+
bump: context.bumps.user_account,
26+
user: context.accounts.user.key(),
2727
name,
2828
};
2929
Ok(())

basics/close-account/anchor/programs/close-account/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ declare_id!("99TQtoDdQ5NS2v5Ppha93aqEmv3vV9VZVfHTP5rGST3c");
99
pub mod close_account_program {
1010
use super::*;
1111

12-
pub fn create_user(ctx: Context<CreateUserContext>, name: String) -> Result<()> {
13-
create_user::create_user(ctx, name)
12+
pub fn create_user(context: Context<CreateUserContext>, name: String) -> Result<()> {
13+
create_user::handle_create_user(context, name)
1414
}
1515

16-
pub fn close_user(ctx: Context<CloseUserContext>) -> Result<()> {
17-
close_user::close_user(ctx)
16+
pub fn close_user(context: Context<CloseUserContext>) -> Result<()> {
17+
close_user::handle_close_user(context)
1818
}
1919
}

basics/counter/anchor/programs/counter_anchor/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ declare_id!("BmDHboaj1kBUoinJKKSRqKfMeRKJqQqEbUj1VgzeQe4A");
66
pub mod counter_anchor {
77
use super::*;
88

9-
pub fn initialize_counter(_ctx: Context<InitializeCounter>) -> Result<()> {
9+
pub fn initialize_counter(_context: Context<InitializeCounterAccountConstraints>) -> Result<()> {
1010
Ok(())
1111
}
1212

13-
pub fn increment(ctx: Context<Increment>) -> Result<()> {
14-
ctx.accounts.counter.count = ctx.accounts.counter.count.checked_add(1).unwrap();
13+
pub fn increment(context: Context<IncrementAccountConstraints>) -> Result<()> {
14+
context.accounts.counter.count = context.accounts.counter.count.checked_add(1).unwrap();
1515
Ok(())
1616
}
1717
}
1818

1919
#[derive(Accounts)]
20-
pub struct InitializeCounter<'info> {
20+
pub struct InitializeCounterAccountConstraints<'info> {
2121
#[account(mut)]
2222
pub payer: Signer<'info>,
2323

@@ -31,7 +31,7 @@ pub struct InitializeCounter<'info> {
3131
}
3232

3333
#[derive(Accounts)]
34-
pub struct Increment<'info> {
34+
pub struct IncrementAccountConstraints<'info> {
3535
#[account(mut)]
3636
pub counter: Account<'info, Counter>,
3737
}

basics/create-account/anchor/programs/create-system-account/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ declare_id!("ARVNCsYKDQsCLHbwUTJLpFXVrJdjhWZStyzvxmKe2xHi");
77
pub mod create_system_account {
88
use super::*;
99

10-
pub fn create_system_account(ctx: Context<CreateSystemAccount>) -> Result<()> {
10+
pub fn create_system_account(context: Context<CreateSystemAccountAccountConstraints>) -> Result<()> {
1111
msg!("Program invoked. Creating a system account...");
1212
msg!(
1313
" New public key will be: {}",
14-
&ctx.accounts.new_account.key().to_string()
14+
&context.accounts.new_account.key().to_string()
1515
);
1616

1717
// The minimum lamports for rent exemption
1818
let lamports = (Rent::get()?).minimum_balance(0);
1919

2020
create_account(
2121
CpiContext::new(
22-
ctx.accounts.system_program.key(),
22+
context.accounts.system_program.key(),
2323
CreateAccount {
24-
from: ctx.accounts.payer.to_account_info(), // From pubkey
25-
to: ctx.accounts.new_account.to_account_info(), // To pubkey
24+
from: context.accounts.payer.to_account_info(), // From pubkey
25+
to: context.accounts.new_account.to_account_info(), // To pubkey
2626
},
2727
),
2828
lamports, // Lamports
2929
0, // Space
30-
&ctx.accounts.system_program.key(), // Owner Program
30+
&context.accounts.system_program.key(), // Owner Program
3131
)?;
3232

3333
msg!("Account created succesfully.");
@@ -36,7 +36,7 @@ pub mod create_system_account {
3636
}
3737

3838
#[derive(Accounts)]
39-
pub struct CreateSystemAccount<'info> {
39+
pub struct CreateSystemAccountAccountConstraints<'info> {
4040
#[account(mut)]
4141
pub payer: Signer<'info>,
4242
#[account(mut)]

basics/cross-program-invocation/anchor/programs/hand/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use lever::program::Lever;
1313
pub mod hand {
1414
use super::*;
1515

16-
pub fn pull_lever(ctx: Context<PullLever>, name: String) -> Result<()> {
16+
pub fn pull_lever(context: Context<PullLeverAccountConstraints>, name: String) -> Result<()> {
1717
let cpi_ctx = CpiContext::new(
18-
ctx.accounts.lever_program.key(),
18+
context.accounts.lever_program.key(),
1919
SwitchPower {
20-
power: ctx.accounts.power.to_account_info(),
20+
power: context.accounts.power.to_account_info(),
2121
},
2222
);
2323
switch_power(cpi_ctx, name)?;
@@ -26,7 +26,7 @@ pub mod hand {
2626
}
2727

2828
#[derive(Accounts)]
29-
pub struct PullLever<'info> {
29+
pub struct PullLeverAccountConstraints<'info> {
3030
#[account(mut)]
3131
pub power: Account<'info, PowerStatus>,
3232
pub lever_program: Program<'info, Lever>,

basics/cross-program-invocation/anchor/programs/lever/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ declare_id!("E64FVeubGC4NPNF2UBJYX4AkrVowf74fRJD9q6YhwstN");
66
pub mod lever {
77
use super::*;
88

9-
pub fn initialize(_ctx: Context<InitializeLever>) -> Result<()> {
9+
pub fn initialize(_mut context: Context<InitializeLeverAccountConstraints>) -> Result<()> {
1010
Ok(())
1111
}
1212

13-
pub fn switch_power(ctx: Context<SetPowerStatus>, name: String) -> Result<()> {
14-
let power = &mut ctx.accounts.power;
13+
pub fn switch_power(mut context: Context<SetPowerStatusAccountConstraints>, name: String) -> Result<()> {
14+
let power = &mut context.accounts.power;
1515
power.is_on = !power.is_on;
1616

1717
msg!("{} is pulling the power switch!", &name);
@@ -26,7 +26,7 @@ pub mod lever {
2626
}
2727

2828
#[derive(Accounts)]
29-
pub struct InitializeLever<'info> {
29+
pub struct InitializeLeverAccountConstraints<'info> {
3030
#[account(init, payer = user, space = PowerStatus::DISCRIMINATOR.len() + PowerStatus::INIT_SPACE)]
3131
pub power: Account<'info, PowerStatus>,
3232
#[account(mut)]
@@ -35,7 +35,7 @@ pub struct InitializeLever<'info> {
3535
}
3636

3737
#[derive(Accounts)]
38-
pub struct SetPowerStatus<'info> {
38+
pub struct SetPowerStatusAccountConstraints<'info> {
3939
#[account(mut)]
4040
pub power: Account<'info, PowerStatus>,
4141
}

0 commit comments

Comments
 (0)