use async_trait::async_trait;
use bytes::Bytes;
use crate::{ChainId, SendOptions, XenithError};
#[async_trait]
pub trait TransactionSigner: Send + Sync {
fn address(&self) -> [u8; 20];
async fn sign_transaction(
&self,
to: [u8; 20],
calldata: Bytes,
options: &SendOptions,
chain_id: ChainId,
) -> Result<Bytes, XenithError>;
}
#[derive(Debug, Default)]
pub struct NoopSigner;
impl NoopSigner {
pub fn new() -> Self {
Self
}
}
#[async_trait]
impl TransactionSigner for NoopSigner {
fn address(&self) -> [u8; 20] {
[0u8; 20]
}
async fn sign_transaction(
&self,
_to: [u8; 20],
calldata: Bytes,
_options: &SendOptions,
_chain_id: ChainId,
) -> Result<Bytes, XenithError> {
Ok(calldata)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn noop_signer_address_is_zero() {
let s = NoopSigner::new();
assert_eq!(s.address(), [0u8; 20]);
}
}