Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWK cache removal: remove dependency on hash tag #102

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions lib/ls-sdk-core/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ use lwk_common::{singlesig_desc, Signer, Singlesig};
use lwk_signer::{AnySigner, SwSigner};
use lwk_wollet::{
elements::{Address, Transaction},
full_scan_with_electrum_client,
hashes::{sha256t_hash_newtype, Hash},
BlockchainBackend, ElectrumClient, ElectrumUrl, ElementsNetwork, FsPersister,
Wollet as LwkWollet, WolletDescriptor,
full_scan_with_electrum_client, BlockchainBackend, ElectrumClient, ElectrumUrl,
ElementsNetwork, FsPersister, Wollet as LwkWollet, WolletDescriptor,
};

use crate::{
Expand All @@ -37,13 +35,6 @@ use crate::{
DEFAULT_DATA_DIR,
};

sha256t_hash_newtype! {
struct DirectoryIdTag = hash_str("LWK-FS-Directory-Id/1.0");

#[hash_newtype(forward)]
struct DirectoryIdHash(_);
}

pub struct Wallet {
signer: SwSigner,
electrum_url: ElectrumUrl,
Expand Down Expand Up @@ -579,14 +570,12 @@ impl Wallet {
Ok(txid)
}

/// Empties all Liquid Wallet caches for this network type.
pub fn empty_wallet_cache(&self) -> Result<()> {
let mut path = PathBuf::from(self.data_dir_path.clone());
path.push(Into::<ElementsNetwork>::into(self.network).as_str());
path.push("enc_cache");

let descriptor = Wallet::get_descriptor(&self.get_signer(), self.network)?;
path.push(DirectoryIdHash::hash(descriptor.to_string().as_bytes()).to_string());

fs::remove_dir_all(&path)?;
fs::create_dir_all(path)?;

Expand Down