]> Untitled Git - bdk/commitdiff
Update docs and tests based on review comments
authorSteve Myers <steve@notmandatory.org>
Tue, 25 Oct 2022 16:20:22 +0000 (11:20 -0500)
committerSteve Myers <steve@notmandatory.org>
Tue, 25 Oct 2022 16:20:22 +0000 (11:20 -0500)
src/descriptor/checksum.rs
src/wallet/mod.rs

index de2b0681fdeda90e906c441d6f624d501e25e4f4..6be3a2444bc8f5bba6b15fc3e986ed12eb3e3941 100644 (file)
@@ -94,12 +94,12 @@ pub(crate) fn calc_checksum_bytes_internal(
     Ok(checksum)
 }
 
-/// Compute the checksum bytes of a descriptor, any existing checksum hash will be excluded from the calculation
+/// Compute the checksum bytes of a descriptor, excludes any existing checksum in the descriptor string from the calculation
 pub fn calc_checksum_bytes(desc: &str) -> Result<[u8; 8], DescriptorError> {
     calc_checksum_bytes_internal(desc, true)
 }
 
-/// Compute the checksum of a descriptor, any existing checksum hash will be excluded from the calculation
+/// Compute the checksum of a descriptor, excludes any existing checksum in the descriptor string from the calculation
 pub fn calc_checksum(desc: &str) -> Result<String, DescriptorError> {
     // unsafe is okay here as the checksum only uses bytes in `CHECKSUM_CHARSET`
     calc_checksum_bytes_internal(desc, true)
@@ -112,7 +112,7 @@ pub fn calc_checksum(desc: &str) -> Result<String, DescriptorError> {
 /// Compute the checksum bytes of a descriptor
 #[deprecated(
     since = "0.24.0",
-    note = "Use new `calc_checksum_bytes` function which excludes any existing hash before calculating the checksum hash bytes. See https://github.com/bitcoindevkit/bdk/pull/765."
+    note = "Use new `calc_checksum_bytes` function which excludes any existing checksum in the descriptor string before calculating the checksum hash bytes. See https://github.com/bitcoindevkit/bdk/pull/765."
 )]
 pub fn get_checksum_bytes(desc: &str) -> Result<[u8; 8], DescriptorError> {
     calc_checksum_bytes_internal(desc, false)
@@ -121,7 +121,7 @@ pub fn get_checksum_bytes(desc: &str) -> Result<[u8; 8], DescriptorError> {
 /// Compute the checksum of a descriptor
 #[deprecated(
     since = "0.24.0",
-    note = "Use new `calc_checksum` function which excludes any existing hash before calculating the checksum hash. See https://github.com/bitcoindevkit/bdk/pull/765."
+    note = "Use new `calc_checksum` function which excludes any existing checksum in the descriptor string before calculating the checksum hash. See https://github.com/bitcoindevkit/bdk/pull/765."
 )]
 pub fn get_checksum(desc: &str) -> Result<String, DescriptorError> {
     // unsafe is okay here as the checksum only uses bytes in `CHECKSUM_CHARSET`
@@ -153,6 +153,18 @@ mod test {
 
         let desc = "pkh(tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/44'/1'/0'/0/*)#lasegmfs";
         assert_eq!(calc_checksum(desc).unwrap(), "lasegmfs");
+
+        let desc = "wpkh(tprv8ZgxMBicQKsPdpkqS7Eair4YxjcuuvDPNYmKX3sCniCf16tHEVrjjiSXEkFRnUH77yXc6ZcwHHcLNfjdi5qUvw3VDfgYiH5mNsj5izuiu2N/1/2/*)#tqz0nc26";
+        assert!(matches!(
+            calc_checksum(desc).err(),
+            Some(DescriptorError::InvalidDescriptorChecksum)
+        ));
+
+        let desc = "pkh(tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/44'/1'/0'/0/*)#lasegmsf";
+        assert!(matches!(
+            calc_checksum(desc).err(),
+            Some(DescriptorError::InvalidDescriptorChecksum)
+        ));
     }
 
     #[test]
index 8c52e82c918b0e63c327bc9a3b64a72f098ad43c..07690e3fadf86449bbab661fafe2029e013ff12e 100644 (file)
@@ -210,7 +210,6 @@ where
             KeychainKind::External,
         )?;
         let signers = Arc::new(SignersContainer::build(keymap, &descriptor, &secp));
-
         let (change_descriptor, change_signers) = match change_descriptor {
             Some(desc) => {
                 let (change_descriptor, change_keymap) =