diff --git a/client/src/connection_cache.rs b/client/src/connection_cache.rs index 045ef57ca5..ce1a8b022d 100644 --- a/client/src/connection_cache.rs +++ b/client/src/connection_cache.rs @@ -145,20 +145,20 @@ impl Default for ConnectionCache { } macro_rules! dispatch { - ($(#[$meta:meta])* $vis:vis fn $name:ident$(<$($t:ident: $cons:ident),*>)?(&self $(, $arg:ident: $ty:ty)*) $(-> $out:ty)?) => { + ($(#[$meta:meta])* $vis:vis fn $name:ident$(<$($t:ident: $cons:ident + ?Sized),*>)?(&self $(, $arg:ident: $ty:ty)*) $(-> $out:ty)?) => { #[inline] $(#[$meta])* - $vis fn $name$(<$($t: $cons),*>)?(&self $(, $arg:$ty)*) $(-> $out)? { + $vis fn $name$(<$($t: $cons + ?Sized),*>)?(&self $(, $arg:$ty)*) $(-> $out)? { match self { Self::Quic(this) => this.$name($($arg, )*), Self::Udp(this) => this.$name($($arg, )*), } } }; - ($(#[$meta:meta])* $vis:vis fn $name:ident$(<$($t:ident: $cons:ident),*>)?(&mut self $(, $arg:ident: $ty:ty)*) $(-> $out:ty)?) => { + ($(#[$meta:meta])* $vis:vis fn $name:ident$(<$($t:ident: $cons:ident + ?Sized),*>)?(&mut self $(, $arg:ident: $ty:ty)*) $(-> $out:ty)?) => { #[inline] $(#[$meta])* - $vis fn $name$(<$($t: $cons),*>)?(&mut self $(, $arg:$ty)*) $(-> $out)? { + $vis fn $name$(<$($t: $cons + ?Sized),*>)?(&mut self $(, $arg:$ty)*) $(-> $out)? { match self { Self::Quic(this) => this.$name($($arg, )*), Self::Udp(this) => this.$name($($arg, )*), diff --git a/client/src/nonblocking/tpu_client.rs b/client/src/nonblocking/tpu_client.rs index fb0f87a755..21c7c55a04 100644 --- a/client/src/nonblocking/tpu_client.rs +++ b/client/src/nonblocking/tpu_client.rs @@ -120,7 +120,7 @@ where }) } - pub async fn send_and_confirm_messages_with_spinner( + pub async fn send_and_confirm_messages_with_spinner( &self, messages: &[Message], signers: &T, diff --git a/client/src/thin_client.rs b/client/src/thin_client.rs index aed9537ea8..559b904c13 100644 --- a/client/src/thin_client.rs +++ b/client/src/thin_client.rs @@ -124,7 +124,7 @@ impl ThinClient { tries: usize ) -> TransportResult); - dispatch!(pub fn send_and_confirm_transaction( + dispatch!(pub fn send_and_confirm_transaction( &self, keypairs: &T, transaction: &mut Transaction, @@ -172,7 +172,7 @@ impl Client for ThinClient { } impl SyncClient for ThinClient { - dispatch!(fn send_and_confirm_message( + dispatch!(fn send_and_confirm_message( &self, keypairs: &T, message: Message diff --git a/client/src/tpu_client.rs b/client/src/tpu_client.rs index ab39b59c74..7d32381445 100644 --- a/client/src/tpu_client.rs +++ b/client/src/tpu_client.rs @@ -111,7 +111,7 @@ where }) } - pub fn send_and_confirm_messages_with_spinner( + pub fn send_and_confirm_messages_with_spinner( &self, messages: &[Message], signers: &T, diff --git a/runtime/src/bank_client.rs b/runtime/src/bank_client.rs index c553ee86a7..e4681db8aa 100644 --- a/runtime/src/bank_client.rs +++ b/runtime/src/bank_client.rs @@ -51,7 +51,7 @@ impl AsyncClient for BankClient { } impl SyncClient for BankClient { - fn send_and_confirm_message( + fn send_and_confirm_message( &self, keypairs: &T, message: Message, diff --git a/sdk/program/src/example_mocks.rs b/sdk/program/src/example_mocks.rs index a551a6dc6f..fdada265b6 100644 --- a/sdk/program/src/example_mocks.rs +++ b/sdk/program/src/example_mocks.rs @@ -213,7 +213,7 @@ pub mod solana_sdk { } impl VersionedTransaction { - pub fn try_new( + pub fn try_new( message: VersionedMessage, _keypairs: &T, ) -> std::result::Result { @@ -230,7 +230,7 @@ pub mod solana_sdk { } impl Transaction { - pub fn new( + pub fn new( _from_keypairs: &T, _message: Message, _recent_blockhash: Hash, @@ -252,7 +252,7 @@ pub mod solana_sdk { } } - pub fn new_signed_with_payer( + pub fn new_signed_with_payer( instructions: &[Instruction], payer: Option<&Pubkey>, signing_keypairs: &T, @@ -262,9 +262,9 @@ pub mod solana_sdk { Self::new(signing_keypairs, message, recent_blockhash) } - pub fn sign(&mut self, _keypairs: &T, _recent_blockhash: Hash) {} + pub fn sign(&mut self, _keypairs: &T, _recent_blockhash: Hash) {} - pub fn try_sign( + pub fn try_sign( &mut self, _keypairs: &T, _recent_blockhash: Hash, diff --git a/sdk/src/client.rs b/sdk/src/client.rs index c2f7f62d35..f9e435c81d 100644 --- a/sdk/src/client.rs +++ b/sdk/src/client.rs @@ -34,7 +34,7 @@ pub trait Client: SyncClient + AsyncClient { pub trait SyncClient { /// Create a transaction from the given message, and send it to the /// server, retrying as-needed. - fn send_and_confirm_message( + fn send_and_confirm_message( &self, keypairs: &T, message: Message, @@ -204,7 +204,7 @@ pub trait AsyncClient { /// Create a transaction from the given message, and send it to the /// server, but don't wait for to see if the server accepted it. - fn async_send_message( + fn async_send_message( &self, keypairs: &T, message: Message, diff --git a/sdk/src/transaction/mod.rs b/sdk/src/transaction/mod.rs index e5eb9fdba5..f1c7e2ed58 100644 --- a/sdk/src/transaction/mod.rs +++ b/sdk/src/transaction/mod.rs @@ -346,7 +346,7 @@ impl Transaction { /// # /// # Ok::<(), anyhow::Error>(()) /// ``` - pub fn new( + pub fn new( from_keypairs: &T, message: Message, recent_blockhash: Hash, @@ -501,7 +501,7 @@ impl Transaction { /// # /// # Ok::<(), anyhow::Error>(()) /// ``` - pub fn new_signed_with_payer( + pub fn new_signed_with_payer( instructions: &[Instruction], payer: Option<&Pubkey>, signing_keypairs: &T, @@ -526,7 +526,7 @@ impl Transaction { /// /// Panics when signing fails. See [`Transaction::try_sign`] and for a full /// description of failure conditions. - pub fn new_with_compiled_instructions( + pub fn new_with_compiled_instructions( from_keypairs: &T, keys: &[Pubkey], recent_blockhash: Hash, @@ -705,7 +705,7 @@ impl Transaction { /// # /// # Ok::<(), anyhow::Error>(()) /// ``` - pub fn sign(&mut self, keypairs: &T, recent_blockhash: Hash) { + pub fn sign(&mut self, keypairs: &T, recent_blockhash: Hash) { if let Err(e) = self.try_sign(keypairs, recent_blockhash) { panic!("Transaction::sign failed with error {e:?}"); } @@ -731,7 +731,7 @@ impl Transaction { /// handle the error. See the documentation for /// [`Transaction::try_partial_sign`] for a full description of failure /// conditions. - pub fn partial_sign(&mut self, keypairs: &T, recent_blockhash: Hash) { + pub fn partial_sign(&mut self, keypairs: &T, recent_blockhash: Hash) { if let Err(e) = self.try_partial_sign(keypairs, recent_blockhash) { panic!("Transaction::partial_sign failed with error {e:?}"); } @@ -750,7 +750,7 @@ impl Transaction { /// /// Panics if signing fails. Use [`Transaction::try_partial_sign_unchecked`] /// to handle the error. - pub fn partial_sign_unchecked( + pub fn partial_sign_unchecked( &mut self, keypairs: &T, positions: Vec, @@ -843,7 +843,7 @@ impl Transaction { /// # /// # Ok::<(), anyhow::Error>(()) /// ``` - pub fn try_sign( + pub fn try_sign( &mut self, keypairs: &T, recent_blockhash: Hash, @@ -906,7 +906,7 @@ impl Transaction { /// [`PresignerError::VerificationFailure`]: crate::signer::presigner::PresignerError::VerificationFailure /// [`solana-remote-wallet`]: https://docs.rs/solana-remote-wallet/latest/ /// [`RemoteKeypair`]: https://docs.rs/solana-remote-wallet/latest/solana_remote_wallet/remote_keypair/struct.RemoteKeypair.html - pub fn try_partial_sign( + pub fn try_partial_sign( &mut self, keypairs: &T, recent_blockhash: Hash, @@ -932,7 +932,7 @@ impl Transaction { /// # Errors /// /// Returns an error if signing fails. - pub fn try_partial_sign_unchecked( + pub fn try_partial_sign_unchecked( &mut self, keypairs: &T, positions: Vec, @@ -1668,4 +1668,22 @@ mod tests { .unwrap_err(); assert_eq!(err, SignerError::KeypairPubkeyMismatch); } + + #[test] + fn test_unsized_signers() { + fn instructions_to_tx( + instructions: &[Instruction], + signers: Box, + ) -> Transaction { + let pubkeys = signers.pubkeys(); + let first_signer = pubkeys.first().expect("should exist"); + let message = Message::new(instructions, Some(first_signer)); + Transaction::new(signers.as_ref(), message, Hash::default()) + } + + let signer: Box = Box::new(Keypair::new()); + let tx = instructions_to_tx(&[], Box::new(vec![signer])); + + assert!(tx.is_signed()); + } } diff --git a/sdk/src/transaction/versioned/mod.rs b/sdk/src/transaction/versioned/mod.rs index fd749c3892..29e385e627 100644 --- a/sdk/src/transaction/versioned/mod.rs +++ b/sdk/src/transaction/versioned/mod.rs @@ -68,7 +68,7 @@ impl From for VersionedTransaction { impl VersionedTransaction { /// Signs a versioned message and if successful, returns a signed /// transaction. - pub fn try_new( + pub fn try_new( message: VersionedMessage, keypairs: &T, ) -> std::result::Result { diff --git a/thin-client/src/thin_client.rs b/thin-client/src/thin_client.rs index c383ee0201..b1ae08fd7c 100644 --- a/thin-client/src/thin_client.rs +++ b/thin-client/src/thin_client.rs @@ -209,7 +209,7 @@ where self.send_and_confirm_transaction(&[keypair], transaction, tries, 0) } - pub fn send_and_confirm_transaction( + pub fn send_and_confirm_transaction( &self, keypairs: &T, transaction: &mut Transaction, @@ -340,7 +340,7 @@ where M: ConnectionManager, C: NewConnectionConfig, { - fn send_and_confirm_message( + fn send_and_confirm_message( &self, keypairs: &T, message: Message, diff --git a/tpu-client/src/nonblocking/tpu_client.rs b/tpu-client/src/nonblocking/tpu_client.rs index 8214dfa6fb..d23de87526 100644 --- a/tpu-client/src/nonblocking/tpu_client.rs +++ b/tpu-client/src/nonblocking/tpu_client.rs @@ -437,7 +437,7 @@ where } #[cfg(feature = "spinner")] - pub async fn send_and_confirm_messages_with_spinner( + pub async fn send_and_confirm_messages_with_spinner( &self, messages: &[Message], signers: &T, diff --git a/tpu-client/src/tpu_client.rs b/tpu-client/src/tpu_client.rs index f2d62c5d77..a620d0e0ce 100644 --- a/tpu-client/src/tpu_client.rs +++ b/tpu-client/src/tpu_client.rs @@ -158,7 +158,7 @@ where } #[cfg(feature = "spinner")] - pub fn send_and_confirm_messages_with_spinner( + pub fn send_and_confirm_messages_with_spinner( &self, messages: &[Message], signers: &T,