diff --git a/src/bdk.udl b/src/bdk.udl index d623250..39f3d0a 100644 --- a/src/bdk.udl +++ b/src/bdk.udl @@ -1,10 +1,10 @@ namespace bdk { - [Throws=BdkError] + [Throws=Error] string generate_mnemonic(WordCount word_count); }; [Error] -enum BdkError { +enum Error { "InvalidU32Bytes", "Generic", "MissingCachedScripts", @@ -134,16 +134,16 @@ interface BlockchainConfig { }; interface Blockchain { - [Throws=BdkError] + [Throws=Error] constructor(BlockchainConfig config); - [Throws=BdkError] + [Throws=Error] void broadcast([ByRef] PartiallySignedBitcoinTransaction psbt); - [Throws=BdkError] + [Throws=Error] u32 get_height(); - [Throws=BdkError] + [Throws=Error] string get_block_hash(u32 height); }; @@ -179,39 +179,39 @@ dictionary AddressAmount { }; interface Wallet { - [Throws=BdkError] + [Throws=Error] constructor(string descriptor, string? change_descriptor, Network network, DatabaseConfig database_config); - [Throws=BdkError] + [Throws=Error] AddressInfo get_address(AddressIndex address_index); - [Throws=BdkError] + [Throws=Error] Balance get_balance(); - [Throws=BdkError] + [Throws=Error] boolean sign([ByRef] PartiallySignedBitcoinTransaction psbt); - [Throws=BdkError] + [Throws=Error] sequence list_transactions(); Network network(); - [Throws=BdkError] + [Throws=Error] void sync([ByRef] Blockchain blockchain, Progress? progress); - [Throws=BdkError] + [Throws=Error] sequence list_unspent(); }; interface PartiallySignedBitcoinTransaction { - [Throws=BdkError] + [Throws=Error] constructor(string psbt_base64); string serialize(); string txid(); - [Throws=BdkError] + [Throws=Error] PartiallySignedBitcoinTransaction combine(PartiallySignedBitcoinTransaction other); }; @@ -250,7 +250,7 @@ interface TxBuilder { TxBuilder set_recipients(sequence recipients); - [Throws=BdkError] + [Throws=Error] PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet); }; @@ -263,20 +263,20 @@ interface BumpFeeTxBuilder { BumpFeeTxBuilder enable_rbf_with_sequence(u32 nsequence); - [Throws=BdkError] + [Throws=Error] PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet); }; interface DerivationPath { - [Throws=BdkError] + [Throws=Error] constructor(string path); }; interface DescriptorSecretKey { - [Throws=BdkError] + [Throws=Error] constructor(Network network, string mnemonic, string? password); - [Throws=BdkError] + [Throws=Error] DescriptorSecretKey derive(DerivationPath path); DescriptorSecretKey extend(DerivationPath path); @@ -289,7 +289,7 @@ interface DescriptorSecretKey { }; interface DescriptorPublicKey { - [Throws=BdkError] + [Throws=Error] DescriptorPublicKey derive(DerivationPath path); DescriptorPublicKey extend(DerivationPath path); diff --git a/src/lib.rs b/src/lib.rs index 7f77ab7..586b2e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,8 +35,6 @@ use std::sync::{Arc, Mutex, MutexGuard}; uniffi_macros::include_scaffolding!("bdk"); -type BdkError = Error; - pub struct AddressAmount { pub address: String, pub amount: u64, @@ -177,7 +175,7 @@ struct Blockchain { } impl Blockchain { - fn new(blockchain_config: BlockchainConfig) -> Result { + fn new(blockchain_config: BlockchainConfig) -> Result { let any_blockchain_config = match blockchain_config { BlockchainConfig::Electrum { config } => { AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig { @@ -390,7 +388,7 @@ impl Wallet { change_descriptor: Option, network: Network, database_config: DatabaseConfig, - ) -> Result { + ) -> Result { let any_database_config = match database_config { DatabaseConfig::Memory => AnyDatabaseConfig::Memory(()), DatabaseConfig::Sled { config } => AnyDatabaseConfig::Sled(config), @@ -420,7 +418,7 @@ impl Wallet { &self, blockchain: &Blockchain, progress: Option>, - ) -> Result<(), BdkError> { + ) -> Result<(), Error> { let bdk_sync_opts = BdkSyncOptions { progress: progress.map(|p| { Box::new(ProgressHolder { progress: p }) @@ -435,7 +433,7 @@ impl Wallet { /// Return a derived address using the external descriptor, see AddressIndex for available address index selection /// strategies. If none of the keys in the descriptor are derivable (i.e. the descriptor does not end with a * character) /// then the same address will always be returned for any AddressIndex. - fn get_address(&self, address_index: AddressIndex) -> Result { + fn get_address(&self, address_index: AddressIndex) -> Result { self.get_wallet() .get_address(address_index.into()) .map(AddressInfo::from) @@ -473,10 +471,10 @@ impl Wallet { } } -fn to_script_pubkey(address: &str) -> Result { +fn to_script_pubkey(address: &str) -> Result { Address::from_str(address) .map(|x| x.script_pubkey()) - .map_err(|e| BdkError::Generic(e.to_string())) + .map_err(|e| Error::Generic(e.to_string())) } #[derive(Clone, Debug)] @@ -805,7 +803,7 @@ impl BumpFeeTxBuilder { } } -fn generate_mnemonic(word_count: WordCount) -> Result { +fn generate_mnemonic(word_count: WordCount) -> Result { let mnemonic: GeneratedKey<_, BareCtx> = Mnemonic::generate((word_count, Language::English)).unwrap(); Ok(mnemonic.to_string()) @@ -816,12 +814,12 @@ struct DerivationPath { } impl DerivationPath { - fn new(path: String) -> Result { + fn new(path: String) -> Result { BdkDerivationPath::from_str(&path) .map(|x| DerivationPath { derivation_path_mutex: Mutex::new(x), }) - .map_err(|e| BdkError::Generic(e.to_string())) + .map_err(|e| Error::Generic(e.to_string())) } } @@ -830,9 +828,9 @@ struct DescriptorSecretKey { } impl DescriptorSecretKey { - fn new(network: Network, mnemonic: String, password: Option) -> Result { + fn new(network: Network, mnemonic: String, password: Option) -> Result { let mnemonic = Mnemonic::parse_in(Language::English, mnemonic) - .map_err(|e| BdkError::Generic(e.to_string()))?; + .map_err(|e| Error::Generic(e.to_string()))?; let xkey: ExtendedKey = (mnemonic, password).into_extended_key()?; let descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey { origin: None, @@ -845,7 +843,7 @@ impl DescriptorSecretKey { }) } - fn derive(&self, path: Arc) -> Result, BdkError> { + fn derive(&self, path: Arc) -> Result, Error> { let secp = Secp256k1::new(); let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap(); let path = path.derivation_path_mutex.lock().unwrap().deref().clone(); @@ -932,7 +930,7 @@ struct DescriptorPublicKey { } impl DescriptorPublicKey { - fn derive(&self, path: Arc) -> Result, BdkError> { + fn derive(&self, path: Arc) -> Result, Error> { let secp = Secp256k1::new(); let descriptor_public_key = self.descriptor_public_key_mutex.lock().unwrap(); let path = path.derivation_path_mutex.lock().unwrap().deref().clone(); @@ -1064,7 +1062,7 @@ mod test { fn derive_dsk( key: &DescriptorSecretKey, path: &str, - ) -> Result, BdkError> { + ) -> Result, Error> { let path = Arc::new(DerivationPath::new(path.to_string()).unwrap()); key.derive(path) } @@ -1077,7 +1075,7 @@ mod test { fn derive_dpk( key: &DescriptorPublicKey, path: &str, - ) -> Result, BdkError> { + ) -> Result, Error> { let path = Arc::new(DerivationPath::new(path.to_string()).unwrap()); key.derive(path) }