From cff1ce4068c5204e0bf7e6fafbcefeab3e7608b8 Mon Sep 17 00:00:00 2001 From: moh-eulith <101080211+moh-eulith@users.noreply.github.com> Date: Mon, 8 Aug 2022 13:30:13 -0400 Subject: [PATCH] Derive Clone on Wallet (#1573) --- ethers-signers/src/wallet/mod.rs | 6 ++++++ ethers-signers/src/wallet/private_key.rs | 11 ----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/ethers-signers/src/wallet/mod.rs b/ethers-signers/src/wallet/mod.rs index dc2a811f..f8f60885 100644 --- a/ethers-signers/src/wallet/mod.rs +++ b/ethers-signers/src/wallet/mod.rs @@ -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> { /// The Wallet's private Key pub(crate) signer: D, diff --git a/ethers-signers/src/wallet/private_key.rs b/ethers-signers/src/wallet/private_key.rs index 10f0e9b7..4ac06ebd 100644 --- a/ethers-signers/src/wallet/private_key.rs +++ b/ethers-signers/src/wallet/private_key.rs @@ -48,17 +48,6 @@ pub enum WalletError { Eip712Error(String), } -impl Clone for Wallet { - 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 { /// 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