sdk: Move `NullSigner` to `signer` module
This commit is contained in:
parent
12bf6c06c3
commit
b71e4bdc61
|
@ -12,7 +12,7 @@ use std::{
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
// legacy module paths
|
// legacy module paths
|
||||||
pub use crate::signer::{keypair::*, presigner::*, *};
|
pub use crate::signer::{keypair::*, null_signer::*, presigner::*, *};
|
||||||
|
|
||||||
/// Number of bytes in a signature
|
/// Number of bytes in a signature
|
||||||
pub const SIGNATURE_BYTES: usize = 64;
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -11,6 +11,7 @@ use {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod keypair;
|
pub mod keypair;
|
||||||
|
pub mod null_signer;
|
||||||
pub mod presigner;
|
pub mod presigner;
|
||||||
|
|
||||||
#[derive(Debug, Error, PartialEq)]
|
#[derive(Debug, Error, PartialEq)]
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue