diff --git a/CHANGELOG.md b/CHANGELOG.md index bf265d9c9f..6c43f8fd32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ The minor version will be incremented upon a breaking change and the patch versi ### Breaking +- client: Make sending a tx not panic and instead return an Error when signing fails ([#3865](https://github.com/solana-foundation/anchor/pull/3865)). - spl: Update SPL dependencies to latest compatible versions ([#3860](https://github.com/solana-foundation/anchor/pull/3860)). - cli: Replace `anchor verify` to use `solana-verify` under the hood, adding automatic installation via AVM, local path support, and future-proof argument passing ([#3768](https://github.com/solana-foundation/anchor/pull/3768)). - cli: Upload IDL by default with an option to skip ((#3863)[https://github.com/solana-foundation/anchor/pull/3863]). diff --git a/client/src/lib.rs b/client/src/lib.rs index 7695e1bd87..8d6da24168 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -500,6 +500,8 @@ pub enum ClientError { LogParseError(String), #[error(transparent)] IOError(#[from] std::io::Error), + #[error("{0}")] + SignerError(#[from] SignerError), } pub trait AsSigner { @@ -604,7 +606,7 @@ impl + Clone, S: AsSigner> RequestBuilder<'_, C, self } - pub fn instructions(&self) -> Result, ClientError> { + pub fn instructions(&self) -> Vec { let mut instructions = self.instructions.clone(); if let Some(ix_data) = &self.instruction_data { instructions.push(Instruction { @@ -614,32 +616,26 @@ impl + Clone, S: AsSigner> RequestBuilder<'_, C, }); } - Ok(instructions) + instructions } fn signed_transaction_with_blockhash( &self, latest_hash: Hash, ) -> Result { - let instructions = self.instructions()?; let signers: Vec<&dyn Signer> = self.signers.iter().map(|s| s.as_signer()).collect(); let mut all_signers = signers; all_signers.push(&*self.payer); - let tx = Transaction::new_signed_with_payer( - &instructions, - Some(&self.payer.pubkey()), - &all_signers, - latest_hash, - ); + let mut tx = self.transaction(); + tx.try_sign(&all_signers, latest_hash)?; Ok(tx) } - pub fn transaction(&self) -> Result { - let instructions = &self.instructions; - let tx = Transaction::new_with_payer(instructions, Some(&self.payer.pubkey())); - Ok(tx) + pub fn transaction(&self) -> Transaction { + let instructions = &self.instructions(); + Transaction::new_with_payer(instructions, Some(&self.payer.pubkey())) } async fn signed_transaction_internal(&self) -> Result {