bitcoin-serai changes from next

Expands the NotEnoughFunds error and enables fetching the entire unsigned
transaction, not just the outputs it'll have.
This commit is contained in:
Luke Parker 2024-09-20 02:45:07 -04:00
parent e6300847d6
commit 9eee1d971e
No known key found for this signature in database
3 changed files with 13 additions and 9 deletions

View file

@ -44,7 +44,7 @@ pub enum TransactionError {
#[error("fee was too low to pass the default minimum fee rate")] #[error("fee was too low to pass the default minimum fee rate")]
TooLowFee, TooLowFee,
#[error("not enough funds for these payments")] #[error("not enough funds for these payments")]
NotEnoughFunds, NotEnoughFunds { inputs: u64, payments: u64, fee: u64 },
#[error("transaction was too large")] #[error("transaction was too large")]
TooLargeTransaction, TooLargeTransaction,
} }
@ -213,7 +213,11 @@ impl SignableTransaction {
} }
if input_sat < (payment_sat + needed_fee) { if input_sat < (payment_sat + needed_fee) {
Err(TransactionError::NotEnoughFunds)?; Err(TransactionError::NotEnoughFunds {
inputs: input_sat,
payments: payment_sat,
fee: needed_fee,
})?;
} }
// If there's a change address, check if there's change to give it // If there's a change address, check if there's change to give it
@ -258,9 +262,9 @@ impl SignableTransaction {
res res
} }
/// Returns the outputs this transaction will create. /// Returns the transaction, sans witness, this will create if signed.
pub fn outputs(&self) -> &[TxOut] { pub fn transaction(&self) -> &Transaction {
&self.tx.output &self.tx
} }
/// Create a multisig machine for this transaction. /// Create a multisig machine for this transaction.

View file

@ -195,10 +195,10 @@ async_sequential! {
Err(TransactionError::TooLowFee), Err(TransactionError::TooLowFee),
); );
assert_eq!( assert!(matches!(
SignableTransaction::new(inputs.clone(), &[(addr(), inputs[0].value() * 2)], None, None, FEE), SignableTransaction::new(inputs.clone(), &[(addr(), inputs[0].value() * 2)], None, None, FEE),
Err(TransactionError::NotEnoughFunds), Err(TransactionError::NotEnoughFunds { .. }),
); ));
assert_eq!( assert_eq!(
SignableTransaction::new(inputs, &vec![(addr(), 1000); 10000], None, None, FEE), SignableTransaction::new(inputs, &vec![(addr(), 1000); 10000], None, None, FEE),

View file

@ -455,7 +455,7 @@ impl Bitcoin {
panic!("trying to create a bitcoin transaction without inputs") panic!("trying to create a bitcoin transaction without inputs")
} }
// No outputs left and the change isn't worth enough/not even enough funds to pay the fee // No outputs left and the change isn't worth enough/not even enough funds to pay the fee
Err(TransactionError::NoOutputs | TransactionError::NotEnoughFunds) => Ok(None), Err(TransactionError::NoOutputs | TransactionError::NotEnoughFunds { .. }) => Ok(None),
// amortize_fee removes payments which fall below the dust threshold // amortize_fee removes payments which fall below the dust threshold
Err(TransactionError::DustPayment) => panic!("dust payment despite removing dust"), Err(TransactionError::DustPayment) => panic!("dust payment despite removing dust"),
Err(TransactionError::TooMuchData) => { Err(TransactionError::TooMuchData) => {