Skip to content

Commit

Permalink
lang: Untabify (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante authored Jul 13, 2021
1 parent e4e6438 commit a65665f
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions lang/syn/src/codegen/program/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
accounts: &[AccountInfo],
ix_data: &[u8],
) -> ProgramResult {
// Deserialize instruction.
let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
let instruction::state::#variant_arm = ix;
// Deserialize instruction.
let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
let instruction::state::#variant_arm = ix;

// Load state.
// Load state.
let mut remaining_accounts: &[AccountInfo] = accounts;
if remaining_accounts.is_empty() {
return Err(anchor_lang::__private::ErrorCode::AccountNotEnoughKeys.into());
Expand Down Expand Up @@ -398,12 +398,12 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
accounts: &[AccountInfo],
ix_data: &[u8],
) -> ProgramResult {
// Deserialize instruction.
let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
let instruction::state::#variant_arm = ix;
// Deserialize instruction.
let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
let instruction::state::#variant_arm = ix;

// Load state.
// Load state.
let mut remaining_accounts: &[AccountInfo] = accounts;
if remaining_accounts.is_empty() {
return Err(anchor_lang::__private::ErrorCode::AccountNotEnoughKeys.into());
Expand Down Expand Up @@ -498,14 +498,14 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
}
};

let deserialize_instruction = quote! {
#args_struct
let ix = Args::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
let Args {
#(#ix_arg_names),*
} = ix;
};
let deserialize_instruction = quote! {
#args_struct
let ix = Args::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
let Args {
#(#ix_arg_names),*
} = ix;
};

if ix.has_receiver {
quote! {
Expand All @@ -515,10 +515,10 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
accounts: &[AccountInfo],
ix_data: &[u8],
) -> ProgramResult {
// Deserialize instruction.
#deserialize_instruction
// Deserialize instruction.
#deserialize_instruction

// Deserialize the program state account.
// Deserialize the program state account.
let mut remaining_accounts: &[AccountInfo] = accounts;
if remaining_accounts.is_empty() {
return Err(anchor_lang::__private::ErrorCode::AccountNotEnoughKeys.into());
Expand Down Expand Up @@ -564,24 +564,24 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
accounts: &[AccountInfo],
ix_data: &[u8],
) -> ProgramResult {
// Deserialize instruction.
#deserialize_instruction
// Deserialize instruction.
#deserialize_instruction

// Deserialize accounts.
// Deserialize accounts.
let mut remaining_accounts: &[AccountInfo] = accounts;
let mut accounts = #anchor_ident::try_accounts(
program_id,
&mut remaining_accounts,
ix_data,
)?;

// Execute user defined function.
// Execute user defined function.
#state_name::#ix_method_name(
Context::new(program_id, &mut accounts, remaining_accounts),
#(#ix_arg_names),*
)?;

// Exit procedure.
// Exit procedure.
accounts.exit(program_id)
}
}
Expand Down Expand Up @@ -610,26 +610,26 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
accounts: &[AccountInfo],
ix_data: &[u8],
) -> ProgramResult {
// Deserialize data.
// Deserialize data.
let ix = instruction::#ix_name::deserialize(&mut &ix_data[..])
.map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
let instruction::#variant_arm = ix;

// Deserialize accounts.
// Deserialize accounts.
let mut remaining_accounts: &[AccountInfo] = accounts;
let mut accounts = #anchor::try_accounts(
program_id,
&mut remaining_accounts,
ix_data,
)?;

// Invoke user defined handler.
// Invoke user defined handler.
#program_name::#ix_method_name(
Context::new(program_id, &mut accounts, remaining_accounts),
#(#ix_arg_names),*
)?;

// Exit routine.
// Exit routine.
accounts.exit(program_id)
}
}
Expand Down

0 comments on commit a65665f

Please sign in to comment.