]> Untitled Git - bdk/commitdiff
bdk_wallet: remove unnecessary calls to calc_checksum
authorAntoine Poinsot <darosior@protonmail.com>
Thu, 25 Jul 2024 14:51:16 +0000 (16:51 +0200)
committerAntoine Poinsot <darosior@protonmail.com>
Sat, 27 Jul 2024 15:56:02 +0000 (17:56 +0200)
This code was:
1. Removing the checksum from the descriptor string, asserting it was
   present
2. Re-calculating the checksum on the descriptor string absent the
   checksum

Instead, just use the existing checksum? If we don't trust it we
probably shouldn't assert its presence in the first place.

crates/wallet/src/wallet/mod.rs

index df22c8a6413ca6b0530d599c3bbf46efb9feec82..7217d32fb44e4d8d332da5ebfb9da3706712f5a9 100644 (file)
@@ -79,7 +79,7 @@ use utils::{check_nsequence_rbf, After, Older, SecpCtx};
 
 use crate::descriptor::policy::BuildSatisfaction;
 use crate::descriptor::{
-    self, calc_checksum, DerivedDescriptor, DescriptorMeta, ExtendedDescriptor, ExtractPolicy,
+    self, DerivedDescriptor, DescriptorMeta, ExtendedDescriptor, ExtractPolicy,
     IntoWalletDescriptor, Policy, XKeyUtils,
 };
 use crate::psbt::PsbtUtils;
@@ -2360,15 +2360,13 @@ where
         .into_wallet_descriptor(secp, network)?
         .0
         .to_string();
-    let mut wallet_name = calc_checksum(&descriptor[..descriptor.find('#').unwrap()])?;
+    let mut wallet_name = descriptor.split_once('#').unwrap().1.to_string();
     if let Some(change_descriptor) = change_descriptor {
         let change_descriptor = change_descriptor
             .into_wallet_descriptor(secp, network)?
             .0
             .to_string();
-        wallet_name.push_str(
-            calc_checksum(&change_descriptor[..change_descriptor.find('#').unwrap()])?.as_str(),
-        );
+        wallet_name.push_str(change_descriptor.split_once('#').unwrap().1);
     }
 
     Ok(wallet_name)