From cea3f25044806cd47549bd8ab919eda04fb0fefa Mon Sep 17 00:00:00 2001 From: cryptopapi997 Date: Wed, 20 Aug 2025 11:34:59 +0200 Subject: [PATCH 1/6] . --- client/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 1ce7997fc4..9352d7665c 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -91,6 +91,7 @@ use solana_sdk::commitment_config::CommitmentConfig; use solana_sdk::hash::Hash; use solana_sdk::instruction::{AccountMeta, Instruction}; use solana_sdk::signature::{Signature, Signer}; +use solana_sdk::signer::SignerError; use solana_sdk::transaction::Transaction; use std::iter::Map; use std::marker::PhantomData; @@ -496,6 +497,8 @@ pub enum ClientError { SolanaClientError(#[from] Box), #[error("{0}")] SolanaClientPubsubError(#[from] Box), + #[error("{0}")] + SignerError(#[from] SignerError), #[error("Unable to parse log: {0}")] LogParseError(String), #[error(transparent)] @@ -621,17 +624,12 @@ impl + Clone, S: AsSigner> RequestBuilder<'_, C, &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) } From 6c58925931bc38a5352292562ecfcc7b204b2174 Mon Sep 17 00:00:00 2001 From: cryptopapi997 Date: Wed, 20 Aug 2025 11:45:37 +0200 Subject: [PATCH 2/6] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1dbb0a9d6..9d5b3fc849 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The minor version will be incremented upon a breaking change and the patch versi ### Breaking - spl: Update SPL dependencies to latest compatible versions ([#3860](https://github.com/solana-foundation/anchor/pull/3860)). +- client: Make sending a tx not panic and instead return an Error when signing fails ([#3865](https://github.com/solana-foundation/anchor/pull/3865)). ## [0.31.1] - 2025-04-19 From e5d51d9b424c8101225cf78835237f11d8c62eee Mon Sep 17 00:00:00 2001 From: cryptopapi997 Date: Wed, 20 Aug 2025 13:03:12 +0200 Subject: [PATCH 3/6] switch error order --- client/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 9352d7665c..5490da4263 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -497,12 +497,12 @@ pub enum ClientError { SolanaClientError(#[from] Box), #[error("{0}")] SolanaClientPubsubError(#[from] Box), - #[error("{0}")] - SignerError(#[from] SignerError), #[error("Unable to parse log: {0}")] LogParseError(String), #[error(transparent)] IOError(#[from] std::io::Error), + #[error("{0}")] + SignerError(#[from] SignerError), } pub trait AsSigner { From 9b7e1568f7197bd8d985069ea902a824d8702ab5 Mon Sep 17 00:00:00 2001 From: cryptopapi997 Date: Tue, 28 Oct 2025 11:27:27 +0800 Subject: [PATCH 4/6] copy over changes from other branch --- client/src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 61688d0127..adca2e5073 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -606,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 { @@ -616,7 +616,7 @@ impl + Clone, S: AsSigner> RequestBuilder<'_, C, }); } - Ok(instructions) + instructions } fn signed_transaction_with_blockhash( @@ -627,16 +627,15 @@ impl + Clone, S: AsSigner> RequestBuilder<'_, C, let mut all_signers = signers; all_signers.push(&*self.payer); - let mut tx = self.transaction()?; + let mut tx = self.transaction(); tx.try_sign(&all_signers, latest_hash)?; Ok(tx) } - pub fn transaction(&self) -> Result { + pub fn transaction(&self) -> Transaction { let instructions = &self.instructions; - let tx = Transaction::new_with_payer(instructions, Some(&self.payer.pubkey())); - Ok(tx) + Transaction::new_with_payer(instructions, Some(&self.payer.pubkey())) } async fn signed_transaction_internal(&self) -> Result { From 9ff042ca0fe05549f4185efdb114d04197489728 Mon Sep 17 00:00:00 2001 From: cryptopapi997 Date: Wed, 29 Oct 2025 16:38:27 +0800 Subject: [PATCH 5/6] fix test --- client/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 6f79473fd7..0a2b8db078 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -634,7 +634,7 @@ impl + Clone, S: AsSigner> RequestBuilder<'_, C, } pub fn transaction(&self) -> Transaction { - let instructions = &self.instructions; + let instructions = &self.instructions(); Transaction::new_with_payer(instructions, Some(&self.payer.pubkey())) } From e4a67c112a87a1f3c652303c209d9ad92808222d Mon Sep 17 00:00:00 2001 From: cryptopapi997 Date: Thu, 30 Oct 2025 12:38:10 +0800 Subject: [PATCH 6/6] switch to solana-signer --- Cargo.lock | 1 + client/Cargo.toml | 1 + client/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index cbf4f29912..2380c75fda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,6 +250,7 @@ dependencies = [ "solana-rpc-client", "solana-rpc-client-api", "solana-sdk", + "solana-signer", "thiserror 1.0.66", "tokio", "url", diff --git a/client/Cargo.toml b/client/Cargo.toml index ac2044e935..f295260adc 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -27,6 +27,7 @@ solana-rpc-client = "2" solana-rpc-client-api = "2" solana-account = "2" solana-sdk = "2" +solana-signer = "2" thiserror = "1" tokio = { version = "1", features = ["rt", "sync"] } url = "2" diff --git a/client/src/lib.rs b/client/src/lib.rs index 0a2b8db078..c26fad315d 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -91,8 +91,8 @@ use solana_sdk::commitment_config::CommitmentConfig; use solana_sdk::hash::Hash; use solana_sdk::instruction::{AccountMeta, Instruction}; use solana_sdk::signature::{Signature, Signer}; -use solana_sdk::signer::SignerError; use solana_sdk::transaction::Transaction; +use solana_signer::SignerError; use std::iter::Map; use std::marker::PhantomData; use std::ops::Deref;