Skip to content

Commit c7d0803

Browse files
Fix use of Error as name for error enum in UDL
1 parent 1a4b9b4 commit c7d0803

File tree

2 files changed

+54
-54
lines changed

2 files changed

+54
-54
lines changed

src/bdk.udl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace bdk {
2-
[Throws=Error]
2+
[Throws=BdkError]
33
string generate_mnemonic(WordCount word_count);
44
};
55

66
[Error]
7-
enum Error {
7+
enum BdkError {
88
"InvalidU32Bytes",
99
"Generic",
1010
"MissingCachedScripts",
@@ -134,16 +134,16 @@ interface BlockchainConfig {
134134
};
135135

136136
interface Blockchain {
137-
[Throws=Error]
137+
[Throws=BdkError]
138138
constructor(BlockchainConfig config);
139139

140-
[Throws=Error]
140+
[Throws=BdkError]
141141
void broadcast([ByRef] PartiallySignedBitcoinTransaction psbt);
142142

143-
[Throws=Error]
143+
[Throws=BdkError]
144144
u32 get_height();
145145

146-
[Throws=Error]
146+
[Throws=BdkError]
147147
string get_block_hash(u32 height);
148148
};
149149

@@ -179,32 +179,32 @@ dictionary ScriptAmount {
179179
};
180180

181181
interface Wallet {
182-
[Throws=Error]
182+
[Throws=BdkError]
183183
constructor(string descriptor, string? change_descriptor, Network network, DatabaseConfig database_config);
184184

185-
[Throws=Error]
185+
[Throws=BdkError]
186186
AddressInfo get_address(AddressIndex address_index);
187187

188-
[Throws=Error]
188+
[Throws=BdkError]
189189
Balance get_balance();
190190

191-
[Throws=Error]
191+
[Throws=BdkError]
192192
boolean sign([ByRef] PartiallySignedBitcoinTransaction psbt);
193193

194-
[Throws=Error]
194+
[Throws=BdkError]
195195
sequence<TransactionDetails> list_transactions();
196196

197197
Network network();
198198

199-
[Throws=Error]
199+
[Throws=BdkError]
200200
void sync([ByRef] Blockchain blockchain, Progress? progress);
201201

202-
[Throws=Error]
202+
[Throws=BdkError]
203203
sequence<LocalUtxo> list_unspent();
204204
};
205205

206206
interface PartiallySignedBitcoinTransaction {
207-
[Throws=Error]
207+
[Throws=BdkError]
208208
constructor(string psbt_base64);
209209

210210
string serialize();
@@ -213,7 +213,7 @@ interface PartiallySignedBitcoinTransaction {
213213

214214
sequence<u8> extract_tx();
215215

216-
[Throws=Error]
216+
[Throws=BdkError]
217217
PartiallySignedBitcoinTransaction combine(PartiallySignedBitcoinTransaction other);
218218
};
219219

@@ -257,7 +257,7 @@ interface TxBuilder {
257257

258258
TxBuilder set_recipients(sequence<ScriptAmount> recipients);
259259

260-
[Throws=Error]
260+
[Throws=BdkError]
261261
TxBuilderResult finish([ByRef] Wallet wallet);
262262
};
263263

@@ -270,20 +270,20 @@ interface BumpFeeTxBuilder {
270270

271271
BumpFeeTxBuilder enable_rbf_with_sequence(u32 nsequence);
272272

273-
[Throws=Error]
273+
[Throws=BdkError]
274274
PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet);
275275
};
276276

277277
interface DerivationPath {
278-
[Throws=Error]
278+
[Throws=BdkError]
279279
constructor(string path);
280280
};
281281

282282
interface DescriptorSecretKey {
283-
[Throws=Error]
283+
[Throws=BdkError]
284284
constructor(Network network, string mnemonic, string? password);
285285

286-
[Throws=Error]
286+
[Throws=BdkError]
287287
DescriptorSecretKey derive(DerivationPath path);
288288

289289
DescriptorSecretKey extend(DerivationPath path);
@@ -296,7 +296,7 @@ interface DescriptorSecretKey {
296296
};
297297

298298
interface DescriptorPublicKey {
299-
[Throws=Error]
299+
[Throws=BdkError]
300300
DescriptorPublicKey derive(DerivationPath path);
301301

302302
DescriptorPublicKey extend(DerivationPath path);
@@ -305,7 +305,7 @@ interface DescriptorPublicKey {
305305
};
306306

307307
interface Address {
308-
[Throws=Error]
308+
[Throws=BdkError]
309309
constructor(string address);
310310

311311
Script script_pubkey();

src/lib.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use bdk::wallet::tx_builder::ChangeSpendPolicy;
2525
use bdk::wallet::AddressIndex as BdkAddressIndex;
2626
use bdk::wallet::AddressInfo as BdkAddressInfo;
2727
use bdk::{
28-
Balance as BdkBalance, BlockTime, Error, FeeRate, KeychainKind, SignOptions,
28+
Balance as BdkBalance, BlockTime, Error as BdkError, FeeRate, KeychainKind, SignOptions,
2929
SyncOptions as BdkSyncOptions, Wallet as BdkWallet,
3030
};
3131
use std::collections::HashSet;
@@ -178,7 +178,7 @@ struct Blockchain {
178178
}
179179

180180
impl Blockchain {
181-
fn new(blockchain_config: BlockchainConfig) -> Result<Self, Error> {
181+
fn new(blockchain_config: BlockchainConfig) -> Result<Self, BdkError> {
182182
let any_blockchain_config = match blockchain_config {
183183
BlockchainConfig::Electrum { config } => {
184184
AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig {
@@ -209,16 +209,16 @@ impl Blockchain {
209209
self.blockchain_mutex.lock().expect("blockchain")
210210
}
211211

212-
fn broadcast(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result<(), Error> {
212+
fn broadcast(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result<(), BdkError> {
213213
let tx = psbt.internal.lock().unwrap().clone().extract_tx();
214214
self.get_blockchain().broadcast(&tx)
215215
}
216216

217-
fn get_height(&self) -> Result<u32, Error> {
217+
fn get_height(&self) -> Result<u32, BdkError> {
218218
self.get_blockchain().get_height()
219219
}
220220

221-
fn get_block_hash(&self, height: u32) -> Result<String, Error> {
221+
fn get_block_hash(&self, height: u32) -> Result<String, BdkError> {
222222
self.get_blockchain()
223223
.get_block_hash(u64::from(height))
224224
.map(|hash| hash.to_string())
@@ -327,7 +327,7 @@ struct ProgressHolder {
327327
}
328328

329329
impl BdkProgress for ProgressHolder {
330-
fn update(&self, progress: f32, message: Option<String>) -> Result<(), Error> {
330+
fn update(&self, progress: f32, message: Option<String>) -> Result<(), BdkError> {
331331
self.progress.update(progress, message);
332332
Ok(())
333333
}
@@ -345,7 +345,7 @@ pub struct PartiallySignedBitcoinTransaction {
345345
}
346346

347347
impl PartiallySignedBitcoinTransaction {
348-
fn new(psbt_base64: String) -> Result<Self, Error> {
348+
fn new(psbt_base64: String) -> Result<Self, BdkError> {
349349
let psbt: PartiallySignedTransaction = PartiallySignedTransaction::from_str(&psbt_base64)?;
350350
Ok(PartiallySignedBitcoinTransaction {
351351
internal: Mutex::new(psbt),
@@ -379,7 +379,7 @@ impl PartiallySignedBitcoinTransaction {
379379
fn combine(
380380
&self,
381381
other: Arc<PartiallySignedBitcoinTransaction>,
382-
) -> Result<Arc<PartiallySignedBitcoinTransaction>, Error> {
382+
) -> Result<Arc<PartiallySignedBitcoinTransaction>, BdkError> {
383383
let other_psbt = other.internal.lock().unwrap().clone();
384384
let mut original_psbt = self.internal.lock().unwrap().clone();
385385

@@ -401,7 +401,7 @@ impl Wallet {
401401
change_descriptor: Option<String>,
402402
network: Network,
403403
database_config: DatabaseConfig,
404-
) -> Result<Self, Error> {
404+
) -> Result<Self, BdkError> {
405405
let any_database_config = match database_config {
406406
DatabaseConfig::Memory => AnyDatabaseConfig::Memory(()),
407407
DatabaseConfig::Sled { config } => AnyDatabaseConfig::Sled(config),
@@ -431,7 +431,7 @@ impl Wallet {
431431
&self,
432432
blockchain: &Blockchain,
433433
progress: Option<Box<dyn Progress>>,
434-
) -> Result<(), Error> {
434+
) -> Result<(), BdkError> {
435435
let bdk_sync_opts = BdkSyncOptions {
436436
progress: progress.map(|p| {
437437
Box::new(ProgressHolder { progress: p })
@@ -446,26 +446,26 @@ impl Wallet {
446446
/// Return a derived address using the external descriptor, see AddressIndex for available address index selection
447447
/// strategies. If none of the keys in the descriptor are derivable (i.e. the descriptor does not end with a * character)
448448
/// then the same address will always be returned for any AddressIndex.
449-
fn get_address(&self, address_index: AddressIndex) -> Result<AddressInfo, Error> {
449+
fn get_address(&self, address_index: AddressIndex) -> Result<AddressInfo, BdkError> {
450450
self.get_wallet()
451451
.get_address(address_index.into())
452452
.map(AddressInfo::from)
453453
}
454454

455455
/// Return the balance, meaning the sum of this wallet’s unspent outputs’ values. Note that this method only operates
456456
/// on the internal database, which first needs to be Wallet.sync manually.
457-
fn get_balance(&self) -> Result<Balance, Error> {
457+
fn get_balance(&self) -> Result<Balance, BdkError> {
458458
self.get_wallet().get_balance().map(|b| b.into())
459459
}
460460

461461
/// Sign a transaction with all the wallet’s signers.
462-
fn sign(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result<bool, Error> {
462+
fn sign(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result<bool, BdkError> {
463463
let mut psbt = psbt.internal.lock().unwrap();
464464
self.get_wallet().sign(&mut psbt, SignOptions::default())
465465
}
466466

467467
/// 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.
468-
fn list_transactions(&self) -> Result<Vec<TransactionDetails>, Error> {
468+
fn list_transactions(&self) -> Result<Vec<TransactionDetails>, BdkError> {
469469
let transaction_details = self.get_wallet().list_transactions(true)?;
470470
Ok(transaction_details
471471
.iter()
@@ -475,7 +475,7 @@ impl Wallet {
475475

476476
/// Return the list of unspent outputs of this wallet. Note that this method only operates on the internal database,
477477
/// which first needs to be Wallet.sync manually.
478-
fn list_unspent(&self) -> Result<Vec<LocalUtxo>, Error> {
478+
fn list_unspent(&self) -> Result<Vec<LocalUtxo>, BdkError> {
479479
let unspents = self.get_wallet().list_unspent()?;
480480
Ok(unspents
481481
.iter()
@@ -484,10 +484,10 @@ impl Wallet {
484484
}
485485
}
486486

487-
fn to_script_pubkey(address: &str) -> Result<BdkScript, Error> {
487+
fn to_script_pubkey(address: &str) -> Result<BdkScript, BdkError> {
488488
BdkAddress::from_str(address)
489489
.map(|x| x.script_pubkey())
490-
.map_err(|e| Error::Generic(e.to_string()))
490+
.map_err(|e| BdkError::Generic(e.to_string()))
491491
}
492492

493493
/// A Bitcoin address.
@@ -496,10 +496,10 @@ struct Address {
496496
}
497497

498498
impl Address {
499-
fn new(address: String) -> Result<Self, Error> {
499+
fn new(address: String) -> Result<Self, BdkError> {
500500
BdkAddress::from_str(address.as_str())
501501
.map(|a| Address { address: a })
502-
.map_err(|e| Error::Generic(e.to_string()))
502+
.map_err(|e| BdkError::Generic(e.to_string()))
503503
}
504504

505505
fn script_pubkey(&self) -> Arc<Script> {
@@ -720,7 +720,7 @@ impl TxBuilder {
720720
}
721721

722722
/// Finish building the transaction. Returns the BIP174 PSBT.
723-
fn finish(&self, wallet: &Wallet) -> Result<TxBuilderResult, Error> {
723+
fn finish(&self, wallet: &Wallet) -> Result<TxBuilderResult, BdkError> {
724724
let wallet = wallet.get_wallet();
725725
let mut tx_builder = wallet.build_tx();
726726
for (script, amount) in &self.recipients {
@@ -827,14 +827,14 @@ impl BumpFeeTxBuilder {
827827
}
828828

829829
/// Finish building the transaction. Returns the BIP174 PSBT.
830-
fn finish(&self, wallet: &Wallet) -> Result<Arc<PartiallySignedBitcoinTransaction>, Error> {
830+
fn finish(&self, wallet: &Wallet) -> Result<Arc<PartiallySignedBitcoinTransaction>, BdkError> {
831831
let wallet = wallet.get_wallet();
832832
let txid = Txid::from_str(self.txid.as_str())?;
833833
let mut tx_builder = wallet.build_fee_bump(txid)?;
834834
tx_builder.fee_rate(FeeRate::from_sat_per_vb(self.fee_rate));
835835
if let Some(allow_shrinking) = &self.allow_shrinking {
836-
let address =
837-
BdkAddress::from_str(allow_shrinking).map_err(|e| Error::Generic(e.to_string()))?;
836+
let address = BdkAddress::from_str(allow_shrinking)
837+
.map_err(|e| BdkError::Generic(e.to_string()))?;
838838
let script = address.script_pubkey();
839839
tx_builder.allow_shrinking(script)?;
840840
}
@@ -857,7 +857,7 @@ impl BumpFeeTxBuilder {
857857
}
858858
}
859859

860-
fn generate_mnemonic(word_count: WordCount) -> Result<String, Error> {
860+
fn generate_mnemonic(word_count: WordCount) -> Result<String, BdkError> {
861861
let mnemonic: GeneratedKey<_, BareCtx> =
862862
Mnemonic::generate((word_count, Language::English)).unwrap();
863863
Ok(mnemonic.to_string())
@@ -868,12 +868,12 @@ struct DerivationPath {
868868
}
869869

870870
impl DerivationPath {
871-
fn new(path: String) -> Result<Self, Error> {
871+
fn new(path: String) -> Result<Self, BdkError> {
872872
BdkDerivationPath::from_str(&path)
873873
.map(|x| DerivationPath {
874874
derivation_path_mutex: Mutex::new(x),
875875
})
876-
.map_err(|e| Error::Generic(e.to_string()))
876+
.map_err(|e| BdkError::Generic(e.to_string()))
877877
}
878878
}
879879

@@ -882,9 +882,9 @@ struct DescriptorSecretKey {
882882
}
883883

884884
impl DescriptorSecretKey {
885-
fn new(network: Network, mnemonic: String, password: Option<String>) -> Result<Self, Error> {
885+
fn new(network: Network, mnemonic: String, password: Option<String>) -> Result<Self, BdkError> {
886886
let mnemonic = Mnemonic::parse_in(Language::English, mnemonic)
887-
.map_err(|e| Error::Generic(e.to_string()))?;
887+
.map_err(|e| BdkError::Generic(e.to_string()))?;
888888
let xkey: ExtendedKey = (mnemonic, password).into_extended_key()?;
889889
let descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey {
890890
origin: None,
@@ -897,7 +897,7 @@ impl DescriptorSecretKey {
897897
})
898898
}
899899

900-
fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, Error> {
900+
fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> {
901901
let secp = Secp256k1::new();
902902
let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap();
903903
let path = path.derivation_path_mutex.lock().unwrap().deref().clone();
@@ -984,7 +984,7 @@ struct DescriptorPublicKey {
984984
}
985985

986986
impl DescriptorPublicKey {
987-
fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, Error> {
987+
fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> {
988988
let secp = Secp256k1::new();
989989
let descriptor_public_key = self.descriptor_public_key_mutex.lock().unwrap();
990990
let path = path.derivation_path_mutex.lock().unwrap().deref().clone();
@@ -1126,7 +1126,7 @@ mod test {
11261126
fn derive_dsk(
11271127
key: &DescriptorSecretKey,
11281128
path: &str,
1129-
) -> Result<Arc<DescriptorSecretKey>, Error> {
1129+
) -> Result<Arc<DescriptorSecretKey>, BdkError> {
11301130
let path = Arc::new(DerivationPath::new(path.to_string()).unwrap());
11311131
key.derive(path)
11321132
}
@@ -1139,7 +1139,7 @@ mod test {
11391139
fn derive_dpk(
11401140
key: &DescriptorPublicKey,
11411141
path: &str,
1142-
) -> Result<Arc<DescriptorPublicKey>, Error> {
1142+
) -> Result<Arc<DescriptorPublicKey>, BdkError> {
11431143
let path = Arc::new(DerivationPath::new(path.to_string()).unwrap());
11441144
key.derive(path)
11451145
}

0 commit comments

Comments
 (0)