fix: fix clippy warnings

This commit is contained in:
thunderbiscuit 2024-01-10 14:10:25 -05:00
parent ccf5fbda6e
commit 54beb23f13
No known key found for this signature in database
GPG Key ID: 88253696EB836462
9 changed files with 34 additions and 54 deletions

1
bdk-ffi/Cargo.lock generated
View File

@ -163,7 +163,6 @@ dependencies = [
"assert_matches",
"bdk",
"bdk_esplora",
"thiserror",
"uniffi",
]

View File

@ -30,7 +30,6 @@ bdk = { version = "1.0.0-alpha.3", features = ["all-keys", "keys-bip39"] }
bdk_esplora = { version = "0.5.0", default-features = false, features = ["std", "blocking"] }
uniffi = { version = "=0.25.1" }
thiserror = "1.0.50"
[build-dependencies]
uniffi = { version = "=0.25.1", features = ["build"] }

View File

@ -9,10 +9,10 @@ use bdk::bitcoin::OutPoint as BdkOutPoint;
use bdk::bitcoin::Transaction as BdkTransaction;
use bdk::bitcoin::Txid;
use crate::error::Alpha3Error;
use std::io::Cursor;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use crate::error::Alpha3Error;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Script(pub(crate) BdkScriptBuf);
@ -74,11 +74,11 @@ impl Address {
pub fn new(address: String, network: Network) -> Result<Self, Alpha3Error> {
let parsed_address = address
.parse::<bdk::bitcoin::Address<NetworkUnchecked>>()
.map_err(|e| Alpha3Error::Generic)?;
.map_err(|_| Alpha3Error::Generic)?;
let network_checked_address = parsed_address
.require_network(network.into())
.map_err(|e| Alpha3Error::Generic)?;
.map_err(|_| Alpha3Error::Generic)?;
Ok(Address {
inner: network_checked_address,
@ -153,8 +153,8 @@ pub struct Transaction {
impl Transaction {
pub fn new(transaction_bytes: Vec<u8>) -> Result<Self, Alpha3Error> {
let mut decoder = Cursor::new(transaction_bytes);
let tx: BdkTransaction = BdkTransaction::consensus_decode(&mut decoder)
.map_err(|e| Alpha3Error::Generic)?;
let tx: BdkTransaction =
BdkTransaction::consensus_decode(&mut decoder).map_err(|_| Alpha3Error::Generic)?;
Ok(Transaction { inner: tx })
}
@ -233,7 +233,7 @@ impl PartiallySignedTransaction {
pub(crate) fn new(psbt_base64: String) -> Result<Self, Alpha3Error> {
let psbt: BdkPartiallySignedTransaction =
BdkPartiallySignedTransaction::from_str(&psbt_base64)
.map_err(|e| Alpha3Error::Generic)?;
.map_err(|_| Alpha3Error::Generic)?;
Ok(PartiallySignedTransaction {
inner: Mutex::new(psbt),

View File

@ -1,7 +1,7 @@
use crate::error::Alpha3Error;
use crate::keys::DescriptorPublicKey;
use crate::keys::DescriptorSecretKey;
use crate::Network;
use crate::error::Alpha3Error;
use bdk::bitcoin::bip32::Fingerprint;
use bdk::bitcoin::key::Secp256k1;
@ -281,8 +281,7 @@ mod test {
use crate::*;
use assert_matches::assert_matches;
use bdk::descriptor::DescriptorError::Key;
use bdk::keys::KeyError::InvalidNetwork;
use crate::Alpha3Error;
fn get_descriptor_secret_key() -> DescriptorSecretKey {
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 {
let descriptor2 = Descriptor::new("wpkh(tprv8hwWMmPE4BVNxGdVt3HhEERZhondQvodUY7Ajyseyhudr4WabJqWKWLr4Wi2r26CDaNCQhhxEftEaNzz7dPGhWuKFU4VULesmhEfZYyBXdE/0/*)".to_string(), Network::Bitcoin);
// Creating a Descriptor using an extended key that doesn't match the network provided will throw and InvalidNetwork Error
assert!(descriptor1.is_ok());
assert_matches!(
descriptor2.unwrap_err(),
bdk::Error::Descriptor(Key(InvalidNetwork))
)
assert_matches!(descriptor2.unwrap_err(), Alpha3Error::Generic)
}
}

View File

@ -7,20 +7,24 @@ use std::fmt;
use bdk::descriptor::DescriptorError;
use bdk::wallet::error::{BuildFeeBumpError, CreateTxError};
use bdk::wallet::tx_builder::{AddUtxoError, AllowShrinkingError};
use bdk::wallet::{NewError, NewOrLoadError};
use bdk::wallet::NewError;
use std::convert::Infallible;
#[derive(Debug, thiserror::Error)]
#[derive(Debug)]
pub enum Alpha3Error {
Generic,
}
impl fmt::Display for Alpha3Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Error in FFI")
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Alpha3Error::Generic => write!(f, "Error in FFI"),
}
}
}
impl std::error::Error for Alpha3Error {}
impl From<DescriptorError> for Alpha3Error {
fn from(_: DescriptorError) -> Self {
Alpha3Error::Generic
@ -57,24 +61,12 @@ impl From<bdk::bitcoin::bip32::Error> for Alpha3Error {
}
}
// impl From<FileError<'_>> for TempFfiError {
// fn from(_: FileError<'_>) -> Self {
// TempFfiError::FfiError
// }
// }
impl From<NewError<std::io::Error>> for Alpha3Error {
fn from(_: NewError<std::io::Error>) -> Self {
Alpha3Error::Generic
}
}
// impl From<NewOrLoadError<std::io::Error, IterError>> for Alpha3Error {
// fn from(_: NewOrLoadError<std::io::Error, IterError>) -> Self {
// Alpha3Error::Alpha3Error
// }
// }
impl From<CreateTxError<std::io::Error>> for Alpha3Error {
fn from(_: CreateTxError<std::io::Error>) -> Self {
Alpha3Error::Generic

View File

@ -1,5 +1,5 @@
use crate::wallet::{Update, Wallet};
use crate::error::Alpha3Error;
use crate::wallet::{Update, Wallet};
use bdk::bitcoin::Transaction as BdkTransaction;
use bdk::wallet::Update as BdkUpdate;
@ -32,11 +32,7 @@ impl EsploraClient {
let (update_graph, last_active_indices) = self
.0
.full_scan(
keychain_spks,
stop_gap as usize,
parallel_requests as usize,
)
.full_scan(keychain_spks, stop_gap as usize, parallel_requests as usize)
.unwrap();
let missing_heights = update_graph.missing_heights(wallet.local_chain());
@ -60,7 +56,7 @@ impl EsploraClient {
let bdk_transaction: BdkTransaction = transaction.into();
self.0
.broadcast(&bdk_transaction)
.map_err(|e| Alpha3Error::Generic)
.map_err(|_| Alpha3Error::Generic)
}
// pub fn estimate_fee();

View File

@ -1,5 +1,5 @@
use crate::Network;
use crate::error::Alpha3Error;
use crate::Network;
use bdk::bitcoin::bip32::DerivationPath as BdkDerivationPath;
use bdk::bitcoin::key::Secp256k1;
@ -38,13 +38,13 @@ impl Mnemonic {
pub(crate) fn from_string(mnemonic: String) -> Result<Self, Alpha3Error> {
BdkMnemonic::from_str(&mnemonic)
.map(|m| Mnemonic { inner: m })
.map_err(|e| Alpha3Error::Generic)
.map_err(|_| Alpha3Error::Generic)
}
pub(crate) fn from_entropy(entropy: Vec<u8>) -> Result<Self, Alpha3Error> {
BdkMnemonic::from_entropy(entropy.as_slice())
.map(|m| Mnemonic { inner: m })
.map_err(|e| Alpha3Error::Generic)
.map_err(|_| Alpha3Error::Generic)
}
pub(crate) fn as_string(&self) -> String {
@ -62,7 +62,7 @@ impl DerivationPath {
.map(|x| DerivationPath {
inner_mutex: Mutex::new(x),
})
.map_err(|e| Alpha3Error::Generic)
.map_err(|_| Alpha3Error::Generic)
}
}
@ -88,7 +88,7 @@ impl DescriptorSecretKey {
pub(crate) fn from_string(private_key: String) -> Result<Self, Alpha3Error> {
let descriptor_secret_key = BdkDescriptorSecretKey::from_str(private_key.as_str())
.map_err(|e| Alpha3Error::Generic)?;
.map_err(|_| Alpha3Error::Generic)?;
Ok(Self {
inner: descriptor_secret_key,
})
@ -179,7 +179,7 @@ pub struct DescriptorPublicKey {
impl DescriptorPublicKey {
pub(crate) fn from_string(public_key: String) -> Result<Self, Alpha3Error> {
let descriptor_public_key = BdkDescriptorPublicKey::from_str(public_key.as_str())
.map_err(|e| Alpha3Error::Generic)?;
.map_err(|_| Alpha3Error::Generic)?;
Ok(Self {
inner: descriptor_public_key,
})
@ -242,9 +242,9 @@ impl DescriptorPublicKey {
mod test {
use crate::keys::{DerivationPath, DescriptorPublicKey, DescriptorSecretKey, Mnemonic};
// use bdk::bitcoin::hashes::hex::ToHex;
use crate::error::Alpha3Error;
use bdk::bitcoin::Network;
use std::sync::Arc;
use crate::error::Alpha3Error;
fn get_inner() -> DescriptorSecretKey {
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();

View File

@ -14,6 +14,7 @@ use crate::bitcoin::Script;
use crate::bitcoin::Transaction;
use crate::bitcoin::TxOut;
use crate::descriptor::Descriptor;
use crate::error::Alpha3Error;
use crate::error::CalculateFeeError;
use crate::esplora::EsploraClient;
use crate::keys::DerivationPath;
@ -22,7 +23,6 @@ use crate::keys::DescriptorSecretKey;
use crate::keys::Mnemonic;
use crate::types::AddressIndex;
use crate::types::AddressInfo;
use crate::error::Alpha3Error;
use crate::types::Balance;
use crate::types::FeeRate;
use crate::types::LocalOutput;

View File

@ -11,7 +11,7 @@ use bdk::bitcoin::psbt::PartiallySignedTransaction as BdkPartiallySignedTransact
use bdk::bitcoin::{OutPoint as BdkOutPoint, Sequence, Txid};
use bdk::wallet::tx_builder::ChangeSpendPolicy;
use bdk::wallet::Update as BdkUpdate;
use bdk::{FeeRate as BdkFeeRate};
use bdk::FeeRate as BdkFeeRate;
use bdk::{SignOptions, Wallet as BdkWallet};
use std::collections::HashSet;
@ -68,7 +68,7 @@ impl Wallet {
pub fn apply_update(&self, update: Arc<Update>) -> Result<(), Alpha3Error> {
self.get_wallet()
.apply_update(update.0.clone())
.map_err(|e| Alpha3Error::Generic)
.map_err(|_| Alpha3Error::Generic)
}
pub fn is_mine(&self, script: &Script) -> bool {
@ -85,7 +85,7 @@ impl Wallet {
let mut psbt = psbt.inner.lock().unwrap();
self.get_wallet()
.sign(&mut psbt, SignOptions::default())
.map_err(|e| Alpha3Error::Generic)
.map_err(|_| Alpha3Error::Generic)
}
pub fn sent_and_received(&self, tx: &Transaction) -> SentAndReceivedValues {
@ -561,8 +561,7 @@ impl BumpFeeTxBuilder {
&self,
wallet: &Wallet,
) -> Result<Arc<PartiallySignedTransaction>, Alpha3Error> {
let txid =
Txid::from_str(self.txid.as_str()).map_err(|e| Alpha3Error::Generic)?;
let txid = Txid::from_str(self.txid.as_str()).map_err(|_| Alpha3Error::Generic)?;
let mut wallet = wallet.get_wallet();
let mut tx_builder = wallet.build_fee_bump(txid)?;
tx_builder.fee_rate(BdkFeeRate::from_sat_per_vb(self.fee_rate));
@ -579,9 +578,8 @@ impl BumpFeeTxBuilder {
}
}
}
let psbt: BdkPartiallySignedTransaction = tx_builder
.finish()
.map_err(|e| Alpha3Error::Generic)?;
let psbt: BdkPartiallySignedTransaction =
tx_builder.finish().map_err(|_| Alpha3Error::Generic)?;
Ok(Arc::new(psbt.into()))
}