diff --git a/crates/client/src/program_client_generator.rs b/crates/client/src/program_client_generator.rs index b66b6149..a6b16b78 100644 --- a/crates/client/src/program_client_generator.rs +++ b/crates/client/src/program_client_generator.rs @@ -48,7 +48,22 @@ pub fn generate_source_code(idl: Idl, use_modules: &[syn::ItemUse]) -> String { .iter() .map(|(name, ty)| { let name = format_ident!("a_{name}"); - let ty: syn::Type = parse_str(ty).unwrap(); + // do not use fully qualified type for Pubkey + let ty = parse_str(ty).unwrap(); + let ty: syn::Type = match &ty { + syn::Type::Path(tp) => { + let last_type = + &tp.path.segments.last().unwrap().ident.to_string(); + if last_type == "Pubkey" { + let t: syn::Type = parse_str(last_type).unwrap(); + t + } else { + // we expect only Pubkey, but if it is something different, than return fully qualified type + ty + } + } + _ => ty, + }; let account: syn::FnArg = parse_quote!(#name: #ty); account }) @@ -83,7 +98,7 @@ pub fn generate_source_code(idl: Idl, use_modules: &[syn::ItemUse]) -> String { #(#accounts,)* signers: impl IntoIterator + Send + 'static, ) -> Result { - Ok(client.send_instruction( + client.send_instruction( PROGRAM_ID, #module_name::instruction::#instruction_struct_name { #(#field_parameters,)* @@ -92,7 +107,7 @@ pub fn generate_source_code(idl: Idl, use_modules: &[syn::ItemUse]) -> String { #(#field_accounts,)* }, signers, - ).await?) + ).await } }; diff --git a/crates/client/tests/test_data/expected_client_code.rs b/crates/client/tests/test_data/expected_client_code.rs index 252d14c4..741b0b16 100644 --- a/crates/client/tests/test_data/expected_client_code.rs +++ b/crates/client/tests/test_data/expected_client_code.rs @@ -10,15 +10,15 @@ pub mod escrow_instruction { client: &Client, i_initializer_amount: u64, i_taker_amount: u64, - a_initializer: anchor_lang::solana_program::pubkey::Pubkey, - a_initializer_deposit_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_initializer_receive_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_escrow_account: anchor_lang::solana_program::pubkey::Pubkey, - a_system_program: anchor_lang::solana_program::pubkey::Pubkey, - a_token_program: anchor_lang::solana_program::pubkey::Pubkey, + a_initializer: Pubkey, + a_initializer_deposit_token_account: Pubkey, + a_initializer_receive_token_account: Pubkey, + a_escrow_account: Pubkey, + a_system_program: Pubkey, + a_token_program: Pubkey, signers: impl IntoIterator + Send + 'static, ) -> Result { - Ok(client + client .send_instruction( PROGRAM_ID, escrow::instruction::InitializeEscrow { @@ -35,17 +35,17 @@ pub mod escrow_instruction { }, signers, ) - .await?) + .await } pub fn initialize_escrow_ix( i_initializer_amount: u64, i_taker_amount: u64, - a_initializer: anchor_lang::solana_program::pubkey::Pubkey, - a_initializer_deposit_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_initializer_receive_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_escrow_account: anchor_lang::solana_program::pubkey::Pubkey, - a_system_program: anchor_lang::solana_program::pubkey::Pubkey, - a_token_program: anchor_lang::solana_program::pubkey::Pubkey, + a_initializer: Pubkey, + a_initializer_deposit_token_account: Pubkey, + a_initializer_receive_token_account: Pubkey, + a_escrow_account: Pubkey, + a_system_program: Pubkey, + a_token_program: Pubkey, ) -> Instruction { Instruction { program_id: PROGRAM_ID, @@ -67,14 +67,14 @@ pub mod escrow_instruction { } pub async fn cancel_escrow( client: &Client, - a_initializer: anchor_lang::solana_program::pubkey::Pubkey, - a_pda_deposit_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_pda_account: anchor_lang::solana_program::pubkey::Pubkey, - a_escrow_account: anchor_lang::solana_program::pubkey::Pubkey, - a_token_program: anchor_lang::solana_program::pubkey::Pubkey, + a_initializer: Pubkey, + a_pda_deposit_token_account: Pubkey, + a_pda_account: Pubkey, + a_escrow_account: Pubkey, + a_token_program: Pubkey, signers: impl IntoIterator + Send + 'static, ) -> Result { - Ok(client + client .send_instruction( PROGRAM_ID, escrow::instruction::CancelEscrow {}, @@ -87,14 +87,14 @@ pub mod escrow_instruction { }, signers, ) - .await?) + .await } pub fn cancel_escrow_ix( - a_initializer: anchor_lang::solana_program::pubkey::Pubkey, - a_pda_deposit_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_pda_account: anchor_lang::solana_program::pubkey::Pubkey, - a_escrow_account: anchor_lang::solana_program::pubkey::Pubkey, - a_token_program: anchor_lang::solana_program::pubkey::Pubkey, + a_initializer: Pubkey, + a_pda_deposit_token_account: Pubkey, + a_pda_account: Pubkey, + a_escrow_account: Pubkey, + a_token_program: Pubkey, ) -> Instruction { Instruction { program_id: PROGRAM_ID, @@ -111,18 +111,18 @@ pub mod escrow_instruction { } pub async fn exchange( client: &Client, - a_taker: anchor_lang::solana_program::pubkey::Pubkey, - a_taker_deposit_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_taker_receive_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_pda_deposit_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_initializer_receive_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_initializer_main_account: anchor_lang::solana_program::pubkey::Pubkey, - a_escrow_account: anchor_lang::solana_program::pubkey::Pubkey, - a_pda_account: anchor_lang::solana_program::pubkey::Pubkey, - a_token_program: anchor_lang::solana_program::pubkey::Pubkey, + a_taker: Pubkey, + a_taker_deposit_token_account: Pubkey, + a_taker_receive_token_account: Pubkey, + a_pda_deposit_token_account: Pubkey, + a_initializer_receive_token_account: Pubkey, + a_initializer_main_account: Pubkey, + a_escrow_account: Pubkey, + a_pda_account: Pubkey, + a_token_program: Pubkey, signers: impl IntoIterator + Send + 'static, ) -> Result { - Ok(client + client .send_instruction( PROGRAM_ID, escrow::instruction::Exchange {}, @@ -139,18 +139,18 @@ pub mod escrow_instruction { }, signers, ) - .await?) + .await } pub fn exchange_ix( - a_taker: anchor_lang::solana_program::pubkey::Pubkey, - a_taker_deposit_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_taker_receive_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_pda_deposit_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_initializer_receive_token_account: anchor_lang::solana_program::pubkey::Pubkey, - a_initializer_main_account: anchor_lang::solana_program::pubkey::Pubkey, - a_escrow_account: anchor_lang::solana_program::pubkey::Pubkey, - a_pda_account: anchor_lang::solana_program::pubkey::Pubkey, - a_token_program: anchor_lang::solana_program::pubkey::Pubkey, + a_taker: Pubkey, + a_taker_deposit_token_account: Pubkey, + a_taker_receive_token_account: Pubkey, + a_pda_deposit_token_account: Pubkey, + a_initializer_receive_token_account: Pubkey, + a_initializer_main_account: Pubkey, + a_escrow_account: Pubkey, + a_pda_account: Pubkey, + a_token_program: Pubkey, ) -> Instruction { Instruction { program_id: PROGRAM_ID,