Skip to content

Commit

Permalink
ci: fix cc and os_str_bytes MSRV errors
Browse files Browse the repository at this point in the history
  • Loading branch information
notmandatory committed Oct 16, 2023
1 parent a3bdf4c commit 17118a5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ jobs:
cargo update -p rustls-webpki:0.101.6 --precise "0.101.1"
cargo update -p zip:0.6.6 --precise "0.6.2"
cargo update -p time --precise "0.3.13"
cargo update -p cc --precise "1.0.81"
cargo update -p byteorder --precise "1.4.3"
cargo update -p webpki --precise "0.22.2"
cargo update -p cc --precise "1.0.81"
cargo update -p jobserver --precise "0.1.26"
cargo update -p os_str_bytes --precise "6.5.1"
- name: Build
run: cargo build ${{ matrix.features }}
- name: Test
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ cargo update -p rustls-webpki:0.101.6 --precise "0.101.1"
cargo update -p zip:0.6.6 --precise "0.6.2"
# time 0.3.14 has MSRV 1.59.0+
cargo update -p time --precise "0.3.13"
# cc 1.0.82 has MSRV 1.61.0+
cargo update -p cc --precise "1.0.81"
# byteorder 1.5.0 has MSRV 1.60.0+
cargo update -p byteorder --precise "1.4.3"
# webpki 0.22.4 requires `ring:0.17.2` which has MSRV 1.61.0+
cargo update -p webpki --precise "0.22.2"
# jobserver 0.1.27 has MSRV 1.66.0+
# cc 1.0.82 has MSRV 1.61.0+
cargo update -p cc --precise "1.0.81"
# jobserver 0.1.27 has MSRV 1.66.0
cargo update -p jobserver --precise "0.1.26"
# os_str_bytes 6.6.0 has MSRV 1.61.0
cargo update -p os_str_bytes --precise "6.5.1"
```

## License
Expand Down
50 changes: 34 additions & 16 deletions crates/bdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::descriptor::DescriptorError;
use crate::wallet::coin_selection;
use crate::{descriptor, wallet, FeeRate, KeychainKind};
use alloc::string::String;
use bitcoin::{absolute, psbt, OutPoint, Sequence};
use bitcoin::{absolute, psbt, OutPoint, Sequence, Txid};
use core::fmt;

/// Old catch-all errors enum that can be thrown by the [`Wallet`](crate::wallet::Wallet)
Expand All @@ -26,12 +26,6 @@ pub enum Error {
Generic(String),
/// Happens when trying to spend an UTXO that is not in the internal database
UnknownUtxo,
// /// Thrown when a tx is not found in the internal database
// TransactionNotFound,
// /// Happens when trying to bump a transaction that is already confirmed
// TransactionConfirmed,
// /// Trying to replace a tx that has a sequence >= `0xFFFFFFFE`
// IrreplaceableTransaction,
/// Node doesn't have data to estimate a fee rate
FeeRateUnavailable,
/// Error while working with [`keys`](crate::keys)
Expand Down Expand Up @@ -348,13 +342,25 @@ impl<P: core::fmt::Display + core::fmt::Debug> std::error::Error for CreateTxErr
/// [`Wallet::build_fee_bump`]: wallet::Wallet::build_fee_bump
pub enum BuildFeeBumpError {
/// Happens when trying to spend an UTXO that is not in the internal database
UnknownUtxo,
UnknownUtxo {
/// The outpoint of the missing UTXO
outpoint: OutPoint,
},
/// Thrown when a tx is not found in the internal database
TransactionNotFound,
TransactionNotFound {
/// The txid of the missing transaction
txid: Txid,
},
/// Happens when trying to bump a transaction that is already confirmed
TransactionConfirmed,
TransactionConfirmed {
/// The txid of the already confirmed transaction
txid: Txid,
},
/// Trying to replace a tx that has a sequence >= `0xFFFFFFFE`
IrreplaceableTransaction,
IrreplaceableTransaction {
/// The txid of the irreplaceable transaction
txid: Txid,
},
/// Node doesn't have data to estimate a fee rate
FeeRateUnavailable,
}
Expand All @@ -363,12 +369,24 @@ pub enum BuildFeeBumpError {
impl fmt::Display for BuildFeeBumpError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnknownUtxo => write!(f, "UTXO not found in the internal database"),
Self::TransactionNotFound => {
write!(f, "Transaction not found in the internal database")
Self::UnknownUtxo { outpoint } => write!(
f,
"UTXO not found in the internal database with txid: {}, vout: {}",
outpoint.txid, outpoint.vout
),
Self::TransactionNotFound { txid } => {
write!(
f,
"Transaction not found in the internal database with txid: {}",
txid
)
}
Self::TransactionConfirmed { txid } => {
write!(f, "Transaction already confirmed with txid: {}", txid)
}
Self::IrreplaceableTransaction { txid } => {
write!(f, "Transaction can't be replaced with txid: {}", txid)
}
Self::TransactionConfirmed => write!(f, "Transaction already confirmed"),
Self::IrreplaceableTransaction => write!(f, "Transaction can't be replaced"),
Self::FeeRateUnavailable => write!(f, "Fee rate unavailable"),
}
}
Expand Down
20 changes: 12 additions & 8 deletions crates/bdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,22 +1291,22 @@ impl<D> Wallet<D> {

let mut tx = graph
.get_tx(txid)
.ok_or(BuildFeeBumpError::TransactionNotFound)?
.ok_or(BuildFeeBumpError::TransactionNotFound { txid })?
.clone();

let pos = graph
.get_chain_position(&self.chain, chain_tip, txid)
.ok_or(BuildFeeBumpError::TransactionNotFound)?;
.ok_or(BuildFeeBumpError::TransactionNotFound { txid })?;
if let ChainPosition::Confirmed(_) = pos {
return Err(BuildFeeBumpError::TransactionConfirmed);
return Err(BuildFeeBumpError::TransactionConfirmed { txid });
}

if !tx
.input
.iter()
.any(|txin| txin.sequence.to_consensus_u32() <= 0xFFFFFFFD)
{
return Err(BuildFeeBumpError::IrreplaceableTransaction);
return Err(BuildFeeBumpError::IrreplaceableTransaction { txid: tx.txid() });
}

let fee = self
Expand All @@ -1321,14 +1321,18 @@ impl<D> Wallet<D> {
let original_utxos = original_txin
.iter()
.map(|txin| -> Result<_, BuildFeeBumpError> {
let prev_tx = graph
.get_tx(txin.previous_output.txid)
.ok_or(BuildFeeBumpError::UnknownUtxo)?;
let prev_tx = graph.get_tx(txin.previous_output.txid).ok_or(
BuildFeeBumpError::UnknownUtxo {
outpoint: txin.previous_output,
},
)?;
let txout = &prev_tx.output[txin.previous_output.vout as usize];

let confirmation_time: ConfirmationTime = graph
.get_chain_position(&self.chain, chain_tip, txin.previous_output.txid)
.ok_or(BuildFeeBumpError::UnknownUtxo)?
.ok_or(BuildFeeBumpError::UnknownUtxo {
outpoint: txin.previous_output,
})?
.cloned()
.into();

Expand Down

0 comments on commit 17118a5

Please sign in to comment.