Skip to content

Commit

Permalink
code formatting + cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder83singh committed Oct 26, 2023
1 parent 8856c98 commit af8675a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
20 changes: 10 additions & 10 deletions wallet/core/src/derivation/gen0/hd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
// let locked = self.opt_inner();
Expand Down Expand Up @@ -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)
})
Expand All @@ -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()))
}
Expand All @@ -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()))
Expand Down Expand Up @@ -236,7 +236,7 @@ impl PubkeyDerivationManagerV0 {

impl From<&PubkeyDerivationManagerV0> for ExtendedPublicKey<secp256k1::PublicKey> {
fn from(inner: &PubkeyDerivationManagerV0) -> ExtendedPublicKey<secp256k1::PublicKey> {
ExtendedPublicKey { public_key: inner.public_key_().unwrap().clone(), attrs: inner.attrs().clone() }
ExtendedPublicKey { public_key: inner.public_key_().unwrap(), attrs: inner.attrs().clone() }
}
}

Expand All @@ -248,7 +248,7 @@ impl PubkeyDerivationManagerTrait for PubkeyDerivationManagerV0 {
}

fn index(&self) -> Result<u32> {
Ok(self.index_()?)
self.index_()
}

fn set_index(&self, index: u32) -> Result<()> {
Expand Down Expand Up @@ -439,7 +439,7 @@ impl WalletDerivationManagerV0 {
xkey: &ExtendedPrivateKey<secp256k1::SecretKey>,
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)?;
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion wallet/core/src/derivation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
4 changes: 2 additions & 2 deletions wallet/core/src/runtime/account/variants/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ impl Account for Legacy {

fn receive_address(&self) -> Result<Address> {
//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<Address> {
//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())
}

Expand Down
1 change: 0 additions & 1 deletion wallet/core/src/runtime/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Wallet>, secret: Secret, name: Option<String>) -> Result<()> {
if let Err(err) = self.load_impl(secret, name).await {
Expand Down
8 changes: 7 additions & 1 deletion wallet/core/src/storage/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")]
Expand Down
5 changes: 5 additions & 0 deletions wallet/core/src/storage/keydata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtendedPrivateKey<secp256k1::SecretKey>> {
let payload = self.payload.decrypt(payment_secret)?;
payload.get_xprv(payment_secret)
}

pub fn as_mnemonic(&self, payment_secret: Option<&Secret>) -> Result<Option<Mnemonic>> {
let payload = self.payload.decrypt(payment_secret)?;
payload.as_mnemonic()
Expand Down

0 comments on commit af8675a

Please sign in to comment.