diff --git a/src/bdk.udl b/src/bdk.udl index 1ccedc8..4d0cef5 100644 --- a/src/bdk.udl +++ b/src/bdk.udl @@ -1,10 +1,10 @@ namespace bdk { - [Throws=Error] + [Throws=BdkError] string generate_mnemonic(WordCount word_count); }; [Error] -enum Error { +enum BdkError { "InvalidU32Bytes", "Generic", "MissingCachedScripts", @@ -134,16 +134,16 @@ interface BlockchainConfig { }; interface Blockchain { - [Throws=Error] + [Throws=BdkError] constructor(BlockchainConfig config); - [Throws=Error] + [Throws=BdkError] void broadcast([ByRef] PartiallySignedBitcoinTransaction psbt); - [Throws=Error] + [Throws=BdkError] u32 get_height(); - [Throws=Error] + [Throws=BdkError] string get_block_hash(u32 height); }; @@ -179,32 +179,32 @@ dictionary ScriptAmount { }; interface Wallet { - [Throws=Error] + [Throws=BdkError] constructor(string descriptor, string? change_descriptor, Network network, DatabaseConfig database_config); - [Throws=Error] + [Throws=BdkError] AddressInfo get_address(AddressIndex address_index); - [Throws=Error] + [Throws=BdkError] Balance get_balance(); - [Throws=Error] + [Throws=BdkError] boolean sign([ByRef] PartiallySignedBitcoinTransaction psbt); - [Throws=Error] + [Throws=BdkError] sequence list_transactions(); Network network(); - [Throws=Error] + [Throws=BdkError] void sync([ByRef] Blockchain blockchain, Progress? progress); - [Throws=Error] + [Throws=BdkError] sequence list_unspent(); }; interface PartiallySignedBitcoinTransaction { - [Throws=Error] + [Throws=BdkError] constructor(string psbt_base64); string serialize(); @@ -213,7 +213,7 @@ interface PartiallySignedBitcoinTransaction { sequence extract_tx(); - [Throws=Error] + [Throws=BdkError] PartiallySignedBitcoinTransaction combine(PartiallySignedBitcoinTransaction other); }; @@ -257,7 +257,7 @@ interface TxBuilder { TxBuilder set_recipients(sequence recipients); - [Throws=Error] + [Throws=BdkError] TxBuilderResult finish([ByRef] Wallet wallet); }; @@ -270,20 +270,20 @@ interface BumpFeeTxBuilder { BumpFeeTxBuilder enable_rbf_with_sequence(u32 nsequence); - [Throws=Error] + [Throws=BdkError] PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet); }; interface DerivationPath { - [Throws=Error] + [Throws=BdkError] constructor(string path); }; interface DescriptorSecretKey { - [Throws=Error] + [Throws=BdkError] constructor(Network network, string mnemonic, string? password); - [Throws=Error] + [Throws=BdkError] DescriptorSecretKey derive(DerivationPath path); DescriptorSecretKey extend(DerivationPath path); @@ -296,7 +296,7 @@ interface DescriptorSecretKey { }; interface DescriptorPublicKey { - [Throws=Error] + [Throws=BdkError] DescriptorPublicKey derive(DerivationPath path); DescriptorPublicKey extend(DerivationPath path); @@ -305,7 +305,7 @@ interface DescriptorPublicKey { }; interface Address { - [Throws=Error] + [Throws=BdkError] constructor(string address); Script script_pubkey(); diff --git a/src/lib.rs b/src/lib.rs index 7590848..43acafa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ use bdk::wallet::tx_builder::ChangeSpendPolicy; use bdk::wallet::AddressIndex as BdkAddressIndex; use bdk::wallet::AddressInfo as BdkAddressInfo; use bdk::{ - Balance as BdkBalance, BlockTime, Error, FeeRate, KeychainKind, SignOptions, + Balance as BdkBalance, BlockTime, Error as BdkError, FeeRate, KeychainKind, SignOptions, SyncOptions as BdkSyncOptions, Wallet as BdkWallet, }; use std::collections::HashSet; @@ -178,7 +178,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 { @@ -209,16 +209,16 @@ impl Blockchain { self.blockchain_mutex.lock().expect("blockchain") } - fn broadcast(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result<(), Error> { + fn broadcast(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result<(), BdkError> { let tx = psbt.internal.lock().unwrap().clone().extract_tx(); self.get_blockchain().broadcast(&tx) } - fn get_height(&self) -> Result { + fn get_height(&self) -> Result { self.get_blockchain().get_height() } - fn get_block_hash(&self, height: u32) -> Result { + fn get_block_hash(&self, height: u32) -> Result { self.get_blockchain() .get_block_hash(u64::from(height)) .map(|hash| hash.to_string()) @@ -327,7 +327,7 @@ struct ProgressHolder { } impl BdkProgress for ProgressHolder { - fn update(&self, progress: f32, message: Option) -> Result<(), Error> { + fn update(&self, progress: f32, message: Option) -> Result<(), BdkError> { self.progress.update(progress, message); Ok(()) } @@ -345,7 +345,7 @@ pub struct PartiallySignedBitcoinTransaction { } impl PartiallySignedBitcoinTransaction { - fn new(psbt_base64: String) -> Result { + fn new(psbt_base64: String) -> Result { let psbt: PartiallySignedTransaction = PartiallySignedTransaction::from_str(&psbt_base64)?; Ok(PartiallySignedBitcoinTransaction { internal: Mutex::new(psbt), @@ -379,7 +379,7 @@ impl PartiallySignedBitcoinTransaction { fn combine( &self, other: Arc, - ) -> Result, Error> { + ) -> Result, BdkError> { let other_psbt = other.internal.lock().unwrap().clone(); let mut original_psbt = self.internal.lock().unwrap().clone(); @@ -401,7 +401,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), @@ -431,7 +431,7 @@ impl Wallet { &self, blockchain: &Blockchain, progress: Option>, - ) -> Result<(), Error> { + ) -> Result<(), BdkError> { let bdk_sync_opts = BdkSyncOptions { progress: progress.map(|p| { Box::new(ProgressHolder { progress: p }) @@ -446,7 +446,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) @@ -454,18 +454,18 @@ impl Wallet { /// Return the balance, meaning the sum of this wallet’s unspent outputs’ values. Note that this method only operates /// on the internal database, which first needs to be Wallet.sync manually. - fn get_balance(&self) -> Result { + fn get_balance(&self) -> Result { self.get_wallet().get_balance().map(|b| b.into()) } /// Sign a transaction with all the wallet’s signers. - fn sign(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result { + fn sign(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result { let mut psbt = psbt.internal.lock().unwrap(); self.get_wallet().sign(&mut psbt, SignOptions::default()) } /// Return the list of transactions made and received by the wallet. Note that this method only operate on the internal database, which first needs to be [Wallet.sync] manually. - fn list_transactions(&self) -> Result, Error> { + fn list_transactions(&self) -> Result, BdkError> { let transaction_details = self.get_wallet().list_transactions(true)?; Ok(transaction_details .iter() @@ -475,7 +475,7 @@ impl Wallet { /// Return the list of unspent outputs of this wallet. Note that this method only operates on the internal database, /// which first needs to be Wallet.sync manually. - fn list_unspent(&self) -> Result, Error> { + fn list_unspent(&self) -> Result, BdkError> { let unspents = self.get_wallet().list_unspent()?; Ok(unspents .iter() @@ -484,10 +484,10 @@ impl Wallet { } } -fn to_script_pubkey(address: &str) -> Result { +fn to_script_pubkey(address: &str) -> Result { BdkAddress::from_str(address) .map(|x| x.script_pubkey()) - .map_err(|e| Error::Generic(e.to_string())) + .map_err(|e| BdkError::Generic(e.to_string())) } /// A Bitcoin address. @@ -496,10 +496,10 @@ struct Address { } impl Address { - fn new(address: String) -> Result { + fn new(address: String) -> Result { BdkAddress::from_str(address.as_str()) .map(|a| Address { address: a }) - .map_err(|e| Error::Generic(e.to_string())) + .map_err(|e| BdkError::Generic(e.to_string())) } fn script_pubkey(&self) -> Arc