From 9ed36875f1112d884f6c3c2beab89faf8aa5d2e0 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Tue, 19 Apr 2022 11:44:50 +0200 Subject: [PATCH] export: Rename `WalletExport` to `FullyNodedExport` The `WalletExport` type can still be used as an alias to `FullyNodedExport` but it has been marked as deprecated and will be removed in the next release. --- CHANGELOG.md | 1 + src/wallet/export.rs | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ba0d603..7f2091c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Deprecate `database::Database::flush()`, the function is only needed for the sled database on mobile, instead for mobile use the sqlite database. - Add `keychain: KeychainKind` to `wallet::AddressInfo`. - Improve key generation traits +- Rename `WalletExport` to `FullyNodedExport`, deprecate the former. ## [v0.17.0] - [v0.16.1] diff --git a/src/wallet/export.rs b/src/wallet/export.rs index 69b8c63f..026083e0 100644 --- a/src/wallet/export.rs +++ b/src/wallet/export.rs @@ -29,7 +29,7 @@ //! "label":"testnet" //! }"#; //! -//! let import = WalletExport::from_str(import)?; +//! let import = FullyNodedExport::from_str(import)?; //! let wallet = Wallet::new( //! &import.descriptor(), //! import.change_descriptor().as_ref(), @@ -51,7 +51,7 @@ //! Network::Testnet, //! MemoryDatabase::default() //! )?; -//! let export = WalletExport::export_wallet(&wallet, "exported wallet", true) +//! let export = FullyNodedExport::export_wallet(&wallet, "exported wallet", true) //! .map_err(ToString::to_string) //! .map_err(bdk::Error::Generic)?; //! @@ -70,11 +70,15 @@ use crate::database::BatchDatabase; use crate::types::KeychainKind; use crate::wallet::Wallet; +/// Alias for [`FullyNodedExport`] +#[deprecated(since = "0.18.0", note = "Please use [`FullyNodedExport`] instead")] +pub type WalletExport = FullyNodedExport; + /// Structure that contains the export of a wallet /// /// For a usage example see [this module](crate::wallet::export)'s documentation. #[derive(Debug, Serialize, Deserialize)] -pub struct WalletExport { +pub struct FullyNodedExport { descriptor: String, /// Earliest block to rescan when looking for the wallet's transactions pub blockheight: u32, @@ -82,13 +86,13 @@ pub struct WalletExport { pub label: String, } -impl ToString for WalletExport { +impl ToString for FullyNodedExport { fn to_string(&self) -> String { serde_json::to_string(self).unwrap() } } -impl FromStr for WalletExport { +impl FromStr for FullyNodedExport { type Err = serde_json::Error; fn from_str(s: &str) -> Result { @@ -100,7 +104,7 @@ fn remove_checksum(s: String) -> String { s.splitn(2, '#').next().map(String::from).unwrap() } -impl WalletExport { +impl FullyNodedExport { /// Export a wallet /// /// This function returns an error if it determines that the `wallet`'s descriptor(s) are not @@ -141,7 +145,7 @@ impl WalletExport { } }; - let export = WalletExport { + let export = FullyNodedExport { descriptor, label: label.into(), blockheight, @@ -265,7 +269,7 @@ mod test { get_test_db(), ) .unwrap(); - let export = WalletExport::export_wallet(&wallet, "Test Label", true).unwrap(); + let export = FullyNodedExport::export_wallet(&wallet, "Test Label", true).unwrap(); assert_eq!(export.descriptor(), descriptor); assert_eq!(export.change_descriptor(), Some(change_descriptor.into())); @@ -283,7 +287,7 @@ mod test { let descriptor = "wpkh(xprv9s21ZrQH143K4CTb63EaMxja1YiTnSEWKMbn23uoEnAzxjdUJRQkazCAtzxGm4LSoTSVTptoV9RbchnKPW9HxKtZumdyxyikZFDLhogJ5Uj/44'/0'/0'/0/*)"; let wallet = Wallet::new(descriptor, None, Network::Bitcoin, get_test_db()).unwrap(); - WalletExport::export_wallet(&wallet, "Test Label", true).unwrap(); + FullyNodedExport::export_wallet(&wallet, "Test Label", true).unwrap(); } #[test] @@ -302,7 +306,7 @@ mod test { get_test_db(), ) .unwrap(); - WalletExport::export_wallet(&wallet, "Test Label", true).unwrap(); + FullyNodedExport::export_wallet(&wallet, "Test Label", true).unwrap(); } #[test] @@ -325,7 +329,7 @@ mod test { get_test_db(), ) .unwrap(); - let export = WalletExport::export_wallet(&wallet, "Test Label", true).unwrap(); + let export = FullyNodedExport::export_wallet(&wallet, "Test Label", true).unwrap(); assert_eq!(export.descriptor(), descriptor); assert_eq!(export.change_descriptor(), Some(change_descriptor.into())); @@ -345,7 +349,7 @@ mod test { get_test_db(), ) .unwrap(); - let export = WalletExport::export_wallet(&wallet, "Test Label", true).unwrap(); + let export = FullyNodedExport::export_wallet(&wallet, "Test Label", true).unwrap(); assert_eq!(export.to_string(), "{\"descriptor\":\"wpkh(xprv9s21ZrQH143K4CTb63EaMxja1YiTnSEWKMbn23uoEnAzxjdUJRQkazCAtzxGm4LSoTSVTptoV9RbchnKPW9HxKtZumdyxyikZFDLhogJ5Uj/44\'/0\'/0\'/0/*)\",\"blockheight\":5000,\"label\":\"Test Label\"}"); } @@ -356,7 +360,7 @@ mod test { let change_descriptor = "wpkh(xprv9s21ZrQH143K4CTb63EaMxja1YiTnSEWKMbn23uoEnAzxjdUJRQkazCAtzxGm4LSoTSVTptoV9RbchnKPW9HxKtZumdyxyikZFDLhogJ5Uj/44'/0'/0'/1/*)"; let import_str = "{\"descriptor\":\"wpkh(xprv9s21ZrQH143K4CTb63EaMxja1YiTnSEWKMbn23uoEnAzxjdUJRQkazCAtzxGm4LSoTSVTptoV9RbchnKPW9HxKtZumdyxyikZFDLhogJ5Uj/44\'/0\'/0\'/0/*)\",\"blockheight\":5000,\"label\":\"Test Label\"}"; - let export = WalletExport::from_str(import_str).unwrap(); + let export = FullyNodedExport::from_str(import_str).unwrap(); assert_eq!(export.descriptor(), descriptor); assert_eq!(export.change_descriptor(), Some(change_descriptor.into()));