diff --git a/wallet/core/src/derivation/gen0/hd.rs b/wallet/core/src/derivation/gen0/hd.rs index 900ed578e..3fed2b307 100644 --- a/wallet/core/src/derivation/gen0/hd.rs +++ b/wallet/core/src/derivation/gen0/hd.rs @@ -107,7 +107,7 @@ impl PubkeyDerivationManagerV0 { let inner = locked .as_ref() .ok_or(crate::error::Error::Custom("PubkeyDerivationManagerV0 initialization is pending (Error: 101).".into()))?; - Ok(inner.public_key.clone()) + Ok(inner.public_key) } fn index_(&self) -> Result { // let locked = self.opt_inner(); @@ -147,7 +147,7 @@ impl PubkeyDerivationManagerV0 { //workflow_log::log_info!("use_cache: {use_cache}"); if use_cache { //workflow_log::log_info!("cache insert: {:?}", key); - cache.insert(index, key.clone()); + cache.insert(index, key); } Ok(key) }) @@ -156,7 +156,7 @@ impl PubkeyDerivationManagerV0 { indexes .map(|index| { if let Some(key) = cache.get(&index) { - Ok(key.clone()) + Ok(*key) } else { Err(crate::error::Error::Custom("PubkeyDerivationManagerV0 initialization is pending (Error: 102).".into())) } @@ -182,11 +182,11 @@ impl PubkeyDerivationManagerV0 { //workflow_log::log_info!("use_cache: {use_cache}"); if self.use_cache() { //workflow_log::log_info!("cache insert: {:?}", key); - self.cache.lock()?.insert(index, key.clone()); + self.cache.lock()?.insert(index, key); } return Ok(key); } else if let Some(key) = self.cache.lock()?.get(&index) { - return Ok(key.clone()); + return Ok(*key); } Err(crate::error::Error::Custom("PubkeyDerivationManagerV0 initialization is pending (Error: 102).".into())) @@ -236,7 +236,7 @@ impl PubkeyDerivationManagerV0 { impl From<&PubkeyDerivationManagerV0> for ExtendedPublicKey { fn from(inner: &PubkeyDerivationManagerV0) -> ExtendedPublicKey { - ExtendedPublicKey { public_key: inner.public_key_().unwrap().clone(), attrs: inner.attrs().clone() } + ExtendedPublicKey { public_key: inner.public_key_().unwrap(), attrs: inner.attrs().clone() } } } @@ -248,7 +248,7 @@ impl PubkeyDerivationManagerTrait for PubkeyDerivationManagerV0 { } fn index(&self) -> Result { - Ok(self.index_()?) + self.index_() } fn set_index(&self, index: u32) -> Result<()> { @@ -439,7 +439,7 @@ impl WalletDerivationManagerV0 { xkey: &ExtendedPrivateKey, path: DerivationPath, ) -> Result<(SecretKey, ExtendedKeyAttrs)> { - let mut private_key = xkey.private_key().clone(); + let mut private_key = *xkey.private_key(); let mut attrs = xkey.attrs().clone(); for child in path { (private_key, attrs) = Self::derive_private_key(&private_key, &attrs, child)?; @@ -543,13 +543,13 @@ impl WalletDerivationManagerV0 { let receive_wallet = PubkeyDerivationManagerV0 { index: Arc::new(Mutex::new(0)), use_cache: Arc::new(AtomicBool::new(true)), - cache: Arc::new(Mutex::new(receive_keys.unwrap_or(HashMap::new()))), + cache: Arc::new(Mutex::new(receive_keys.unwrap_or_default())), inner: Arc::new(Mutex::new(None)), }; let change_wallet = PubkeyDerivationManagerV0 { index: Arc::new(Mutex::new(0)), use_cache: Arc::new(AtomicBool::new(true)), - cache: Arc::new(Mutex::new(change_keys.unwrap_or(HashMap::new()))), + cache: Arc::new(Mutex::new(change_keys.unwrap_or_default())), inner: Arc::new(Mutex::new(None)), }; let wallet = Self { diff --git a/wallet/core/src/derivation/mod.rs b/wallet/core/src/derivation/mod.rs index 4eba948de..28a6098d9 100644 --- a/wallet/core/src/derivation/mod.rs +++ b/wallet/core/src/derivation/mod.rs @@ -17,7 +17,6 @@ use kaspa_consensus_core::network::NetworkType; use kaspa_txscript::{ extract_script_pub_key_address, multisig_redeem_script, multisig_redeem_script_ecdsa, pay_to_script_hash_script, }; -use kaspa_utils::hex::ToHex; use std::collections::HashMap; use std::sync::{Arc, Mutex, MutexGuard}; use wasm_bindgen::prelude::*; diff --git a/wallet/core/src/runtime/account/variants/legacy.rs b/wallet/core/src/runtime/account/variants/legacy.rs index 216bef1bb..558e583f5 100644 --- a/wallet/core/src/runtime/account/variants/legacy.rs +++ b/wallet/core/src/runtime/account/variants/legacy.rs @@ -118,13 +118,13 @@ impl Account for Legacy { fn receive_address(&self) -> Result
{ //self.info()?.receive_address.clone().ok_or(Error::Custom("Account initialization is pending.".into())) - Ok(self.derivation.receive_address_manager().current_address()?) + self.derivation.receive_address_manager().current_address() //Ok(self.receive_address.clone()) } fn change_address(&self) -> Result
{ //self.info()?.change_address.clone().ok_or(Error::Custom("Account initialization is pending.".into())) - Ok(self.derivation.change_address_manager().current_address()?) + self.derivation.change_address_manager().current_address() //Ok(self.change_address.clone()) } diff --git a/wallet/core/src/runtime/wallet.rs b/wallet/core/src/runtime/wallet.rs index ccf6a9c01..3a0019cc8 100644 --- a/wallet/core/src/runtime/wallet.rs +++ b/wallet/core/src/runtime/wallet.rs @@ -296,7 +296,6 @@ impl Wallet { Ok(()) } - /// Loads a wallet from storage. Accounts are not activated by this call. pub async fn load(self: &Arc, secret: Secret, name: Option) -> Result<()> { if let Err(err) = self.load_impl(secret, name).await { diff --git a/wallet/core/src/storage/account.rs b/wallet/core/src/storage/account.rs index 061fe0eb1..9476b94ff 100644 --- a/wallet/core/src/storage/account.rs +++ b/wallet/core/src/storage/account.rs @@ -16,7 +16,7 @@ const LEGACY_ACCOUNT_VERSION: u16 = 0; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub struct Legacy { - pub version: u16 + pub version: u16, } impl Legacy { @@ -25,6 +25,12 @@ impl Legacy { } } +impl Default for Legacy { + fn default() -> Self { + Self::new() + } +} + const BIP32_ACCOUNT_VERSION: u16 = 0; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] diff --git a/wallet/core/src/storage/keydata.rs b/wallet/core/src/storage/keydata.rs index 17e84a918..b1ff01276 100644 --- a/wallet/core/src/storage/keydata.rs +++ b/wallet/core/src/storage/keydata.rs @@ -269,6 +269,11 @@ impl PrvKeyData { create_xpub_from_xprv(xprv, account_kind, account_index).await } + pub fn get_xprv(&self, payment_secret: Option<&Secret>) -> Result> { + let payload = self.payload.decrypt(payment_secret)?; + payload.get_xprv(payment_secret) + } + pub fn as_mnemonic(&self, payment_secret: Option<&Secret>) -> Result> { let payload = self.payload.decrypt(payment_secret)?; payload.as_mnemonic()