From 70c7d6b1c064103b359ad2e774a2648fbd85a414 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Thu, 25 Jul 2024 16:51:16 +0200 Subject: [PATCH] bdk_wallet: remove unnecessary calls to calc_checksum 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 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/wallet/src/wallet/mod.rs b/crates/wallet/src/wallet/mod.rs index df22c8a6..7217d32f 100644 --- a/crates/wallet/src/wallet/mod.rs +++ b/crates/wallet/src/wallet/mod.rs @@ -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) -- 2.49.0