Skip to content

Commit

Permalink
auto_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Dec 11, 2023
1 parent e11de38 commit e06356a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ tracing-subscriber = "0.3.18"

tempfile = "3.8"

auto_impl = "1.1"
assert_matches = "1.5"
base64 = "0.21"
bimap = "0.6"
Expand Down
1 change: 1 addition & 0 deletions crates/signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ alloy-primitives.workspace = true
# TODO
# alloy-rpc-types.workspace = true

auto_impl.workspace = true
elliptic-curve.workspace = true
k256.workspace = true
rand.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions crates/signer/src/signer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{Result, Signature};
use alloy_primitives::{eip191_hash_message, Address, B256};
use async_trait::async_trait;
use auto_impl::auto_impl;

#[cfg(feature = "eip712")]
use alloy_sol_types::{Eip712Domain, SolStruct};
Expand All @@ -15,6 +16,7 @@ use alloy_sol_types::{Eip712Domain, SolStruct};
/// Synchronous signers should implement both this trait and [`SignerSync`].
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[auto_impl(&mut, Box)]
pub trait Signer: Send + Sync {
/// Signs the given hash.
async fn sign_hash(&self, hash: &B256) -> Result<Signature>;
Expand Down Expand Up @@ -62,6 +64,7 @@ pub trait Signer: Send + Sync {
/// Sets the signer's chain ID and returns `self`.
#[inline]
#[must_use]
#[auto_impl(keep_default_for(&mut, Box))]
fn with_chain_id(mut self, chain_id: u64) -> Self
where
Self: Sized,
Expand All @@ -80,6 +83,7 @@ pub trait Signer: Send + Sync {
///
/// Synchronous signers should also implement [`Signer`], as they are always able to by delegating
/// the asynchronous methods to the synchronous ones.
#[auto_impl(&, &mut, Box, Rc, Arc)]
pub trait SignerSync {
/// Signs the given hash.
fn sign_hash_sync(&self, hash: &B256) -> Result<Signature>;
Expand Down

0 comments on commit e06356a

Please sign in to comment.