refactor: rename inner field names
This commit is contained in:
		
							parent
							
								
									c3e8469686
								
							
						
					
					
						commit
						7717ebb097
					
				| @ -17,7 +17,7 @@ use std::path::PathBuf; | |||||||
| use std::sync::{Arc, Mutex, MutexGuard}; | use std::sync::{Arc, Mutex, MutexGuard}; | ||||||
| 
 | 
 | ||||||
| pub(crate) struct Blockchain { | pub(crate) struct Blockchain { | ||||||
|     blockchain_mutex: Mutex<AnyBlockchain>, |     inner_mutex: Mutex<AnyBlockchain>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Blockchain { | impl Blockchain { | ||||||
| @ -52,16 +52,16 @@ impl Blockchain { | |||||||
|         }; |         }; | ||||||
|         let blockchain = AnyBlockchain::from_config(&any_blockchain_config)?; |         let blockchain = AnyBlockchain::from_config(&any_blockchain_config)?; | ||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             blockchain_mutex: Mutex::new(blockchain), |             inner_mutex: Mutex::new(blockchain), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn get_blockchain(&self) -> MutexGuard<AnyBlockchain> { |     pub(crate) fn get_blockchain(&self) -> MutexGuard<AnyBlockchain> { | ||||||
|         self.blockchain_mutex.lock().expect("blockchain") |         self.inner_mutex.lock().expect("blockchain") | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn broadcast(&self, transaction: &Transaction) -> Result<(), BdkError> { |     pub(crate) fn broadcast(&self, transaction: &Transaction) -> Result<(), BdkError> { | ||||||
|         let tx = &transaction.internal; |         let tx = &transaction.inner; | ||||||
|         self.get_blockchain().broadcast(tx) |         self.get_blockchain().broadcast(tx) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -36,7 +36,7 @@ impl Descriptor { | |||||||
|         keychain_kind: KeychainKind, |         keychain_kind: KeychainKind, | ||||||
|         network: Network, |         network: Network, | ||||||
|     ) -> Self { |     ) -> Self { | ||||||
|         let derivable_key = secret_key.descriptor_secret_key_mutex.lock().unwrap(); |         let derivable_key = secret_key.inner_mutex.lock().unwrap(); | ||||||
| 
 | 
 | ||||||
|         match derivable_key.deref() { |         match derivable_key.deref() { | ||||||
|             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { |             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { | ||||||
| @ -61,7 +61,7 @@ impl Descriptor { | |||||||
|         network: Network, |         network: Network, | ||||||
|     ) -> Self { |     ) -> Self { | ||||||
|         let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); |         let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); | ||||||
|         let derivable_key = public_key.descriptor_public_key_mutex.lock().unwrap(); |         let derivable_key = public_key.inner_mutex.lock().unwrap(); | ||||||
| 
 | 
 | ||||||
|         match derivable_key.deref() { |         match derivable_key.deref() { | ||||||
|             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { |             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { | ||||||
| @ -87,7 +87,7 @@ impl Descriptor { | |||||||
|         keychain_kind: KeychainKind, |         keychain_kind: KeychainKind, | ||||||
|         network: Network, |         network: Network, | ||||||
|     ) -> Self { |     ) -> Self { | ||||||
|         let derivable_key = secret_key.descriptor_secret_key_mutex.lock().unwrap(); |         let derivable_key = secret_key.inner_mutex.lock().unwrap(); | ||||||
| 
 | 
 | ||||||
|         match derivable_key.deref() { |         match derivable_key.deref() { | ||||||
|             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { |             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { | ||||||
| @ -112,7 +112,7 @@ impl Descriptor { | |||||||
|         network: Network, |         network: Network, | ||||||
|     ) -> Self { |     ) -> Self { | ||||||
|         let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); |         let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); | ||||||
|         let derivable_key = public_key.descriptor_public_key_mutex.lock().unwrap(); |         let derivable_key = public_key.inner_mutex.lock().unwrap(); | ||||||
| 
 | 
 | ||||||
|         match derivable_key.deref() { |         match derivable_key.deref() { | ||||||
|             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { |             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { | ||||||
| @ -138,7 +138,7 @@ impl Descriptor { | |||||||
|         keychain_kind: KeychainKind, |         keychain_kind: KeychainKind, | ||||||
|         network: Network, |         network: Network, | ||||||
|     ) -> Self { |     ) -> Self { | ||||||
|         let derivable_key = secret_key.descriptor_secret_key_mutex.lock().unwrap(); |         let derivable_key = secret_key.inner_mutex.lock().unwrap(); | ||||||
| 
 | 
 | ||||||
|         match derivable_key.deref() { |         match derivable_key.deref() { | ||||||
|             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { |             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { | ||||||
| @ -163,7 +163,7 @@ impl Descriptor { | |||||||
|         network: Network, |         network: Network, | ||||||
|     ) -> Self { |     ) -> Self { | ||||||
|         let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); |         let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); | ||||||
|         let derivable_key = public_key.descriptor_public_key_mutex.lock().unwrap(); |         let derivable_key = public_key.inner_mutex.lock().unwrap(); | ||||||
| 
 | 
 | ||||||
|         match derivable_key.deref() { |         match derivable_key.deref() { | ||||||
|             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { |             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { | ||||||
| @ -189,7 +189,7 @@ impl Descriptor { | |||||||
|         keychain_kind: KeychainKind, |         keychain_kind: KeychainKind, | ||||||
|         network: Network, |         network: Network, | ||||||
|     ) -> Self { |     ) -> Self { | ||||||
|         let derivable_key = secret_key.descriptor_secret_key_mutex.lock().unwrap(); |         let derivable_key = secret_key.inner_mutex.lock().unwrap(); | ||||||
| 
 | 
 | ||||||
|         match derivable_key.deref() { |         match derivable_key.deref() { | ||||||
|             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { |             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { | ||||||
| @ -214,7 +214,7 @@ impl Descriptor { | |||||||
|         network: Network, |         network: Network, | ||||||
|     ) -> Self { |     ) -> Self { | ||||||
|         let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); |         let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); | ||||||
|         let derivable_key = public_key.descriptor_public_key_mutex.lock().unwrap(); |         let derivable_key = public_key.inner_mutex.lock().unwrap(); | ||||||
| 
 | 
 | ||||||
|         match derivable_key.deref() { |         match derivable_key.deref() { | ||||||
|             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { |             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { | ||||||
|  | |||||||
| @ -17,7 +17,7 @@ use std::sync::{Arc, Mutex}; | |||||||
| /// Mnemonic phrases are a human-readable version of the private keys.
 | /// Mnemonic phrases are a human-readable version of the private keys.
 | ||||||
| /// Supported number of words are 12, 15, 18, 21 and 24.
 | /// Supported number of words are 12, 15, 18, 21 and 24.
 | ||||||
| pub(crate) struct Mnemonic { | pub(crate) struct Mnemonic { | ||||||
|     internal: BdkMnemonic, |     inner: BdkMnemonic, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Mnemonic { | impl Mnemonic { | ||||||
| @ -26,13 +26,13 @@ impl Mnemonic { | |||||||
|         let generated_key: GeneratedKey<_, BareCtx> = |         let generated_key: GeneratedKey<_, BareCtx> = | ||||||
|             BdkMnemonic::generate((word_count, Language::English)).unwrap(); |             BdkMnemonic::generate((word_count, Language::English)).unwrap(); | ||||||
|         let mnemonic = BdkMnemonic::parse_in(Language::English, generated_key.to_string()).unwrap(); |         let mnemonic = BdkMnemonic::parse_in(Language::English, generated_key.to_string()).unwrap(); | ||||||
|         Mnemonic { internal: mnemonic } |         Mnemonic { inner: mnemonic } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Parse a Mnemonic with given string
 |     /// Parse a Mnemonic with given string
 | ||||||
|     pub(crate) fn from_string(mnemonic: String) -> Result<Self, BdkError> { |     pub(crate) fn from_string(mnemonic: String) -> Result<Self, BdkError> { | ||||||
|         BdkMnemonic::from_str(&mnemonic) |         BdkMnemonic::from_str(&mnemonic) | ||||||
|             .map(|m| Mnemonic { internal: m }) |             .map(|m| Mnemonic { inner: m }) | ||||||
|             .map_err(|e| BdkError::Generic(e.to_string())) |             .map_err(|e| BdkError::Generic(e.to_string())) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -40,25 +40,25 @@ impl Mnemonic { | |||||||
|     /// Entropy must be a multiple of 32 bits (4 bytes) and 128-256 bits in length.
 |     /// Entropy must be a multiple of 32 bits (4 bytes) and 128-256 bits in length.
 | ||||||
|     pub(crate) fn from_entropy(entropy: Vec<u8>) -> Result<Self, BdkError> { |     pub(crate) fn from_entropy(entropy: Vec<u8>) -> Result<Self, BdkError> { | ||||||
|         BdkMnemonic::from_entropy(entropy.as_slice()) |         BdkMnemonic::from_entropy(entropy.as_slice()) | ||||||
|             .map(|m| Mnemonic { internal: m }) |             .map(|m| Mnemonic { inner: m }) | ||||||
|             .map_err(|e| BdkError::Generic(e.to_string())) |             .map_err(|e| BdkError::Generic(e.to_string())) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Returns Mnemonic as string
 |     /// Returns Mnemonic as string
 | ||||||
|     pub(crate) fn as_string(&self) -> String { |     pub(crate) fn as_string(&self) -> String { | ||||||
|         self.internal.to_string() |         self.inner.to_string() | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub(crate) struct DerivationPath { | pub(crate) struct DerivationPath { | ||||||
|     derivation_path_mutex: Mutex<BdkDerivationPath>, |     inner_mutex: Mutex<BdkDerivationPath>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl DerivationPath { | impl DerivationPath { | ||||||
|     pub(crate) fn new(path: String) -> Result<Self, BdkError> { |     pub(crate) fn new(path: String) -> Result<Self, BdkError> { | ||||||
|         BdkDerivationPath::from_str(&path) |         BdkDerivationPath::from_str(&path) | ||||||
|             .map(|x| DerivationPath { |             .map(|x| DerivationPath { | ||||||
|                 derivation_path_mutex: Mutex::new(x), |                 inner_mutex: Mutex::new(x), | ||||||
|             }) |             }) | ||||||
|             .map_err(|e| BdkError::Generic(e.to_string())) |             .map_err(|e| BdkError::Generic(e.to_string())) | ||||||
|     } |     } | ||||||
| @ -66,36 +66,36 @@ impl DerivationPath { | |||||||
| 
 | 
 | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| pub(crate) struct DescriptorSecretKey { | pub(crate) struct DescriptorSecretKey { | ||||||
|     pub(crate) descriptor_secret_key_mutex: Mutex<BdkDescriptorSecretKey>, |     pub(crate) inner_mutex: Mutex<BdkDescriptorSecretKey>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl DescriptorSecretKey { | impl DescriptorSecretKey { | ||||||
|     pub(crate) fn new(network: Network, mnemonic: Arc<Mnemonic>, password: Option<String>) -> Self { |     pub(crate) fn new(network: Network, mnemonic: Arc<Mnemonic>, password: Option<String>) -> Self { | ||||||
|         let mnemonic = mnemonic.internal.clone(); |         let mnemonic = mnemonic.inner.clone(); | ||||||
|         let xkey: ExtendedKey = (mnemonic, password).into_extended_key().unwrap(); |         let xkey: ExtendedKey = (mnemonic, password).into_extended_key().unwrap(); | ||||||
|         let descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey { |         let inner = BdkDescriptorSecretKey::XPrv(DescriptorXKey { | ||||||
|             origin: None, |             origin: None, | ||||||
|             xkey: xkey.into_xprv(network).unwrap(), |             xkey: xkey.into_xprv(network).unwrap(), | ||||||
|             derivation_path: BdkDerivationPath::master(), |             derivation_path: BdkDerivationPath::master(), | ||||||
|             wildcard: bdk::descriptor::Wildcard::Unhardened, |             wildcard: bdk::descriptor::Wildcard::Unhardened, | ||||||
|         }); |         }); | ||||||
|         Self { |         Self { | ||||||
|             descriptor_secret_key_mutex: Mutex::new(descriptor_secret_key), |             inner_mutex: Mutex::new(inner), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn from_string(private_key: String) -> Result<Self, BdkError> { |     pub(crate) fn from_string(private_key: String) -> Result<Self, BdkError> { | ||||||
|         let descriptor_secret_key = BdkDescriptorSecretKey::from_str(private_key.as_str()) |         let inner = BdkDescriptorSecretKey::from_str(private_key.as_str()) | ||||||
|             .map_err(|e| BdkError::Generic(e.to_string()))?; |             .map_err(|e| BdkError::Generic(e.to_string()))?; | ||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             descriptor_secret_key_mutex: Mutex::new(descriptor_secret_key), |             inner_mutex: Mutex::new(inner), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { |     pub(crate) fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { | ||||||
|         let secp = Secp256k1::new(); |         let secp = Secp256k1::new(); | ||||||
|         let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap(); |         let descriptor_secret_key = self.inner_mutex.lock().unwrap(); | ||||||
|         let path = path.derivation_path_mutex.lock().unwrap().deref().clone(); |         let path = path.inner_mutex.lock().unwrap().deref().clone(); | ||||||
|         match descriptor_secret_key.deref() { |         match descriptor_secret_key.deref() { | ||||||
|             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { |             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { | ||||||
|                 let derived_xprv = descriptor_x_key.xkey.derive_priv(&secp, &path)?; |                 let derived_xprv = descriptor_x_key.xkey.derive_priv(&secp, &path)?; | ||||||
| @ -110,7 +110,7 @@ impl DescriptorSecretKey { | |||||||
|                     wildcard: descriptor_x_key.wildcard, |                     wildcard: descriptor_x_key.wildcard, | ||||||
|                 }); |                 }); | ||||||
|                 Ok(Arc::new(Self { |                 Ok(Arc::new(Self { | ||||||
|                     descriptor_secret_key_mutex: Mutex::new(derived_descriptor_secret_key), |                     inner_mutex: Mutex::new(derived_descriptor_secret_key), | ||||||
|                 })) |                 })) | ||||||
|             } |             } | ||||||
|             BdkDescriptorSecretKey::Single(_) => Err(BdkError::Generic( |             BdkDescriptorSecretKey::Single(_) => Err(BdkError::Generic( | ||||||
| @ -120,19 +120,19 @@ impl DescriptorSecretKey { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn extend(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { |     pub(crate) fn extend(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { | ||||||
|         let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap(); |         let inner = self.inner_mutex.lock().unwrap(); | ||||||
|         let path = path.derivation_path_mutex.lock().unwrap().deref().clone(); |         let path = path.inner_mutex.lock().unwrap().deref().clone(); | ||||||
|         match descriptor_secret_key.deref() { |         match inner.deref() { | ||||||
|             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { |             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { | ||||||
|                 let extended_path = descriptor_x_key.derivation_path.extend(path); |                 let extended_path = descriptor_x_key.derivation_path.extend(path); | ||||||
|                 let extended_descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey { |                 let extended_inner = BdkDescriptorSecretKey::XPrv(DescriptorXKey { | ||||||
|                     origin: descriptor_x_key.origin.clone(), |                     origin: descriptor_x_key.origin.clone(), | ||||||
|                     xkey: descriptor_x_key.xkey, |                     xkey: descriptor_x_key.xkey, | ||||||
|                     derivation_path: extended_path, |                     derivation_path: extended_path, | ||||||
|                     wildcard: descriptor_x_key.wildcard, |                     wildcard: descriptor_x_key.wildcard, | ||||||
|                 }); |                 }); | ||||||
|                 Ok(Arc::new(Self { |                 Ok(Arc::new(Self { | ||||||
|                     descriptor_secret_key_mutex: Mutex::new(extended_descriptor_secret_key), |                     inner_mutex: Mutex::new(extended_inner), | ||||||
|                 })) |                 })) | ||||||
|             } |             } | ||||||
|             BdkDescriptorSecretKey::Single(_) => Err(BdkError::Generic( |             BdkDescriptorSecretKey::Single(_) => Err(BdkError::Generic( | ||||||
| @ -143,21 +143,16 @@ impl DescriptorSecretKey { | |||||||
| 
 | 
 | ||||||
|     pub(crate) fn as_public(&self) -> Arc<DescriptorPublicKey> { |     pub(crate) fn as_public(&self) -> Arc<DescriptorPublicKey> { | ||||||
|         let secp = Secp256k1::new(); |         let secp = Secp256k1::new(); | ||||||
|         let descriptor_public_key = self |         let descriptor_public_key = self.inner_mutex.lock().unwrap().to_public(&secp).unwrap(); | ||||||
|             .descriptor_secret_key_mutex |  | ||||||
|             .lock() |  | ||||||
|             .unwrap() |  | ||||||
|             .to_public(&secp) |  | ||||||
|             .unwrap(); |  | ||||||
|         Arc::new(DescriptorPublicKey { |         Arc::new(DescriptorPublicKey { | ||||||
|             descriptor_public_key_mutex: Mutex::new(descriptor_public_key), |             inner_mutex: Mutex::new(descriptor_public_key), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Get the private key as bytes.
 |     /// Get the private key as bytes.
 | ||||||
|     pub(crate) fn secret_bytes(&self) -> Vec<u8> { |     pub(crate) fn secret_bytes(&self) -> Vec<u8> { | ||||||
|         let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap(); |         let inner = self.inner_mutex.lock().unwrap(); | ||||||
|         let secret_bytes: Vec<u8> = match descriptor_secret_key.deref() { |         let secret_bytes: Vec<u8> = match inner.deref() { | ||||||
|             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { |             BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { | ||||||
|                 descriptor_x_key.xkey.private_key.secret_bytes().to_vec() |                 descriptor_x_key.xkey.private_key.secret_bytes().to_vec() | ||||||
|             } |             } | ||||||
| @ -170,13 +165,13 @@ impl DescriptorSecretKey { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn as_string(&self) -> String { |     pub(crate) fn as_string(&self) -> String { | ||||||
|         self.descriptor_secret_key_mutex.lock().unwrap().to_string() |         self.inner_mutex.lock().unwrap().to_string() | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| pub(crate) struct DescriptorPublicKey { | pub(crate) struct DescriptorPublicKey { | ||||||
|     pub(crate) descriptor_public_key_mutex: Mutex<BdkDescriptorPublicKey>, |     pub(crate) inner_mutex: Mutex<BdkDescriptorPublicKey>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl DescriptorPublicKey { | impl DescriptorPublicKey { | ||||||
| @ -184,14 +179,14 @@ impl DescriptorPublicKey { | |||||||
|         let descriptor_public_key = BdkDescriptorPublicKey::from_str(public_key.as_str()) |         let descriptor_public_key = BdkDescriptorPublicKey::from_str(public_key.as_str()) | ||||||
|             .map_err(|e| BdkError::Generic(e.to_string()))?; |             .map_err(|e| BdkError::Generic(e.to_string()))?; | ||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             descriptor_public_key_mutex: Mutex::new(descriptor_public_key), |             inner_mutex: Mutex::new(descriptor_public_key), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { |     pub(crate) fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { | ||||||
|         let secp = Secp256k1::new(); |         let secp = Secp256k1::new(); | ||||||
|         let descriptor_public_key = self.descriptor_public_key_mutex.lock().unwrap(); |         let descriptor_public_key = self.inner_mutex.lock().unwrap(); | ||||||
|         let path = path.derivation_path_mutex.lock().unwrap().deref().clone(); |         let path = path.inner_mutex.lock().unwrap().deref().clone(); | ||||||
| 
 | 
 | ||||||
|         match descriptor_public_key.deref() { |         match descriptor_public_key.deref() { | ||||||
|             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { |             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { | ||||||
| @ -207,7 +202,7 @@ impl DescriptorPublicKey { | |||||||
|                     wildcard: descriptor_x_key.wildcard, |                     wildcard: descriptor_x_key.wildcard, | ||||||
|                 }); |                 }); | ||||||
|                 Ok(Arc::new(Self { |                 Ok(Arc::new(Self { | ||||||
|                     descriptor_public_key_mutex: Mutex::new(derived_descriptor_public_key), |                     inner_mutex: Mutex::new(derived_descriptor_public_key), | ||||||
|                 })) |                 })) | ||||||
|             } |             } | ||||||
|             BdkDescriptorPublicKey::Single(_) => Err(BdkError::Generic( |             BdkDescriptorPublicKey::Single(_) => Err(BdkError::Generic( | ||||||
| @ -217,8 +212,8 @@ impl DescriptorPublicKey { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn extend(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { |     pub(crate) fn extend(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { | ||||||
|         let descriptor_public_key = self.descriptor_public_key_mutex.lock().unwrap(); |         let descriptor_public_key = self.inner_mutex.lock().unwrap(); | ||||||
|         let path = path.derivation_path_mutex.lock().unwrap().deref().clone(); |         let path = path.inner_mutex.lock().unwrap().deref().clone(); | ||||||
|         match descriptor_public_key.deref() { |         match descriptor_public_key.deref() { | ||||||
|             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { |             BdkDescriptorPublicKey::XPub(descriptor_x_key) => { | ||||||
|                 let extended_path = descriptor_x_key.derivation_path.extend(path); |                 let extended_path = descriptor_x_key.derivation_path.extend(path); | ||||||
| @ -229,7 +224,7 @@ impl DescriptorPublicKey { | |||||||
|                     wildcard: descriptor_x_key.wildcard, |                     wildcard: descriptor_x_key.wildcard, | ||||||
|                 }); |                 }); | ||||||
|                 Ok(Arc::new(Self { |                 Ok(Arc::new(Self { | ||||||
|                     descriptor_public_key_mutex: Mutex::new(extended_descriptor_public_key), |                     inner_mutex: Mutex::new(extended_descriptor_public_key), | ||||||
|                 })) |                 })) | ||||||
|             } |             } | ||||||
|             BdkDescriptorPublicKey::Single(_) => Err(BdkError::Generic( |             BdkDescriptorPublicKey::Single(_) => Err(BdkError::Generic( | ||||||
| @ -239,7 +234,7 @@ impl DescriptorPublicKey { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn as_string(&self) -> String { |     pub(crate) fn as_string(&self) -> String { | ||||||
|         self.descriptor_public_key_mutex.lock().unwrap().to_string() |         self.inner_mutex.lock().unwrap().to_string() | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -254,7 +249,7 @@ mod test { | |||||||
|     use bdk::bitcoin::Network; |     use bdk::bitcoin::Network; | ||||||
|     use std::sync::Arc; |     use std::sync::Arc; | ||||||
| 
 | 
 | ||||||
|     fn get_descriptor_secret_key() -> DescriptorSecretKey { |     fn get_inner() -> DescriptorSecretKey { | ||||||
|         let mnemonic = Mnemonic::from_string("chaos fabric time speed sponsor all flat solution wisdom trophy crack object robot pave observe combine where aware bench orient secret primary cable detect".to_string()).unwrap(); |         let mnemonic = Mnemonic::from_string("chaos fabric time speed sponsor all flat solution wisdom trophy crack object robot pave observe combine where aware bench orient secret primary cable detect".to_string()).unwrap(); | ||||||
|         DescriptorSecretKey::new(Network::Testnet, Arc::new(mnemonic), None) |         DescriptorSecretKey::new(Network::Testnet, Arc::new(mnemonic), None) | ||||||
|     } |     } | ||||||
| @ -293,14 +288,14 @@ mod test { | |||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_generate_descriptor_secret_key() { |     fn test_generate_descriptor_secret_key() { | ||||||
|         let master_dsk = get_descriptor_secret_key(); |         let master_dsk = get_inner(); | ||||||
|         assert_eq!(master_dsk.as_string(), "tprv8ZgxMBicQKsPdWuqM1t1CDRvQtQuBPyfL6GbhQwtxDKgUAVPbxmj71pRA8raTqLrec5LyTs5TqCxdABcZr77bt2KyWA5bizJHnC4g4ysm4h/*"); |         assert_eq!(master_dsk.as_string(), "tprv8ZgxMBicQKsPdWuqM1t1CDRvQtQuBPyfL6GbhQwtxDKgUAVPbxmj71pRA8raTqLrec5LyTs5TqCxdABcZr77bt2KyWA5bizJHnC4g4ysm4h/*"); | ||||||
|         assert_eq!(master_dsk.as_public().as_string(), "tpubD6NzVbkrYhZ4WywdEfYbbd62yuvqLjAZuPsNyvzCNV85JekAEMbKHWSHLF9h3j45SxewXDcLv328B1SEZrxg4iwGfmdt1pDFjZiTkGiFqGa/*"); |         assert_eq!(master_dsk.as_public().as_string(), "tpubD6NzVbkrYhZ4WywdEfYbbd62yuvqLjAZuPsNyvzCNV85JekAEMbKHWSHLF9h3j45SxewXDcLv328B1SEZrxg4iwGfmdt1pDFjZiTkGiFqGa/*"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_derive_self() { |     fn test_derive_self() { | ||||||
|         let master_dsk = get_descriptor_secret_key(); |         let master_dsk = get_inner(); | ||||||
|         let derived_dsk: &DescriptorSecretKey = &derive_dsk(&master_dsk, "m").unwrap(); |         let derived_dsk: &DescriptorSecretKey = &derive_dsk(&master_dsk, "m").unwrap(); | ||||||
|         assert_eq!(derived_dsk.as_string(), "[d1d04177]tprv8ZgxMBicQKsPdWuqM1t1CDRvQtQuBPyfL6GbhQwtxDKgUAVPbxmj71pRA8raTqLrec5LyTs5TqCxdABcZr77bt2KyWA5bizJHnC4g4ysm4h/*"); |         assert_eq!(derived_dsk.as_string(), "[d1d04177]tprv8ZgxMBicQKsPdWuqM1t1CDRvQtQuBPyfL6GbhQwtxDKgUAVPbxmj71pRA8raTqLrec5LyTs5TqCxdABcZr77bt2KyWA5bizJHnC4g4ysm4h/*"); | ||||||
|         let master_dpk: &DescriptorPublicKey = &master_dsk.as_public(); |         let master_dpk: &DescriptorPublicKey = &master_dsk.as_public(); | ||||||
| @ -310,7 +305,7 @@ mod test { | |||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_derive_descriptors_keys() { |     fn test_derive_descriptors_keys() { | ||||||
|         let master_dsk = get_descriptor_secret_key(); |         let master_dsk = get_inner(); | ||||||
|         let derived_dsk: &DescriptorSecretKey = &derive_dsk(&master_dsk, "m/0").unwrap(); |         let derived_dsk: &DescriptorSecretKey = &derive_dsk(&master_dsk, "m/0").unwrap(); | ||||||
|         assert_eq!(derived_dsk.as_string(), "[d1d04177/0]tprv8d7Y4JLmD25jkKbyDZXcdoPHu1YtMHuH21qeN7mFpjfumtSU7eZimFYUCSa3MYzkEYfSNRBV34GEr2QXwZCMYRZ7M1g6PUtiLhbJhBZEGYJ/*"); |         assert_eq!(derived_dsk.as_string(), "[d1d04177/0]tprv8d7Y4JLmD25jkKbyDZXcdoPHu1YtMHuH21qeN7mFpjfumtSU7eZimFYUCSa3MYzkEYfSNRBV34GEr2QXwZCMYRZ7M1g6PUtiLhbJhBZEGYJ/*"); | ||||||
|         let master_dpk: &DescriptorPublicKey = &master_dsk.as_public(); |         let master_dpk: &DescriptorPublicKey = &master_dsk.as_public(); | ||||||
| @ -320,7 +315,7 @@ mod test { | |||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_extend_descriptor_keys() { |     fn test_extend_descriptor_keys() { | ||||||
|         let master_dsk = get_descriptor_secret_key(); |         let master_dsk = get_inner(); | ||||||
|         let extended_dsk: &DescriptorSecretKey = &extend_dsk(&master_dsk, "m/0").unwrap(); |         let extended_dsk: &DescriptorSecretKey = &extend_dsk(&master_dsk, "m/0").unwrap(); | ||||||
|         assert_eq!(extended_dsk.as_string(), "tprv8ZgxMBicQKsPdWuqM1t1CDRvQtQuBPyfL6GbhQwtxDKgUAVPbxmj71pRA8raTqLrec5LyTs5TqCxdABcZr77bt2KyWA5bizJHnC4g4ysm4h/0/*"); |         assert_eq!(extended_dsk.as_string(), "tprv8ZgxMBicQKsPdWuqM1t1CDRvQtQuBPyfL6GbhQwtxDKgUAVPbxmj71pRA8raTqLrec5LyTs5TqCxdABcZr77bt2KyWA5bizJHnC4g4ysm4h/0/*"); | ||||||
|         let master_dpk: &DescriptorPublicKey = &master_dsk.as_public(); |         let master_dpk: &DescriptorPublicKey = &master_dsk.as_public(); | ||||||
| @ -334,7 +329,7 @@ mod test { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_from_str_descriptor_secret_key() { |     fn test_from_str_inner() { | ||||||
|         let key1 = "L2wTu6hQrnDMiFNWA5na6jB12ErGQqtXwqpSL7aWquJaZG8Ai3ch"; |         let key1 = "L2wTu6hQrnDMiFNWA5na6jB12ErGQqtXwqpSL7aWquJaZG8Ai3ch"; | ||||||
|         let key2 = "tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/1/1/1/*"; |         let key2 = "tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/1/1/1/*"; | ||||||
|         let private_descriptor_key1 = DescriptorSecretKey::from_string(key1.to_string()).unwrap(); |         let private_descriptor_key1 = DescriptorSecretKey::from_string(key1.to_string()).unwrap(); | ||||||
| @ -347,8 +342,8 @@ mod test { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_derive_and_extend_descriptor_secret_key() { |     fn test_derive_and_extend_inner() { | ||||||
|         let master_dsk = get_descriptor_secret_key(); |         let master_dsk = get_inner(); | ||||||
|         // derive DescriptorSecretKey with path "m/0" from master
 |         // derive DescriptorSecretKey with path "m/0" from master
 | ||||||
|         let derived_dsk: &DescriptorSecretKey = &derive_dsk(&master_dsk, "m/0").unwrap(); |         let derived_dsk: &DescriptorSecretKey = &derive_dsk(&master_dsk, "m/0").unwrap(); | ||||||
|         assert_eq!(derived_dsk.as_string(), "[d1d04177/0]tprv8d7Y4JLmD25jkKbyDZXcdoPHu1YtMHuH21qeN7mFpjfumtSU7eZimFYUCSa3MYzkEYfSNRBV34GEr2QXwZCMYRZ7M1g6PUtiLhbJhBZEGYJ/*"); |         assert_eq!(derived_dsk.as_string(), "[d1d04177/0]tprv8d7Y4JLmD25jkKbyDZXcdoPHu1YtMHuH21qeN7mFpjfumtSU7eZimFYUCSa3MYzkEYfSNRBV34GEr2QXwZCMYRZ7M1g6PUtiLhbJhBZEGYJ/*"); | ||||||
| @ -359,14 +354,14 @@ mod test { | |||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_derive_hardened_path_using_public() { |     fn test_derive_hardened_path_using_public() { | ||||||
|         let master_dpk = get_descriptor_secret_key().as_public(); |         let master_dpk = get_inner().as_public(); | ||||||
|         let derived_dpk = &derive_dpk(&master_dpk, "m/84h/1h/0h"); |         let derived_dpk = &derive_dpk(&master_dpk, "m/84h/1h/0h"); | ||||||
|         assert!(derived_dpk.is_err()); |         assert!(derived_dpk.is_err()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_retrieve_master_secret_key() { |     fn test_retrieve_master_secret_key() { | ||||||
|         let master_dpk = get_descriptor_secret_key(); |         let master_dpk = get_inner(); | ||||||
|         let master_private_key = master_dpk.secret_bytes().to_hex(); |         let master_private_key = master_dpk.secret_bytes().to_hex(); | ||||||
|         assert_eq!( |         assert_eq!( | ||||||
|             master_private_key, |             master_private_key, | ||||||
|  | |||||||
| @ -203,7 +203,7 @@ impl From<&BdkTxOut> for TxOut { | |||||||
|         TxOut { |         TxOut { | ||||||
|             value: tx_out.value, |             value: tx_out.value, | ||||||
|             script_pubkey: Arc::new(Script { |             script_pubkey: Arc::new(Script { | ||||||
|                 script: tx_out.script_pubkey.clone(), |                 inner: tx_out.script_pubkey.clone(), | ||||||
|             }), |             }), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -226,7 +226,7 @@ impl From<BdkLocalUtxo> for LocalUtxo { | |||||||
|             txout: TxOut { |             txout: TxOut { | ||||||
|                 value: local_utxo.txout.value, |                 value: local_utxo.txout.value, | ||||||
|                 script_pubkey: Arc::new(Script { |                 script_pubkey: Arc::new(Script { | ||||||
|                     script: local_utxo.txout.script_pubkey, |                     inner: local_utxo.txout.script_pubkey, | ||||||
|                 }), |                 }), | ||||||
|             }, |             }, | ||||||
|             keychain: local_utxo.keychain, |             keychain: local_utxo.keychain, | ||||||
| @ -275,7 +275,7 @@ impl From<&BdkTxIn> for TxIn { | |||||||
|                 vout: tx_in.previous_output.vout, |                 vout: tx_in.previous_output.vout, | ||||||
|             }, |             }, | ||||||
|             script_sig: Arc::new(Script { |             script_sig: Arc::new(Script { | ||||||
|                 script: tx_in.script_sig.clone(), |                 inner: tx_in.script_sig.clone(), | ||||||
|             }), |             }), | ||||||
|             sequence: tx_in.sequence.0, |             sequence: tx_in.sequence.0, | ||||||
|             witness: tx_in.witness.to_vec(), |             witness: tx_in.witness.to_vec(), | ||||||
| @ -286,93 +286,93 @@ impl From<&BdkTxIn> for TxIn { | |||||||
| /// A Bitcoin transaction.
 | /// A Bitcoin transaction.
 | ||||||
| #[derive(Debug, Clone, PartialEq, Eq)] | #[derive(Debug, Clone, PartialEq, Eq)] | ||||||
| pub struct Transaction { | pub struct Transaction { | ||||||
|     internal: BdkTransaction, |     inner: BdkTransaction, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Transaction { | impl Transaction { | ||||||
|     fn new(transaction_bytes: Vec<u8>) -> Result<Self, BdkError> { |     fn new(transaction_bytes: Vec<u8>) -> Result<Self, BdkError> { | ||||||
|         let mut decoder = Cursor::new(transaction_bytes); |         let mut decoder = Cursor::new(transaction_bytes); | ||||||
|         let tx: BdkTransaction = BdkTransaction::consensus_decode(&mut decoder)?; |         let tx: BdkTransaction = BdkTransaction::consensus_decode(&mut decoder)?; | ||||||
|         Ok(Transaction { internal: tx }) |         Ok(Transaction { inner: tx }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn txid(&self) -> String { |     fn txid(&self) -> String { | ||||||
|         self.internal.txid().to_string() |         self.inner.txid().to_string() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn weight(&self) -> u64 { |     fn weight(&self) -> u64 { | ||||||
|         self.internal.weight() as u64 |         self.inner.weight() as u64 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn size(&self) -> u64 { |     fn size(&self) -> u64 { | ||||||
|         self.internal.size() as u64 |         self.inner.size() as u64 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn vsize(&self) -> u64 { |     fn vsize(&self) -> u64 { | ||||||
|         self.internal.vsize() as u64 |         self.inner.vsize() as u64 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn serialize(&self) -> Vec<u8> { |     fn serialize(&self) -> Vec<u8> { | ||||||
|         self.internal.serialize() |         self.inner.serialize() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn is_coin_base(&self) -> bool { |     fn is_coin_base(&self) -> bool { | ||||||
|         self.internal.is_coin_base() |         self.inner.is_coin_base() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn is_explicitly_rbf(&self) -> bool { |     fn is_explicitly_rbf(&self) -> bool { | ||||||
|         self.internal.is_explicitly_rbf() |         self.inner.is_explicitly_rbf() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn is_lock_time_enabled(&self) -> bool { |     fn is_lock_time_enabled(&self) -> bool { | ||||||
|         self.internal.is_lock_time_enabled() |         self.inner.is_lock_time_enabled() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn version(&self) -> i32 { |     fn version(&self) -> i32 { | ||||||
|         self.internal.version |         self.inner.version | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn lock_time(&self) -> u32 { |     fn lock_time(&self) -> u32 { | ||||||
|         self.internal.lock_time.0 |         self.inner.lock_time.0 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn input(&self) -> Vec<TxIn> { |     fn input(&self) -> Vec<TxIn> { | ||||||
|         self.internal.input.iter().map(|x| x.into()).collect() |         self.inner.input.iter().map(|x| x.into()).collect() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn output(&self) -> Vec<TxOut> { |     fn output(&self) -> Vec<TxOut> { | ||||||
|         self.internal.output.iter().map(|x| x.into()).collect() |         self.inner.output.iter().map(|x| x.into()).collect() | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl From<BdkTransaction> for Transaction { | impl From<BdkTransaction> for Transaction { | ||||||
|     fn from(tx: BdkTransaction) -> Self { |     fn from(tx: BdkTransaction) -> Self { | ||||||
|         Transaction { internal: tx } |         Transaction { inner: tx } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// A Bitcoin address.
 | /// A Bitcoin address.
 | ||||||
| #[derive(Debug, PartialEq, Eq)] | #[derive(Debug, PartialEq, Eq)] | ||||||
| pub struct Address { | pub struct Address { | ||||||
|     address: BdkAddress, |     inner: BdkAddress, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Address { | impl Address { | ||||||
|     fn new(address: String) -> Result<Self, BdkError> { |     fn new(address: String) -> Result<Self, BdkError> { | ||||||
|         BdkAddress::from_str(address.as_str()) |         BdkAddress::from_str(address.as_str()) | ||||||
|             .map(|a| Address { address: a }) |             .map(|a| Address { inner: a }) | ||||||
|             .map_err(|e| BdkError::Generic(e.to_string())) |             .map_err(|e| BdkError::Generic(e.to_string())) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// alternative constructor
 |     /// alternative constructor
 | ||||||
|     fn from_script(script: Arc<Script>, network: Network) -> Result<Self, BdkError> { |     fn from_script(script: Arc<Script>, network: Network) -> Result<Self, BdkError> { | ||||||
|         BdkAddress::from_script(&script.script, network) |         BdkAddress::from_script(&script.inner, network) | ||||||
|             .map(|a| Address { address: a }) |             .map(|a| Address { inner: a }) | ||||||
|             .map_err(|e| BdkError::Generic(e.to_string())) |             .map_err(|e| BdkError::Generic(e.to_string())) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn payload(&self) -> Payload { |     fn payload(&self) -> Payload { | ||||||
|         match &self.address.payload.clone() { |         match &self.inner.payload.clone() { | ||||||
|             BdkPayload::PubkeyHash(pubkey_hash) => Payload::PubkeyHash { |             BdkPayload::PubkeyHash(pubkey_hash) => Payload::PubkeyHash { | ||||||
|                 pubkey_hash: pubkey_hash.to_vec(), |                 pubkey_hash: pubkey_hash.to_vec(), | ||||||
|             }, |             }, | ||||||
| @ -387,27 +387,27 @@ impl Address { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn network(&self) -> Network { |     fn network(&self) -> Network { | ||||||
|         self.address.network |         self.inner.network | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn script_pubkey(&self) -> Arc<Script> { |     fn script_pubkey(&self) -> Arc<Script> { | ||||||
|         Arc::new(Script { |         Arc::new(Script { | ||||||
|             script: self.address.script_pubkey(), |             inner: self.inner.script_pubkey(), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn to_qr_uri(&self) -> String { |     fn to_qr_uri(&self) -> String { | ||||||
|         self.address.to_qr_uri() |         self.inner.to_qr_uri() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn as_string(&self) -> String { |     fn as_string(&self) -> String { | ||||||
|         self.address.to_string() |         self.inner.to_string() | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl From<BdkAddress> for Address { | impl From<BdkAddress> for Address { | ||||||
|     fn from(address: BdkAddress) -> Self { |     fn from(address: BdkAddress) -> Self { | ||||||
|         Address { address } |         Address { inner: address } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -430,23 +430,23 @@ pub enum Payload { | |||||||
| /// A Bitcoin script.
 | /// A Bitcoin script.
 | ||||||
| #[derive(Clone, Debug, PartialEq, Eq)] | #[derive(Clone, Debug, PartialEq, Eq)] | ||||||
| pub struct Script { | pub struct Script { | ||||||
|     script: BdkScript, |     inner: BdkScript, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Script { | impl Script { | ||||||
|     fn new(raw_output_script: Vec<u8>) -> Self { |     fn new(raw_output_script: Vec<u8>) -> Self { | ||||||
|         let script: BdkScript = BdkScript::from(raw_output_script); |         let script: BdkScript = BdkScript::from(raw_output_script); | ||||||
|         Script { script } |         Script { inner: script } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn to_bytes(&self) -> Vec<u8> { |     fn to_bytes(&self) -> Vec<u8> { | ||||||
|         self.script.to_bytes() |         self.inner.to_bytes() | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl From<BdkScript> for Script { | impl From<BdkScript> for Script { | ||||||
|     fn from(bdk_script: BdkScript) -> Self { |     fn from(bdk_script: BdkScript) -> Self { | ||||||
|         Script { script: bdk_script } |         Script { inner: bdk_script } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -10,7 +10,7 @@ use crate::{BdkError, FeeRate, Transaction}; | |||||||
| 
 | 
 | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| pub(crate) struct PartiallySignedTransaction { | pub(crate) struct PartiallySignedTransaction { | ||||||
|     pub(crate) internal: Mutex<BdkPartiallySignedTransaction>, |     pub(crate) inner: Mutex<BdkPartiallySignedTransaction>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl PartiallySignedTransaction { | impl PartiallySignedTransaction { | ||||||
| @ -18,24 +18,24 @@ impl PartiallySignedTransaction { | |||||||
|         let psbt: BdkPartiallySignedTransaction = |         let psbt: BdkPartiallySignedTransaction = | ||||||
|             BdkPartiallySignedTransaction::from_str(&psbt_base64)?; |             BdkPartiallySignedTransaction::from_str(&psbt_base64)?; | ||||||
|         Ok(PartiallySignedTransaction { |         Ok(PartiallySignedTransaction { | ||||||
|             internal: Mutex::new(psbt), |             inner: Mutex::new(psbt), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn serialize(&self) -> String { |     pub(crate) fn serialize(&self) -> String { | ||||||
|         let psbt = self.internal.lock().unwrap().clone(); |         let psbt = self.inner.lock().unwrap().clone(); | ||||||
|         psbt.to_string() |         psbt.to_string() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn txid(&self) -> String { |     pub(crate) fn txid(&self) -> String { | ||||||
|         let tx = self.internal.lock().unwrap().clone().extract_tx(); |         let tx = self.inner.lock().unwrap().clone().extract_tx(); | ||||||
|         let txid = tx.txid(); |         let txid = tx.txid(); | ||||||
|         txid.to_hex() |         txid.to_hex() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Return the transaction.
 |     /// Return the transaction.
 | ||||||
|     pub(crate) fn extract_tx(&self) -> Arc<Transaction> { |     pub(crate) fn extract_tx(&self) -> Arc<Transaction> { | ||||||
|         let tx = self.internal.lock().unwrap().clone().extract_tx(); |         let tx = self.inner.lock().unwrap().clone().extract_tx(); | ||||||
|         Arc::new(tx.into()) |         Arc::new(tx.into()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -46,19 +46,19 @@ impl PartiallySignedTransaction { | |||||||
|         &self, |         &self, | ||||||
|         other: Arc<PartiallySignedTransaction>, |         other: Arc<PartiallySignedTransaction>, | ||||||
|     ) -> Result<Arc<PartiallySignedTransaction>, BdkError> { |     ) -> Result<Arc<PartiallySignedTransaction>, BdkError> { | ||||||
|         let other_psbt = other.internal.lock().unwrap().clone(); |         let other_psbt = other.inner.lock().unwrap().clone(); | ||||||
|         let mut original_psbt = self.internal.lock().unwrap().clone(); |         let mut original_psbt = self.inner.lock().unwrap().clone(); | ||||||
| 
 | 
 | ||||||
|         original_psbt.combine(other_psbt)?; |         original_psbt.combine(other_psbt)?; | ||||||
|         Ok(Arc::new(PartiallySignedTransaction { |         Ok(Arc::new(PartiallySignedTransaction { | ||||||
|             internal: Mutex::new(original_psbt), |             inner: Mutex::new(original_psbt), | ||||||
|         })) |         })) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// The total transaction fee amount, sum of input amounts minus sum of output amounts, in Sats.
 |     /// The total transaction fee amount, sum of input amounts minus sum of output amounts, in Sats.
 | ||||||
|     /// If the PSBT is missing a TxOut for an input returns None.
 |     /// If the PSBT is missing a TxOut for an input returns None.
 | ||||||
|     pub(crate) fn fee_amount(&self) -> Option<u64> { |     pub(crate) fn fee_amount(&self) -> Option<u64> { | ||||||
|         self.internal.lock().unwrap().fee_amount() |         self.inner.lock().unwrap().fee_amount() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// The transaction's fee rate. This value will only be accurate if calculated AFTER the
 |     /// The transaction's fee rate. This value will only be accurate if calculated AFTER the
 | ||||||
| @ -66,12 +66,12 @@ impl PartiallySignedTransaction { | |||||||
|     /// transaction.
 |     /// transaction.
 | ||||||
|     /// If the PSBT is missing a TxOut for an input returns None.
 |     /// If the PSBT is missing a TxOut for an input returns None.
 | ||||||
|     pub(crate) fn fee_rate(&self) -> Option<Arc<FeeRate>> { |     pub(crate) fn fee_rate(&self) -> Option<Arc<FeeRate>> { | ||||||
|         self.internal.lock().unwrap().fee_rate().map(Arc::new) |         self.inner.lock().unwrap().fee_rate().map(Arc::new) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Serialize the PSBT data structure as a String of JSON.
 |     /// Serialize the PSBT data structure as a String of JSON.
 | ||||||
|     pub(crate) fn json_serialize(&self) -> String { |     pub(crate) fn json_serialize(&self) -> String { | ||||||
|         let psbt = self.internal.lock().unwrap(); |         let psbt = self.inner.lock().unwrap(); | ||||||
|         serde_json::to_string(psbt.deref()).unwrap() |         serde_json::to_string(psbt.deref()).unwrap() | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -90,7 +90,7 @@ mod test { | |||||||
|         let test_wpkh = "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)"; |         let test_wpkh = "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)"; | ||||||
|         let (funded_wallet, _, _) = get_funded_wallet(test_wpkh); |         let (funded_wallet, _, _) = get_funded_wallet(test_wpkh); | ||||||
|         let test_wallet = Wallet { |         let test_wallet = Wallet { | ||||||
|             wallet_mutex: Mutex::new(funded_wallet), |             inner_mutex: Mutex::new(funded_wallet), | ||||||
|         }; |         }; | ||||||
|         let drain_to_address = "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt".to_string(); |         let drain_to_address = "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt".to_string(); | ||||||
|         let drain_to_script = crate::Address::new(drain_to_address) |         let drain_to_script = crate::Address::new(drain_to_address) | ||||||
| @ -103,7 +103,7 @@ mod test { | |||||||
|             .drain_to(drain_to_script.clone()); |             .drain_to(drain_to_script.clone()); | ||||||
|         //dbg!(&tx_builder);
 |         //dbg!(&tx_builder);
 | ||||||
|         assert!(tx_builder.drain_wallet); |         assert!(tx_builder.drain_wallet); | ||||||
|         assert_eq!(tx_builder.drain_to, Some(drain_to_script.script.clone())); |         assert_eq!(tx_builder.drain_to, Some(drain_to_script.inner.clone())); | ||||||
| 
 | 
 | ||||||
|         let tx_builder_result = tx_builder.finish(&test_wallet).unwrap(); |         let tx_builder_result = tx_builder.finish(&test_wallet).unwrap(); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ use crate::{ | |||||||
| 
 | 
 | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| pub(crate) struct Wallet { | pub(crate) struct Wallet { | ||||||
|     pub(crate) wallet_mutex: Mutex<BdkWallet<AnyDatabase>>, |     pub(crate) inner_mutex: Mutex<BdkWallet<AnyDatabase>>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// A Bitcoin wallet.
 | /// A Bitcoin wallet.
 | ||||||
| @ -53,11 +53,13 @@ impl Wallet { | |||||||
|             network, |             network, | ||||||
|             database, |             database, | ||||||
|         )?); |         )?); | ||||||
|         Ok(Wallet { wallet_mutex }) |         Ok(Wallet { | ||||||
|  |             inner_mutex: wallet_mutex, | ||||||
|  |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub(crate) fn get_wallet(&self) -> MutexGuard<BdkWallet<AnyDatabase>> { |     pub(crate) fn get_wallet(&self) -> MutexGuard<BdkWallet<AnyDatabase>> { | ||||||
|         self.wallet_mutex.lock().expect("wallet") |         self.inner_mutex.lock().expect("wallet") | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Get the Bitcoin network the wallet is using.
 |     /// Get the Bitcoin network the wallet is using.
 | ||||||
| @ -67,7 +69,7 @@ impl Wallet { | |||||||
| 
 | 
 | ||||||
|     /// Return whether or not a script is part of this wallet (either internal or external).
 |     /// Return whether or not a script is part of this wallet (either internal or external).
 | ||||||
|     pub(crate) fn is_mine(&self, script: Arc<Script>) -> Result<bool, BdkError> { |     pub(crate) fn is_mine(&self, script: Arc<Script>) -> Result<bool, BdkError> { | ||||||
|         self.get_wallet().is_mine(&script.script) |         self.get_wallet().is_mine(&script.inner) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Sync the internal database with the blockchain.
 |     /// Sync the internal database with the blockchain.
 | ||||||
| @ -131,7 +133,7 @@ impl Wallet { | |||||||
|         psbt: &PartiallySignedTransaction, |         psbt: &PartiallySignedTransaction, | ||||||
|         sign_options: Option<SignOptions>, |         sign_options: Option<SignOptions>, | ||||||
|     ) -> Result<bool, BdkError> { |     ) -> Result<bool, BdkError> { | ||||||
|         let mut psbt = psbt.internal.lock().unwrap(); |         let mut psbt = psbt.inner.lock().unwrap(); | ||||||
|         self.get_wallet().sign( |         self.get_wallet().sign( | ||||||
|             &mut psbt, |             &mut psbt, | ||||||
|             sign_options.map(SignOptions::into).unwrap_or_default(), |             sign_options.map(SignOptions::into).unwrap_or_default(), | ||||||
| @ -271,7 +273,7 @@ impl TxBuilder { | |||||||
|     /// Add a recipient to the internal list.
 |     /// Add a recipient to the internal list.
 | ||||||
|     pub(crate) fn add_recipient(&self, script: Arc<Script>, amount: u64) -> Arc<Self> { |     pub(crate) fn add_recipient(&self, script: Arc<Script>, amount: u64) -> Arc<Self> { | ||||||
|         let mut recipients: Vec<(BdkScript, u64)> = self.recipients.clone(); |         let mut recipients: Vec<(BdkScript, u64)> = self.recipients.clone(); | ||||||
|         recipients.append(&mut vec![(script.script.clone(), amount)]); |         recipients.append(&mut vec![(script.inner.clone(), amount)]); | ||||||
|         Arc::new(TxBuilder { |         Arc::new(TxBuilder { | ||||||
|             recipients, |             recipients, | ||||||
|             ..self.clone() |             ..self.clone() | ||||||
| @ -281,7 +283,7 @@ impl TxBuilder { | |||||||
|     pub(crate) fn set_recipients(&self, recipients: Vec<ScriptAmount>) -> Arc<Self> { |     pub(crate) fn set_recipients(&self, recipients: Vec<ScriptAmount>) -> Arc<Self> { | ||||||
|         let recipients = recipients |         let recipients = recipients | ||||||
|             .iter() |             .iter() | ||||||
|             .map(|script_amount| (script_amount.script.script.clone(), script_amount.amount)) |             .map(|script_amount| (script_amount.script.inner.clone(), script_amount.amount)) | ||||||
|             .collect(); |             .collect(); | ||||||
|         Arc::new(TxBuilder { |         Arc::new(TxBuilder { | ||||||
|             recipients, |             recipients, | ||||||
| @ -386,7 +388,7 @@ impl TxBuilder { | |||||||
|     /// to allow this output to be reduced to pay for the extra fees.
 |     /// to allow this output to be reduced to pay for the extra fees.
 | ||||||
|     pub(crate) fn drain_to(&self, script: Arc<Script>) -> Arc<Self> { |     pub(crate) fn drain_to(&self, script: Arc<Script>) -> Arc<Self> { | ||||||
|         Arc::new(TxBuilder { |         Arc::new(TxBuilder { | ||||||
|             drain_to: Some(script.script.clone()), |             drain_to: Some(script.inner.clone()), | ||||||
|             ..self.clone() |             ..self.clone() | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| @ -468,7 +470,7 @@ impl TxBuilder { | |||||||
|             .finish() |             .finish() | ||||||
|             .map(|(psbt, tx_details)| TxBuilderResult { |             .map(|(psbt, tx_details)| TxBuilderResult { | ||||||
|                 psbt: Arc::new(PartiallySignedTransaction { |                 psbt: Arc::new(PartiallySignedTransaction { | ||||||
|                     internal: Mutex::new(psbt), |                     inner: Mutex::new(psbt), | ||||||
|                 }), |                 }), | ||||||
|                 transaction_details: TransactionDetails::from(tx_details), |                 transaction_details: TransactionDetails::from(tx_details), | ||||||
|             }) |             }) | ||||||
| @ -552,7 +554,7 @@ impl BumpFeeTxBuilder { | |||||||
|         tx_builder |         tx_builder | ||||||
|             .finish() |             .finish() | ||||||
|             .map(|(psbt, _)| PartiallySignedTransaction { |             .map(|(psbt, _)| PartiallySignedTransaction { | ||||||
|                 internal: Mutex::new(psbt), |                 inner: Mutex::new(psbt), | ||||||
|             }) |             }) | ||||||
|             .map(Arc::new) |             .map(Arc::new) | ||||||
|     } |     } | ||||||
| @ -580,7 +582,7 @@ mod test { | |||||||
|         let test_wpkh = "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)"; |         let test_wpkh = "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)"; | ||||||
|         let (funded_wallet, _, _) = get_funded_wallet(test_wpkh); |         let (funded_wallet, _, _) = get_funded_wallet(test_wpkh); | ||||||
|         let test_wallet = Wallet { |         let test_wallet = Wallet { | ||||||
|             wallet_mutex: Mutex::new(funded_wallet), |             inner_mutex: Mutex::new(funded_wallet), | ||||||
|         }; |         }; | ||||||
|         let drain_to_address = "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt".to_string(); |         let drain_to_address = "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt".to_string(); | ||||||
|         let drain_to_script = crate::Address::new(drain_to_address) |         let drain_to_script = crate::Address::new(drain_to_address) | ||||||
| @ -590,10 +592,10 @@ mod test { | |||||||
|             .drain_wallet() |             .drain_wallet() | ||||||
|             .drain_to(drain_to_script.clone()); |             .drain_to(drain_to_script.clone()); | ||||||
|         assert!(tx_builder.drain_wallet); |         assert!(tx_builder.drain_wallet); | ||||||
|         assert_eq!(tx_builder.drain_to, Some(drain_to_script.script.clone())); |         assert_eq!(tx_builder.drain_to, Some(drain_to_script.inner.clone())); | ||||||
| 
 | 
 | ||||||
|         let tx_builder_result = tx_builder.finish(&test_wallet).unwrap(); |         let tx_builder_result = tx_builder.finish(&test_wallet).unwrap(); | ||||||
|         let psbt = tx_builder_result.psbt.internal.lock().unwrap().clone(); |         let psbt = tx_builder_result.psbt.inner.lock().unwrap().clone(); | ||||||
|         let tx_details = tx_builder_result.transaction_details; |         let tx_details = tx_builder_result.transaction_details; | ||||||
| 
 | 
 | ||||||
|         // confirm one input with 50,000 sats
 |         // confirm one input with 50,000 sats
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user