solana_signer/
null_signer.rs

1use {
2    crate::{Signer, SignerError},
3    solana_pubkey::Pubkey,
4    solana_signature::Signature,
5};
6
7/// NullSigner - A `Signer` implementation that always produces `Signature::default()`.
8/// Used as a placeholder for absentee signers whose 'Pubkey` is required to construct
9/// the transaction
10#[derive(Clone, Debug, Default)]
11pub struct NullSigner {
12    pubkey: Pubkey,
13}
14
15impl NullSigner {
16    pub fn new(pubkey: &Pubkey) -> Self {
17        Self { pubkey: *pubkey }
18    }
19}
20
21impl Signer for NullSigner {
22    fn try_pubkey(&self) -> Result<Pubkey, SignerError> {
23        Ok(self.pubkey)
24    }
25
26    fn try_sign_message(&self, _message: &[u8]) -> Result<Signature, SignerError> {
27        Ok(Signature::default())
28    }
29
30    fn is_interactive(&self) -> bool {
31        false
32    }
33}
34
35impl<T> PartialEq<T> for NullSigner
36where
37    T: Signer,
38{
39    fn eq(&self, other: &T) -> bool {
40        self.pubkey == other.pubkey()
41    }
42}