Skip to content

Commit

Permalink
wallet: fix data descriptor initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Sep 7, 2024
1 parent 1aba927 commit c60db06
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl<K, D: Descriptor<K>, L2: Layer2Descriptor> Drop for WalletDescr<K, D, L2> {
}
}

#[derive(Debug, Default)]
#[derive(Debug)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
Expand Down Expand Up @@ -232,6 +232,39 @@ impl<L2: Layer2Data> Persisting for WalletData<L2> {
fn as_mut_persistence(&mut self) -> &mut Option<Persistence<Self>> { &mut self.persistence }
}

impl WalletData<NoLayer2> {
pub fn new_layer1<K, D: Descriptor<K>>(descriptor: &D) -> Self {
WalletData {
persistence: None,
descriptor: descriptor.to_string(),
name: none!(),
tx_annotations: empty!(),
txout_annotations: empty!(),
txin_annotations: empty!(),
addr_annotations: empty!(),
layer2_annotations: none!(),
last_used: empty!(),
}
}

Check warning on line 248 in src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

src/wallet.rs#L236-L248

Added lines #L236 - L248 were not covered by tests
}

impl<L2: Layer2Data> WalletData<L2> {
pub fn new_layer2<K, D: Descriptor<K>>(descriptor: &D) -> Self
where L2: Default {
WalletData {
persistence: None,
descriptor: descriptor.to_string(),
name: none!(),
tx_annotations: empty!(),
txout_annotations: empty!(),
txin_annotations: empty!(),
addr_annotations: empty!(),
layer2_annotations: none!(),
last_used: empty!(),
}
}

Check warning on line 265 in src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

src/wallet.rs#L252-L265

Added lines #L252 - L265 were not covered by tests
}

impl<L2: Layer2Data> Drop for WalletData<L2> {
fn drop(&mut self) {
if self.is_autosave() {
Expand Down Expand Up @@ -433,8 +466,8 @@ impl<K, D: Descriptor<K>> Wallet<K, D> {
pub fn new_layer1(descr: D, network: Network) -> Self {
Wallet {
cache: WalletCache::new_nonsync(&descr),
data: WalletData::new_layer1(&descr),

Check warning on line 469 in src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

src/wallet.rs#L469

Added line #L469 was not covered by tests
descr: WalletDescr::new_standard(descr, network),
data: empty!(),
layer2: none!(),
}
}
Expand All @@ -444,8 +477,8 @@ impl<K, D: Descriptor<K>, L2: Layer2> Wallet<K, D, L2> {
pub fn new_layer2(descr: D, l2_descr: L2::Descr, layer2: L2, network: Network) -> Self {
Wallet {
cache: WalletCache::new_nonsync(&descr),
data: WalletData::new_layer2(&descr),

Check warning on line 480 in src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

src/wallet.rs#L480

Added line #L480 was not covered by tests
descr: WalletDescr::new_layer2(descr, l2_descr, network),
data: empty!(),
layer2,
}
}
Expand Down Expand Up @@ -563,10 +596,14 @@ impl<K, D: Descriptor<K>, L2: Layer2> Wallet<K, D, L2> {
+ PersistenceProvider<L2>
+ 'static {
let descr = WalletDescr::<K, D, L2::Descr>::load(provider.clone(), autosave)?;
let data = WalletData::<L2::Data>::load(provider.clone(), autosave)?;
let cache = WalletCache::<L2::Cache>::load(provider.clone(), autosave)?;
let mut data = WalletData::<L2::Data>::load(provider.clone(), autosave)?;
let mut cache = WalletCache::<L2::Cache>::load(provider.clone(), autosave)?;

Check warning on line 600 in src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

src/wallet.rs#L599-L600

Added lines #L599 - L600 were not covered by tests
let layer2 = L2::load(provider, autosave)?;

let descriptor = descr.generator.to_string();
data.descriptor = descriptor.clone();
cache.descriptor = descriptor.clone();

Check warning on line 606 in src/wallet.rs

View check run for this annotation

Codecov / codecov/patch

src/wallet.rs#L603-L606

Added lines #L603 - L606 were not covered by tests
Ok(Wallet {
descr,
data,
Expand Down

0 comments on commit c60db06

Please sign in to comment.