Skip to content

Commit 54beb23

Browse files
fix: fix clippy warnings
1 parent ccf5fbd commit 54beb23

File tree

9 files changed

+34
-54
lines changed

9 files changed

+34
-54
lines changed

bdk-ffi/Cargo.lock

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

bdk-ffi/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ 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"
3433

3534
[build-dependencies]
3635
uniffi = { version = "=0.25.1", features = ["build"] }

bdk-ffi/src/bitcoin.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use bdk::bitcoin::OutPoint as BdkOutPoint;
99
use bdk::bitcoin::Transaction as BdkTransaction;
1010
use bdk::bitcoin::Txid;
1111

12+
use crate::error::Alpha3Error;
1213
use std::io::Cursor;
1314
use std::str::FromStr;
1415
use std::sync::{Arc, Mutex};
15-
use crate::error::Alpha3Error;
1616

1717
#[derive(Clone, Debug, PartialEq, Eq)]
1818
pub struct Script(pub(crate) BdkScriptBuf);
@@ -74,11 +74,11 @@ impl Address {
7474
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| Alpha3Error::Generic)?;
77+
.map_err(|_| Alpha3Error::Generic)?;
7878

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

8383
Ok(Address {
8484
inner: network_checked_address,
@@ -153,8 +153,8 @@ pub struct Transaction {
153153
impl Transaction {
154154
pub fn new(transaction_bytes: Vec<u8>) -> Result<Self, Alpha3Error> {
155155
let mut decoder = Cursor::new(transaction_bytes);
156-
let tx: BdkTransaction = BdkTransaction::consensus_decode(&mut decoder)
157-
.map_err(|e| Alpha3Error::Generic)?;
156+
let tx: BdkTransaction =
157+
BdkTransaction::consensus_decode(&mut decoder).map_err(|_| Alpha3Error::Generic)?;
158158
Ok(Transaction { inner: tx })
159159
}
160160

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

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

bdk-ffi/src/descriptor.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use crate::error::Alpha3Error;
12
use crate::keys::DescriptorPublicKey;
23
use crate::keys::DescriptorSecretKey;
34
use crate::Network;
4-
use crate::error::Alpha3Error;
55

66
use bdk::bitcoin::bip32::Fingerprint;
77
use bdk::bitcoin::key::Secp256k1;
@@ -281,8 +281,7 @@ mod test {
281281
use crate::*;
282282
use assert_matches::assert_matches;
283283

284-
use bdk::descriptor::DescriptorError::Key;
285-
use bdk::keys::KeyError::InvalidNetwork;
284+
use crate::Alpha3Error;
286285

287286
fn get_descriptor_secret_key() -> DescriptorSecretKey {
288287
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();
@@ -400,9 +399,6 @@ mod test {
400399
let descriptor2 = Descriptor::new("wpkh(tprv8hwWMmPE4BVNxGdVt3HhEERZhondQvodUY7Ajyseyhudr4WabJqWKWLr4Wi2r26CDaNCQhhxEftEaNzz7dPGhWuKFU4VULesmhEfZYyBXdE/0/*)".to_string(), Network::Bitcoin);
401400
// Creating a Descriptor using an extended key that doesn't match the network provided will throw and InvalidNetwork Error
402401
assert!(descriptor1.is_ok());
403-
assert_matches!(
404-
descriptor2.unwrap_err(),
405-
bdk::Error::Descriptor(Key(InvalidNetwork))
406-
)
402+
assert_matches!(descriptor2.unwrap_err(), Alpha3Error::Generic)
407403
}
408404
}

bdk-ffi/src/error.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ use std::fmt;
77
use bdk::descriptor::DescriptorError;
88
use bdk::wallet::error::{BuildFeeBumpError, CreateTxError};
99
use bdk::wallet::tx_builder::{AddUtxoError, AllowShrinkingError};
10-
use bdk::wallet::{NewError, NewOrLoadError};
10+
use bdk::wallet::NewError;
1111
use std::convert::Infallible;
1212

13-
#[derive(Debug, thiserror::Error)]
13+
#[derive(Debug)]
1414
pub enum Alpha3Error {
1515
Generic,
1616
}
1717

1818
impl fmt::Display for Alpha3Error {
19-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20-
write!(f, "Error in FFI")
19+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20+
match self {
21+
Alpha3Error::Generic => write!(f, "Error in FFI"),
22+
}
2123
}
2224
}
2325

26+
impl std::error::Error for Alpha3Error {}
27+
2428
impl From<DescriptorError> for Alpha3Error {
2529
fn from(_: DescriptorError) -> Self {
2630
Alpha3Error::Generic
@@ -57,24 +61,12 @@ impl From<bdk::bitcoin::bip32::Error> for Alpha3Error {
5761
}
5862
}
5963

60-
// impl From<FileError<'_>> for TempFfiError {
61-
// fn from(_: FileError<'_>) -> Self {
62-
// TempFfiError::FfiError
63-
// }
64-
// }
65-
6664
impl From<NewError<std::io::Error>> for Alpha3Error {
6765
fn from(_: NewError<std::io::Error>) -> Self {
6866
Alpha3Error::Generic
6967
}
7068
}
7169

72-
// impl From<NewOrLoadError<std::io::Error, IterError>> for Alpha3Error {
73-
// fn from(_: NewOrLoadError<std::io::Error, IterError>) -> Self {
74-
// Alpha3Error::Alpha3Error
75-
// }
76-
// }
77-
7870
impl From<CreateTxError<std::io::Error>> for Alpha3Error {
7971
fn from(_: CreateTxError<std::io::Error>) -> Self {
8072
Alpha3Error::Generic

bdk-ffi/src/esplora.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::wallet::{Update, Wallet};
21
use crate::error::Alpha3Error;
2+
use crate::wallet::{Update, Wallet};
33

44
use bdk::bitcoin::Transaction as BdkTransaction;
55
use bdk::wallet::Update as BdkUpdate;
@@ -32,11 +32,7 @@ impl EsploraClient {
3232

3333
let (update_graph, last_active_indices) = self
3434
.0
35-
.full_scan(
36-
keychain_spks,
37-
stop_gap as usize,
38-
parallel_requests as usize,
39-
)
35+
.full_scan(keychain_spks, stop_gap as usize, parallel_requests as usize)
4036
.unwrap();
4137

4238
let missing_heights = update_graph.missing_heights(wallet.local_chain());
@@ -60,7 +56,7 @@ impl EsploraClient {
6056
let bdk_transaction: BdkTransaction = transaction.into();
6157
self.0
6258
.broadcast(&bdk_transaction)
63-
.map_err(|e| Alpha3Error::Generic)
59+
.map_err(|_| Alpha3Error::Generic)
6460
}
6561

6662
// pub fn estimate_fee();

bdk-ffi/src/keys.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::Network;
21
use crate::error::Alpha3Error;
2+
use crate::Network;
33

44
use bdk::bitcoin::bip32::DerivationPath as BdkDerivationPath;
55
use bdk::bitcoin::key::Secp256k1;
@@ -38,13 +38,13 @@ impl Mnemonic {
3838
pub(crate) fn from_string(mnemonic: String) -> Result<Self, Alpha3Error> {
3939
BdkMnemonic::from_str(&mnemonic)
4040
.map(|m| Mnemonic { inner: m })
41-
.map_err(|e| Alpha3Error::Generic)
41+
.map_err(|_| Alpha3Error::Generic)
4242
}
4343

4444
pub(crate) fn from_entropy(entropy: Vec<u8>) -> Result<Self, Alpha3Error> {
4545
BdkMnemonic::from_entropy(entropy.as_slice())
4646
.map(|m| Mnemonic { inner: m })
47-
.map_err(|e| Alpha3Error::Generic)
47+
.map_err(|_| Alpha3Error::Generic)
4848
}
4949

5050
pub(crate) fn as_string(&self) -> String {
@@ -62,7 +62,7 @@ impl DerivationPath {
6262
.map(|x| DerivationPath {
6363
inner_mutex: Mutex::new(x),
6464
})
65-
.map_err(|e| Alpha3Error::Generic)
65+
.map_err(|_| Alpha3Error::Generic)
6666
}
6767
}
6868

@@ -88,7 +88,7 @@ impl DescriptorSecretKey {
8888

8989
pub(crate) fn from_string(private_key: String) -> Result<Self, Alpha3Error> {
9090
let descriptor_secret_key = BdkDescriptorSecretKey::from_str(private_key.as_str())
91-
.map_err(|e| Alpha3Error::Generic)?;
91+
.map_err(|_| Alpha3Error::Generic)?;
9292
Ok(Self {
9393
inner: descriptor_secret_key,
9494
})
@@ -179,7 +179,7 @@ pub struct DescriptorPublicKey {
179179
impl DescriptorPublicKey {
180180
pub(crate) fn from_string(public_key: String) -> Result<Self, Alpha3Error> {
181181
let descriptor_public_key = BdkDescriptorPublicKey::from_str(public_key.as_str())
182-
.map_err(|e| Alpha3Error::Generic)?;
182+
.map_err(|_| Alpha3Error::Generic)?;
183183
Ok(Self {
184184
inner: descriptor_public_key,
185185
})
@@ -242,9 +242,9 @@ impl DescriptorPublicKey {
242242
mod test {
243243
use crate::keys::{DerivationPath, DescriptorPublicKey, DescriptorSecretKey, Mnemonic};
244244
// use bdk::bitcoin::hashes::hex::ToHex;
245+
use crate::error::Alpha3Error;
245246
use bdk::bitcoin::Network;
246247
use std::sync::Arc;
247-
use crate::error::Alpha3Error;
248248

249249
fn get_inner() -> DescriptorSecretKey {
250250
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();

bdk-ffi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::bitcoin::Script;
1414
use crate::bitcoin::Transaction;
1515
use crate::bitcoin::TxOut;
1616
use crate::descriptor::Descriptor;
17+
use crate::error::Alpha3Error;
1718
use crate::error::CalculateFeeError;
1819
use crate::esplora::EsploraClient;
1920
use crate::keys::DerivationPath;
@@ -22,7 +23,6 @@ use crate::keys::DescriptorSecretKey;
2223
use crate::keys::Mnemonic;
2324
use crate::types::AddressIndex;
2425
use crate::types::AddressInfo;
25-
use crate::error::Alpha3Error;
2626
use crate::types::Balance;
2727
use crate::types::FeeRate;
2828
use crate::types::LocalOutput;

bdk-ffi/src/wallet.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use bdk::bitcoin::psbt::PartiallySignedTransaction as BdkPartiallySignedTransact
1111
use bdk::bitcoin::{OutPoint as BdkOutPoint, Sequence, Txid};
1212
use bdk::wallet::tx_builder::ChangeSpendPolicy;
1313
use bdk::wallet::Update as BdkUpdate;
14-
use bdk::{FeeRate as BdkFeeRate};
14+
use bdk::FeeRate as BdkFeeRate;
1515
use bdk::{SignOptions, Wallet as BdkWallet};
1616

1717
use std::collections::HashSet;
@@ -68,7 +68,7 @@ impl Wallet {
6868
pub fn apply_update(&self, update: Arc<Update>) -> Result<(), Alpha3Error> {
6969
self.get_wallet()
7070
.apply_update(update.0.clone())
71-
.map_err(|e| Alpha3Error::Generic)
71+
.map_err(|_| Alpha3Error::Generic)
7272
}
7373

7474
pub fn is_mine(&self, script: &Script) -> bool {
@@ -85,7 +85,7 @@ impl Wallet {
8585
let mut psbt = psbt.inner.lock().unwrap();
8686
self.get_wallet()
8787
.sign(&mut psbt, SignOptions::default())
88-
.map_err(|e| Alpha3Error::Generic)
88+
.map_err(|_| Alpha3Error::Generic)
8989
}
9090

9191
pub fn sent_and_received(&self, tx: &Transaction) -> SentAndReceivedValues {
@@ -561,8 +561,7 @@ impl BumpFeeTxBuilder {
561561
&self,
562562
wallet: &Wallet,
563563
) -> Result<Arc<PartiallySignedTransaction>, Alpha3Error> {
564-
let txid =
565-
Txid::from_str(self.txid.as_str()).map_err(|e| Alpha3Error::Generic)?;
564+
let txid = Txid::from_str(self.txid.as_str()).map_err(|_| Alpha3Error::Generic)?;
566565
let mut wallet = wallet.get_wallet();
567566
let mut tx_builder = wallet.build_fee_bump(txid)?;
568567
tx_builder.fee_rate(BdkFeeRate::from_sat_per_vb(self.fee_rate));
@@ -579,9 +578,8 @@ impl BumpFeeTxBuilder {
579578
}
580579
}
581580
}
582-
let psbt: BdkPartiallySignedTransaction = tx_builder
583-
.finish()
584-
.map_err(|e| Alpha3Error::Generic)?;
581+
let psbt: BdkPartiallySignedTransaction =
582+
tx_builder.finish().map_err(|_| Alpha3Error::Generic)?;
585583

586584
Ok(Arc::new(psbt.into()))
587585
}

0 commit comments

Comments
 (0)