sdk: Move `NullSigner` to `signer` module

This commit is contained in:
Trent Nelson 2021-05-07 02:06:20 -06:00 committed by Trent Nelson
parent 12bf6c06c3
commit b71e4bdc61
3 changed files with 42 additions and 34 deletions

View File

@ -12,7 +12,7 @@ use std::{
use thiserror::Error;
// legacy module paths
pub use crate::signer::{keypair::*, presigner::*, *};
pub use crate::signer::{keypair::*, null_signer::*, presigner::*, *};
/// Number of bytes in a signature
pub const SIGNATURE_BYTES: usize = 64;
@ -113,39 +113,6 @@ impl FromStr for Signature {
}
}
/// NullSigner - A `Signer` implementation that always produces `Signature::default()`.
/// Used as a placeholder for absentee signers whose 'Pubkey` is required to construct
/// the transaction
#[derive(Clone, Debug, Default)]
pub struct NullSigner {
pubkey: Pubkey,
}
impl NullSigner {
pub fn new(pubkey: &Pubkey) -> Self {
Self { pubkey: *pubkey }
}
}
impl Signer for NullSigner {
fn try_pubkey(&self) -> Result<Pubkey, SignerError> {
Ok(self.pubkey)
}
fn try_sign_message(&self, _message: &[u8]) -> Result<Signature, SignerError> {
Ok(Signature::default())
}
}
impl<T> PartialEq<T> for NullSigner
where
T: Signer,
{
fn eq(&self, other: &T) -> bool {
self.pubkey == other.pubkey()
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -11,6 +11,7 @@ use {
};
pub mod keypair;
pub mod null_signer;
pub mod presigner;
#[derive(Debug, Error, PartialEq)]

View File

@ -0,0 +1,40 @@
#![cfg(feature = "full")]
use crate::{
pubkey::Pubkey,
signature::Signature,
signer::{Signer, SignerError},
};
/// NullSigner - A `Signer` implementation that always produces `Signature::default()`.
/// Used as a placeholder for absentee signers whose 'Pubkey` is required to construct
/// the transaction
#[derive(Clone, Debug, Default)]
pub struct NullSigner {
pubkey: Pubkey,
}
impl NullSigner {
pub fn new(pubkey: &Pubkey) -> Self {
Self { pubkey: *pubkey }
}
}
impl Signer for NullSigner {
fn try_pubkey(&self) -> Result<Pubkey, SignerError> {
Ok(self.pubkey)
}
fn try_sign_message(&self, _message: &[u8]) -> Result<Signature, SignerError> {
Ok(Signature::default())
}
}
impl<T> PartialEq<T> for NullSigner
where
T: Signer,
{
fn eq(&self, other: &T) -> bool {
self.pubkey == other.pubkey()
}
}