Derive Clone on Wallet (#1573)

This commit is contained in:
moh-eulith 2022-08-08 13:30:13 -04:00 committed by GitHub
parent 13c0ee8596
commit cff1ce4068
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 11 deletions

View File

@ -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,

View File

@ -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