Skip to content

Commit ccf5fbd

Browse files
feat: add generic alpha 3 error
1 parent 4f6c198 commit ccf5fbd

File tree

11 files changed

+177
-137
lines changed

11 files changed

+177
-137
lines changed

bdk-ffi/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bdk-ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ bdk = { version = "1.0.0-alpha.3", features = ["all-keys", "keys-bip39"] }
3030

3131
bdk_esplora = { version = "0.5.0", default-features = false, features = ["std", "blocking"] }
3232
uniffi = { version = "=0.25.1" }
33+
thiserror = "1.0.50"
3334

3435
[build-dependencies]
3536
uniffi = { version = "=0.25.1", features = ["build"] }

bdk-ffi/src/bdk.udl

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
namespace bdk {};
22

3+
// ------------------------------------------------------------------------
4+
// bdk crate - error module
5+
// ------------------------------------------------------------------------
6+
7+
[Error]
8+
enum Alpha3Error {
9+
"Generic"
10+
};
11+
12+
[Error]
13+
interface CalculateFeeError {
14+
MissingTxOut(sequence<OutPoint> out_points);
15+
NegativeFee(i64 fee);
16+
};
17+
318
// ------------------------------------------------------------------------
419
// bdk crate - types module
520
// ------------------------------------------------------------------------
@@ -36,7 +51,7 @@ dictionary Balance {
3651
u64 total;
3752
};
3853

