Skip to content

Commit

Permalink
temp: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Jan 10, 2024
1 parent 1cb3a8b commit 115f383
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 46 deletions.
12 changes: 6 additions & 6 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 })
}

Expand Down Expand Up @@ -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),
Expand Down
7 changes: 3 additions & 4 deletions bdk-ffi/src/descriptor.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -402,7 +401,7 @@ mod test {
assert!(descriptor1.is_ok());
assert_matches!(
descriptor2.unwrap_err(),
bdk::Error::Descriptor(Key(InvalidNetwork))
Alpha3Error::Generic
)
}
}
14 changes: 1 addition & 13 deletions bdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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)]
Expand Down Expand Up @@ -57,24 +57,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
Expand Down
10 changes: 3 additions & 7 deletions bdk-ffi/src/esplora.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions bdk-ffi/src/keys.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -62,7 +62,7 @@ impl DerivationPath {
.map(|x| DerivationPath {
inner_mutex: Mutex::new(x),
})
.map_err(|e| Alpha3Error::Generic)
.map_err(|_| Alpha3Error::Generic)
}
}

Expand All @@ -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,
})
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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));
Expand All @@ -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()))
}
Expand Down

0 comments on commit 115f383

Please sign in to comment.