Derive Clone on Wallet (#1573)
This commit is contained in:
parent
13c0ee8596
commit
cff1ce4068
|
@ -52,12 +52,18 @@ use std::fmt;
|
||||||
/// let message = b"hello";
|
/// let message = b"hello";
|
||||||
/// let signature = wallet.sign_message(message).await?;
|
/// let signature = wallet.sign_message(message).await?;
|
||||||
/// assert_eq!(signature.recover(&message[..]).unwrap(), wallet.address());
|
/// 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(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`Signature`]: ethers_core::types::Signature
|
/// [`Signature`]: ethers_core::types::Signature
|
||||||
/// [`hash_message`]: fn@ethers_core::utils::hash_message
|
/// [`hash_message`]: fn@ethers_core::utils::hash_message
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Wallet<D: DigestSigner<Sha256Proxy, RecoverableSignature>> {
|
pub struct Wallet<D: DigestSigner<Sha256Proxy, RecoverableSignature>> {
|
||||||
/// The Wallet's private Key
|
/// The Wallet's private Key
|
||||||
pub(crate) signer: D,
|
pub(crate) signer: D,
|
||||||
|
|
|
@ -48,17 +48,6 @@ pub enum WalletError {
|
||||||
Eip712Error(String),
|
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> {
|
impl Wallet<SigningKey> {
|
||||||
/// Creates a new random encrypted JSON with the provided password and stores it in the
|
/// 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
|
/// provided directory. Returns a tuple (Wallet, String) of the wallet instance for the
|
||||||
|
|
Loading…
Reference in New Issue