39-
dictionary LocalUtxo {
54+
dictionary LocalOutput {
4055
OutPoint outpoint;
4156
TxOut txout;
4257
KeychainKind keychain;
@@ -52,42 +67,6 @@ dictionary TxOut {
5267
// bdk crate - wallet module
5368
// ------------------------------------------------------------------------
5469

55-
[Error]
56-
enum BdkError {
57-
"Generic",
58-
"NoRecipients",
59-
"NoUtxosSelected",
60-
"OutputBelowDustLimit",
61-
"InsufficientFunds",
62-
"BnBTotalTriesExceeded",
63-
"BnBNoExactMatch",
64-
"UnknownUtxo",
65-
"TransactionNotFound",
66-
"TransactionConfirmed",
67-
"IrreplaceableTransaction",
68-
"FeeRateTooLow",
69-
"FeeTooLow",
70-
"FeeRateUnavailable",
71-
"MissingKeyOrigin",
72-
"Key",
73-
"ChecksumMismatch",
74-
"SpendingPolicyRequired",
75-
"InvalidPolicyPathError",
76-
"Signer",
77-
"InvalidOutpoint",
78-
"Descriptor",
79-
"Miniscript",
80-
"MiniscriptPsbt",
81-
"Bip32",
82-
"Psbt",
83-
};
84-
85-
[Error]
86-
interface CalculateFeeError {
87-
MissingTxOut(sequence<OutPoint> out_points);
88-
NegativeFee(i64 fee);
89-
};
90-
9170
interface FeeRate {
9271
f32 as_sat_per_vb();
9372
f32 sat_per_kwu();
@@ -100,7 +79,7 @@ enum ChangeSpendPolicy {
10079
};
10180

10281
interface Wallet {
103-
[Name=new_no_persist, Throws=BdkError]
82+
[Name=new_no_persist, Throws=Alpha3Error]
10483
constructor(Descriptor descriptor, Descriptor? change_descriptor, Network network);
10584

10685
AddressInfo get_address(AddressIndex address_index);
@@ -113,10 +92,10 @@ interface Wallet {
11392

11493
boolean is_mine([ByRef] Script script);
11594

116-
[Throws=BdkError]
95+
[Throws=Alpha3Error]
11796
void apply_update(Update update);
11897

119-
[Throws=BdkError]
98+
[Throws=Alpha3Error]
12099
boolean sign(PartiallySignedTransaction psbt);
121100

122101
SentAndReceivedValues sent_and_received([ByRef] Transaction tx);
@@ -165,7 +144,7 @@ interface TxBuilder {
165144

166145
TxBuilder enable_rbf_with_sequence(u32 nsequence);
167146

168-
[Throws=BdkError]
147+
[Throws=Alpha3Error]
169148
PartiallySignedTransaction finish([ByRef] Wallet wallet);
170149
};
171150

@@ -178,7 +157,7 @@ interface BumpFeeTxBuilder {
178157

179158
BumpFeeTxBuilder enable_rbf_with_sequence(u32 nsequence);
180159

181-
[Throws=BdkError]
160+
[Throws=Alpha3Error]
182161
PartiallySignedTransaction finish([ByRef] Wallet wallet);
183162
};
184163

@@ -189,30 +168,30 @@ interface BumpFeeTxBuilder {
189168
interface Mnemonic {
190169
constructor(WordCount word_count);
191170

192-
[Name=from_string, Throws=BdkError]
171+
[Name=from_string, Throws=Alpha3Error]
193172
constructor(string mnemonic);
194173

195-
[Name=from_entropy, Throws=BdkError]
174+
[Name=from_entropy, Throws=Alpha3Error]
196175
constructor(sequence<u8> entropy);
197176

198177
string as_string();
199178
};
200179

201180
interface DerivationPath {
202-
[Throws=BdkError]
181+
[Throws=Alpha3Error]
203182
constructor(string path);
204183
};
205184

206185
interface DescriptorSecretKey {
207186
constructor(Network network, [ByRef] Mnemonic mnemonic, string? password);
208187

209-
[Name=from_string, Throws=BdkError]
188+
[Name=from_string, Throws=Alpha3Error]
210189
constructor(string secret_key);
211190

212-
[Throws=BdkError]
191+
[Throws=Alpha3Error]
213192
DescriptorSecretKey derive([ByRef] DerivationPath path);
214193

215-
[Throws=BdkError]
194+
[Throws=Alpha3Error]
216195
DescriptorSecretKey extend([ByRef] DerivationPath path);
217196

218197
DescriptorPublicKey as_public();
@@ -223,20 +202,20 @@ interface DescriptorSecretKey {
223202
};
224203

225204
interface DescriptorPublicKey {
226-
[Name=from_string, Throws=BdkError]
205+
[Name=from_string, Throws=Alpha3Error]
227206
constructor(string public_key);
228207

229-
[Throws=BdkError]
208+
[Throws=Alpha3Error]
230209
DescriptorPublicKey derive([ByRef] DerivationPath path);
231210

232-
[Throws=BdkError]
211+
[Throws=Alpha3Error]
233212
DescriptorPublicKey extend([ByRef] DerivationPath path);
234213

235214
string as_string();
236215
};
237216

238217
interface Descriptor {
239-
[Throws=BdkError]
218+
[Throws=Alpha3Error]
240219
constructor(string descriptor, Network network);
241220

242221
[Name=new_bip44]
@@ -275,10 +254,10 @@ interface Descriptor {
275254
interface EsploraClient {
276255
constructor(string url);
277256

278-
[Throws=BdkError]
257+
[Throws=Alpha3Error]
279258
Update scan(Wallet wallet, u64 stop_gap, u64 parallel_requests);
280259

281-
[Throws=BdkError]
260+
[Throws=Alpha3Error]
282261
void broadcast([ByRef] Transaction transaction);
283262
};
284263

@@ -322,7 +301,7 @@ enum WordCount {
322301
};
323302

324303
interface Address {
325-
[Throws=BdkError]
304+
[Throws=Alpha3Error]
326305
constructor(string address, Network network);
327306

328307
Network network();
@@ -337,7 +316,7 @@ interface Address {
337316
};
338317

339318
interface Transaction {
340-
[Throws=BdkError]
319+
[Throws=Alpha3Error]
341320
constructor(sequence<u8> transaction_bytes);
342321

343322
string txid();
@@ -356,7 +335,7 @@ interface Transaction {
356335
};
357336

358337
interface PartiallySignedTransaction {
359-
[Throws=BdkError]
338+
[Throws=Alpha3Error]
360339
constructor(string psbt_base64);
361340

362341
string serialize();
@@ -367,4 +346,4 @@ interface PartiallySignedTransaction {
367346
dictionary OutPoint {
368347
string txid;
369348
u32 vout;
370-
};
349+
};

bdk-ffi/src/bitcoin.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use bdk::bitcoin::Address as BdkAddress;
88
use bdk::bitcoin::OutPoint as BdkOutPoint;
99
use bdk::bitcoin::Transaction as BdkTransaction;
1010
use bdk::bitcoin::Txid;
11-
use bdk::Error as BdkError;
1211

1312
use std::io::Cursor;
1413
use std::str::FromStr;
1514
use std::sync::{Arc, Mutex};
15+
use crate::error::Alpha3Error;
1616

1717
#[derive(Clone, Debug, PartialEq, Eq)]
1818
pub struct Script(pub(crate) BdkScriptBuf);
@@ -71,14 +71,14 @@ pub struct Address {
7171
}
7272

7373
impl Address {
74-
pub fn new(address: String, network: Network) -> Result<Self, BdkError> {
74+
pub fn new(address: String, network: Network) -> Result<Self, Alpha3Error> {
7575
let parsed_address = address
7676
.parse::<bdk::bitcoin::Address<NetworkUnchecked>>()
77-
.map_err(|e| BdkError::Generic(e.to_string()))?;
77+
.map_err(|e| Alpha3Error::Generic)?;
7878

7979
let network_checked_address = parsed_address
8080
.require_network(network.into())
81-
.map_err(|e| BdkError::Generic(e.to_string()))?;
81+
.map_err(|e| Alpha3Error::Generic)?;
8282

8383
Ok(Address {
8484
inner: network_checked_address,
@@ -151,10 +151,10 @@ pub struct Transaction {
151151
}
152152

153153
impl Transaction {
154-
pub fn new(transaction_bytes: Vec<u8>) -> Result<Self, BdkError> {
154+
pub fn new(transaction_bytes: Vec<u8>) -> Result<Self, Alpha3Error> {
155155
let mut decoder = Cursor::new(transaction_bytes);
156156
let tx: BdkTransaction = BdkTransaction::consensus_decode(&mut decoder)
157-
.map_err(|e| BdkError::Generic(e.to_string()))?;
157+
.map_err(|e| Alpha3Error::Generic)?;
158158
Ok(Transaction { inner: tx })
159159
}
160160

@@ -230,10 +230,10 @@ pub struct PartiallySignedTransaction {
230230
}
231231

232232
impl PartiallySignedTransaction {
233-
pub(crate) fn new(psbt_base64: String) -> Result<Self, BdkError> {
233+
pub(crate) fn new(psbt_base64: String) -> Result<Self, Alpha3Error> {
234234
let psbt: BdkPartiallySignedTransaction =
235235
BdkPartiallySignedTransaction::from_str(&psbt_base64)
236-
.map_err(|e| BdkError::Generic(e.to_string()))?;
236+
.map_err(|e| Alpha3Error::Generic)?;
237237

238238
Ok(PartiallySignedTransaction {
239239
inner: Mutex::new(psbt),

bdk-ffi/src/descriptor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::keys::DescriptorPublicKey;
22
use crate::keys::DescriptorSecretKey;
33
use crate::Network;
4+
use crate::error::Alpha3Error;
45

56
use bdk::bitcoin::bip32::Fingerprint;
67
use bdk::bitcoin::key::Secp256k1;
@@ -11,7 +12,6 @@ use bdk::template::{
1112
Bip44, Bip44Public, Bip49, Bip49Public, Bip84, Bip84Public, Bip86, Bip86Public,
1213
DescriptorTemplate,
1314
};
14-
use bdk::Error as BdkError;
1515
use bdk::KeychainKind;
1616

1717
use std::str::FromStr;
@@ -23,7 +23,7 @@ pub struct Descriptor {
2323
}
2424

2525
impl Descriptor {
26-
pub(crate) fn new(descriptor: String, network: Network) -> Result<Self, BdkError> {
26+
pub(crate) fn new(descriptor: String, network: Network) -> Result<Self, Alpha3Error> {
2727
let secp = Secp256k1::new();
2828
let (extended_descriptor, key_map) =
2929
descriptor.into_wallet_descriptor(&secp, network.into())?;

0 commit comments

Comments
 (0)