Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Derive Clone on Wallet (#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
moh-eulith authored Aug 8, 2022
1 parent 13c0ee8 commit cff1ce4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
6 changes: 6 additions & 0 deletions ethers-signers/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ use std::fmt;
/// let message = b"hello";
/// let signature = wallet.sign_message(message).await?;
/// assert_eq!(signature.recover(&message[..]).unwrap(), wallet.address());
///
/// // LocalWallet is clonable:
/// let wallet_clone = wallet.clone();
/// let signature2 = wallet_clone.sign_message(message).await?;
/// assert_eq!(signature, signature2);
/// # Ok(())
/// # }
/// ```
///
/// [`Signature`]: ethers_core::types::Signature
/// [`hash_message`]: fn@ethers_core::utils::hash_message
#[derive(Clone)]
pub struct Wallet<D: DigestSigner<Sha256Proxy, RecoverableSignature>> {
/// The Wallet's private Key
pub(crate) signer: D,
Expand Down
11 changes: 0 additions & 11 deletions ethers-signers/src/wallet/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ pub enum WalletError {
Eip712Error(String),
}

impl Clone for Wallet<SigningKey> {
fn clone(&self) -> Self {
Self {
// TODO: Can we have a better way to clone here?
signer: SigningKey::from_bytes(&self.signer.to_bytes()).unwrap(),
address: self.address,
chain_id: self.chain_id,
}
}
}

impl Wallet<SigningKey> {
/// Creates a new random encrypted JSON with the provided password and stores it in the
/// provided directory. Returns a tuple (Wallet, String) of the wallet instance for the
Expand Down

0 comments on commit cff1ce4

Please sign in to comment.