solana_sdk/signer/
null_signer.rs

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