Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
sdk: Move NullSigner to signer module
Browse files Browse the repository at this point in the history
  • Loading branch information
t-nelson committed May 8, 2021
1 parent ee9495d commit 4e42d32
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
35 changes: 1 addition & 34 deletions sdk/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::*;
Expand Down
1 change: 1 addition & 0 deletions sdk/src/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use {
};

pub mod keypair;
pub mod null_signer;
pub mod presigner;

#[derive(Debug, Error, PartialEq)]
Expand Down
38 changes: 38 additions & 0 deletions sdk/src/signer/null_signer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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()
}
}

0 comments on commit 4e42d32

Please sign in to comment.