diff --git a/benches/sighash_bench.rs b/benches/sighash_bench.rs index 9fcbb7d..fd5ed9d 100644 --- a/benches/sighash_bench.rs +++ b/benches/sighash_bench.rs @@ -1,6 +1,6 @@ -use std::rc::Rc; +use std::{hint::black_box, rc::Rc, slice::from_ref}; -use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; +use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use bitcoin::{hashes::Hash, Network, ScriptBuf}; use key_manager::{key_manager::KeyManager, key_type::BitcoinKeyType}; @@ -30,7 +30,7 @@ fn build_single_chain(n_txs: usize, km: &Rc) -> Protocol { let mut protocol = Protocol::new("bench_single"); let builder = ProtocolBuilder {}; - let ext_output = OutputType::taproot(value, &key, &[script.clone()]).unwrap(); + let ext_output = OutputType::taproot(value, &key, from_ref(&script)).unwrap(); builder .add_external_connection( &mut protocol, @@ -55,7 +55,7 @@ fn build_single_chain(n_txs: usize, km: &Rc) -> Protocol { &format!("tx_{i}"), value, &key, - &[script.clone()], + from_ref(&script), &spend_all, &format!("tx_{}", i + 1), &tr_sighash, diff --git a/src/builder/builder.rs b/src/builder/builder.rs index 803bf4b..947c4e4 100644 --- a/src/builder/builder.rs +++ b/src/builder/builder.rs @@ -146,14 +146,14 @@ impl ProtocolBuilder { for (idx, speedup_data) in speedups_data.iter().enumerate() { let tx_name = &format!("tx_to_speedup_{idx}"); - protocol.add_external_transaction(&tx_name)?; + protocol.add_external_transaction(tx_name)?; if let Some(utxo) = &speedup_data.utxo { - protocol.add_unknown_outputs(&tx_name, utxo.vout)?; + protocol.add_unknown_outputs(tx_name, utxo.vout)?; let external_output = OutputType::segwit_key(utxo.amount, &utxo.pub_key)?; protocol.add_connection( &format!("speedup_{idx}"), - &tx_name, + tx_name, external_output.into(), "cpfp", InputSpec::Auto(SighashType::ecdsa_all(), SpendMode::Segwit), @@ -162,10 +162,10 @@ impl ProtocolBuilder { )?; } else { let partial_utxo = speedup_data.partial_utxo.as_ref().unwrap(); - protocol.add_unknown_outputs(&tx_name, partial_utxo.1)?; + protocol.add_unknown_outputs(tx_name, partial_utxo.1)?; protocol.add_connection( &format!("speedup_{idx}"), - &tx_name, + tx_name, speedup_data.output_type.as_ref().unwrap().clone().into(), "cpfp", InputSpec::Auto( @@ -198,9 +198,9 @@ impl ProtocolBuilder { } let total_funding: u64 = funding_inputs.iter().map(|u| u.amount).sum(); - let change_amount = total_funding.checked_sub(speedup_fee).ok_or_else(|| { - ProtocolBuilderError::InsufficientFunds(total_funding, speedup_fee) - })?; + let change_amount = total_funding + .checked_sub(speedup_fee) + .ok_or_else(|| ProtocolBuilderError::InsufficientFunds(total_funding, speedup_fee))?; let change_output = OutputType::segwit_key(change_amount, change_address)?; protocol.add_transaction_output("cpfp", &change_output)?; diff --git a/src/builder/mod.rs b/src/builder/mod.rs index 0e11f6a..418aee6 100644 --- a/src/builder/mod.rs +++ b/src/builder/mod.rs @@ -1,3 +1,4 @@ +#[allow(clippy::module_inception)] mod builder; mod check_params; mod protocol; diff --git a/src/builder/protocol.rs b/src/builder/protocol.rs index 2a43efb..56465cc 100644 --- a/src/builder/protocol.rs +++ b/src/builder/protocol.rs @@ -39,11 +39,11 @@ impl Protocol { } pub fn load(name: &str, storage: Rc) -> Result, ProtocolBuilderError> { - Ok(storage.get(&name, None)?) + Ok(storage.get(name, None)?) } pub fn save(&self, storage: Rc) -> Result<(), ProtocolBuilderError> { - storage.set(&self.name, &self, None)?; + storage.set(&self.name, self, None)?; Ok(()) } @@ -137,6 +137,7 @@ impl Protocol { Ok(transaction.output.len() as u32) } + #[allow(clippy::too_many_arguments)] pub fn add_connection( &mut self, connection_name: &str, @@ -545,17 +546,16 @@ impl Protocol { .graph .get_output(transaction_name, output_index as usize)? { - match output_type { - OutputType::Taproot { leaves, .. } => return Ok((output_type, &leaves)), - _ => {} + if let OutputType::Taproot { leaves, .. } = output_type { + return Ok((output_type, leaves)); } } - return Err(ProtocolBuilderError::CannotGetScriptForOutputType( + Err(ProtocolBuilderError::CannotGetScriptForOutputType( transaction_name.to_string(), output_index, 0, "Output not found".to_string(), - )); + )) } pub fn get_script_to_spend( diff --git a/src/cli.rs b/src/cli.rs index 474a41e..b5d69ee 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,4 +1,4 @@ -use std::{path::PathBuf, rc::Rc}; +use std::{path::PathBuf, rc::Rc, slice::from_ref}; use anyhow::{Ok, Result}; @@ -395,7 +395,7 @@ impl Cli { from, value, &internal_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -491,8 +491,8 @@ impl Cli { to, value, &public_key, - &[script.clone()], - &[script.clone()], + from_ref(&script), + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, diff --git a/src/config.rs b/src/config.rs index ed54c9a..c7f2c63 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,6 +26,8 @@ pub struct Config { impl Config { pub fn new(config: Option) -> Result { - Ok(bitvmx_settings::settings::load_config_file::(config)?) + Ok(bitvmx_settings::settings::load_config_file::( + config, + )?) } } diff --git a/src/errors.rs b/src/errors.rs index 367c0ac..72895cd 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -249,7 +249,7 @@ pub enum ProtocolBuilderError { DustOutput { value: Amount, dust_limit: Amount, - output_type: OutputType, + output_type: Box, }, #[error("Uncompressed public key error: {0}")] diff --git a/src/graph/estimate.rs b/src/graph/estimate.rs index ff8a9db..a065da5 100644 --- a/src/graph/estimate.rs +++ b/src/graph/estimate.rs @@ -16,7 +16,7 @@ pub fn script_num_size(n: u32) -> usize { // Minimal number of bytes needed to hold n let bits = 32 - n.leading_zeros(); - let len = ((bits + 7) / 8) as usize; // ceil(bits/8) + let len = bits.div_ceil(8) as usize; // ceil(bits/8) // Extra byte needed if the top bit of the most significant byte // is set, since CScriptNum encodes sign in that bit. @@ -143,7 +143,7 @@ fn vbytes_from_parts( ) -> u64 { let s = stripped_size as u64; let w = total_witness_bytes_including_marker_flag as u64; - s + ((w + 3) / 4) // ceil(w/4) + s + w.div_ceil(4) // ceil(w/4) } /// Estimate the minimum relay fee (in sats) for `tx` at `feerate_sat_per_vb`, diff --git a/src/graph/graph.rs b/src/graph/graph.rs index b6a72ea..d181fbc 100644 --- a/src/graph/graph.rs +++ b/src/graph/graph.rs @@ -526,7 +526,7 @@ impl TransactionGraph { Ok(acc + parent.outputs[output_index] .get_value() - .ok_or_else(|| GraphError::AmountTypeValueExpected)? + .ok_or(GraphError::AmountTypeValueExpected)? .to_sat()) })?; @@ -550,14 +550,12 @@ impl TransactionGraph { let total_subtracted = total_transaction_amount .checked_add(minimum_relay_fee) - .ok_or_else(|| { + .ok_or({ GraphError::OverflowError(total_transaction_amount, minimum_relay_fee) })?; - let recover_amount = total_parents_amount - .checked_sub(total_subtracted) - .ok_or_else(|| { - GraphError::InsufficientFunds(total_parents_amount, total_subtracted) - })?; + let recover_amount = total_parents_amount.checked_sub(total_subtracted).ok_or( + GraphError::InsufficientFunds(total_parents_amount, total_subtracted), + )?; let recover_amount = Amount::from_sat(recover_amount); // Update OutputType value @@ -671,7 +669,7 @@ impl TransactionGraph { } else { let value = output .get_value() - .ok_or_else(|| GraphError::AmountTypeValueExpected)?; + .ok_or(GraphError::AmountTypeValueExpected)?; remaining = remaining.saturating_sub(value.to_sat()); // Saturating at 0 let current_amount = amounts.get(&parent_key).cloned().unwrap_or_default(); if value.to_sat() > current_amount.to_sat() { @@ -726,7 +724,7 @@ impl TransactionGraph { Ok::( i.output_type()? .get_value() - .ok_or_else(|| GraphError::AmountTypeValueExpected)? + .ok_or(GraphError::AmountTypeValueExpected)? .to_sat(), ) }) diff --git a/src/graph/mod.rs b/src/graph/mod.rs index 267602a..f9e4880 100644 --- a/src/graph/mod.rs +++ b/src/graph/mod.rs @@ -1,2 +1,3 @@ pub mod estimate; +#[allow(clippy::module_inception)] pub mod graph; diff --git a/src/scripts.rs b/src/scripts.rs index c8087d8..9d2ad3e 100644 --- a/src/scripts.rs +++ b/src/scripts.rs @@ -78,14 +78,17 @@ impl KeyType { )), } } +} - pub fn to_string(&self) -> String { - match self { - KeyType::WinternitzKey { .. } => "Winternitz".to_string(), - KeyType::LamportKey { .. } => "Lamport".to_string(), - KeyType::EcdsaKey { .. } => "Ecdsa".to_string(), - KeyType::XOnlyKey { .. } => "XOnly".to_string(), - } +impl Display for KeyType { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let name = match self { + KeyType::WinternitzKey { .. } => "Winternitz", + KeyType::LamportKey { .. } => "Lamport", + KeyType::EcdsaKey => "Ecdsa", + KeyType::XOnlyKey => "XOnly", + }; + write!(f, "{}", name) } } @@ -425,7 +428,7 @@ pub fn ots_checklamport(public_key: &LamportPublicKey, keep_message: bool) -> Sc stack.define(1, format!("signature_{}", i).as_str()); } - lamport_checksig(&mut stack, &public_key, keep_message); + lamport_checksig(&mut stack, public_key, keep_message); stack.get_script() } @@ -514,7 +517,7 @@ pub fn verify_winternitz_signature_timelock( )?; protocol_script.add_stack_item(StackItem::new_schnorr_sig(true)); - protocol_script.add_stack_item(StackItem::new_winternitz_sig(&public_key)); + protocol_script.add_stack_item(StackItem::new_winternitz_sig(public_key)); Ok(protocol_script) } @@ -900,13 +903,13 @@ pub fn build_taproot_spend_info( let total_slots = 1 << (min_depth + 1); // 2^(min_depth + 1) let nodes_at_min_depth = total_slots - scripts_count; // Add leaves at minimum depth - for i in 0..nodes_at_min_depth { - tr_builder = tr_builder.add_leaf(min_depth, leaves[i].get_script().clone())?; + for leaf in &leaves[..nodes_at_min_depth] { + tr_builder = tr_builder.add_leaf(min_depth, leaf.get_script().clone())?; } // Add remaining leaves at minimum depth + 1 - for i in nodes_at_min_depth..scripts_count { - tr_builder = tr_builder.add_leaf(min_depth + 1, leaves[i].get_script().clone())?; + for leaf in &leaves[nodes_at_min_depth..scripts_count] { + tr_builder = tr_builder.add_leaf(min_depth + 1, leaf.get_script().clone())?; } tr_builder @@ -1461,7 +1464,7 @@ mod tests { let mut stack = StackTracker::new(); for hash in signature.to_hashes().iter() { - stack.hexstr(&hex::encode(&hash)); + stack.hexstr(&hex::encode(hash)); } lamport_checksig(&mut stack, &public_key, false); @@ -1487,7 +1490,7 @@ mod tests { let mut stack = StackTracker::new(); for hash in signature.to_hashes().iter() { - stack.hexstr(&hex::encode(&hash)); + stack.hexstr(&hex::encode(hash)); } lamport_checksig(&mut stack, &public_key, true); diff --git a/src/tests/autovalues_fees_test.rs b/src/tests/autovalues_fees_test.rs index 04b4a49..712ea9a 100644 --- a/src/tests/autovalues_fees_test.rs +++ b/src/tests/autovalues_fees_test.rs @@ -3,7 +3,12 @@ mod tests { use bitcoin::{hashes::Hash, ScriptBuf}; use crate::{ - builder::{Protocol, ProtocolBuilder}, errors::ProtocolBuilderError, graph::estimate::estimate_min_relay_fee, scripts::{ProtocolScript, SignMode, StackItem, verify_lamport_signatures}, tests::utils::TestContext, types::{ + builder::{Protocol, ProtocolBuilder}, + errors::ProtocolBuilderError, + graph::estimate::estimate_min_relay_fee, + scripts::{verify_lamport_signatures, ProtocolScript, SignMode, StackItem}, + tests::utils::TestContext, + types::{ connection::{InputSpec, OutputSpec}, input::{InputArgs, SpendMode}, output::OutputType, @@ -66,7 +71,7 @@ mod tests { // Verify parent has output assert!( - parent_tx.output.len() > 0, + !parent_tx.output.is_empty(), "Parent transaction should have at least one output" ); @@ -77,7 +82,7 @@ mod tests { // Verify child consumed parent output by having an input assert!( - child_tx.input.len() > 0, + !child_tx.input.is_empty(), "Child should have at least one input from parent" ); diff --git a/src/tests/builder_connection_test.rs b/src/tests/builder_connection_test.rs index e83209a..f092359 100644 --- a/src/tests/builder_connection_test.rs +++ b/src/tests/builder_connection_test.rs @@ -1,5 +1,7 @@ #[cfg(test)] mod tests { + use std::slice::from_ref; + use bitcoin::{ hashes::Hash, key::rand, @@ -472,8 +474,8 @@ mod tests { "C", value, &internal_taproot_key, - &[script.clone()], - &[script.clone()], + from_ref(&script), + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -495,7 +497,7 @@ mod tests { "A", value, &internal_taproot_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -568,8 +570,8 @@ mod tests { "C", value, &internal_key, - &[script.clone()], - &[script.clone()], + from_ref(&script), + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -635,7 +637,7 @@ mod tests { "A", value, &internal_taproot_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -648,7 +650,7 @@ mod tests { "A", value, &internal_taproot_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -661,7 +663,7 @@ mod tests { "B", value, &internal_taproot_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -674,7 +676,7 @@ mod tests { "C", value, &internal_taproot_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -687,7 +689,7 @@ mod tests { "D", value, &internal_taproot_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -700,7 +702,7 @@ mod tests { "A", value, &internal_taproot_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -713,7 +715,7 @@ mod tests { "D", value, &internal_taproot_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -726,7 +728,7 @@ mod tests { "F", value, &internal_taproot_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -742,8 +744,8 @@ mod tests { "I", value, &internal_taproot_key, - &[script.clone()], - &[script.clone()], + from_ref(&script), + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -757,7 +759,7 @@ mod tests { "G", value, &internal_taproot_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -899,7 +901,7 @@ mod tests { let txid = Hash::all_zeros(); let script = ProtocolScript::new(ScriptBuf::from(vec![0x04]), &external_key, SignMode::Single); - let output_type = OutputType::taproot(value, &external_key, &[script.clone()])?; + let output_type = OutputType::taproot(value, &external_key, from_ref(&script))?; let mut protocol = Protocol::new("taproot_rounds_endpoints"); let builder = ProtocolBuilder {}; @@ -912,8 +914,8 @@ mod tests { "C", value, &internal_key, - &[script.clone()], - &[script.clone()], + from_ref(&script), + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -946,7 +948,7 @@ mod tests { "A", value, &internal_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -1474,7 +1476,7 @@ mod tests { "A", value, &internal_key, - &[script.clone()], + from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -1524,26 +1526,22 @@ mod tests { let txid = Hash::all_zeros(); // Create a script with SignMode::Skip - this script should not be signed - let skip_script = ProtocolScript::new( - ScriptBuf::from(vec![0x01]), - &ecdsa_key, - SignMode::Skip, - ); + let skip_script = + ProtocolScript::new(ScriptBuf::from(vec![0x01]), &ecdsa_key, SignMode::Skip); let output_type = OutputType::segwit_script(value, &skip_script)?; let mut protocol = Protocol::new("p2wsh_skip_signing"); let builder = ProtocolBuilder {}; - builder - .add_external_connection( - &mut protocol, - "external", - txid, - OutputSpec::Auto(output_type), - "start", - InputSpec::Auto(tc.ecdsa_sighash_type(), SpendMode::Segwit), - )?; + builder.add_external_connection( + &mut protocol, + "external", + txid, + OutputSpec::Auto(output_type), + "start", + InputSpec::Auto(tc.ecdsa_sighash_type(), SpendMode::Segwit), + )?; protocol.build_and_sign(tc.key_manager(), "")?; @@ -1601,11 +1599,8 @@ mod tests { let scripts = vec![script_0, script_1, script_2]; - let segwit_script = ProtocolScript::new( - ScriptBuf::from(vec![0x03]), - &ecdsa_key, - SignMode::Single, - ); + let segwit_script = + ProtocolScript::new(ScriptBuf::from(vec![0x03]), &ecdsa_key, SignMode::Single); let output_type = OutputType::segwit_script(value, &segwit_script)?; let mut protocol = Protocol::new("invalid_leaf_test"); @@ -1708,11 +1703,8 @@ mod tests { let scripts = vec![skip_script, single_script.clone(), skip_script2]; - let segwit_script = ProtocolScript::new( - ScriptBuf::from(vec![0x03]), - &ecdsa_key, - SignMode::Single, - ); + let segwit_script = + ProtocolScript::new(ScriptBuf::from(vec![0x03]), &ecdsa_key, SignMode::Single); let output_type = OutputType::segwit_script(value, &segwit_script)?; let mut protocol = Protocol::new("mixed_signmodes_test"); @@ -1756,7 +1748,7 @@ mod tests { // Verify witness contains expected elements let witness = &tx.input[0].witness; - + // Witness should have: [signature, script, control_block] // At minimum 3 elements (signature, script, control_block) assert!( @@ -1807,7 +1799,7 @@ mod tests { "origin", value, &internal_taproot_key, - &[taproot_script.clone()], + from_ref(&taproot_script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -1840,7 +1832,7 @@ mod tests { // Verify witness structure (at least signature + script + control_block) let last_element_size = taproot_witness.last().map(|w| w.len()).unwrap_or(0); - + // Control block is typically 33 bytes (for single-leaf tree) assert!( last_element_size > 0, @@ -1881,11 +1873,8 @@ mod tests { let leaves = vec![skip_leaf, single_leaf.clone()]; - let segwit_script = ProtocolScript::new( - ScriptBuf::from(vec![0x02]), - &ecdsa_key, - SignMode::Single, - ); + let segwit_script = + ProtocolScript::new(ScriptBuf::from(vec![0x02]), &ecdsa_key, SignMode::Single); let output_type = OutputType::segwit_script(value, &segwit_script)?; let mut protocol = Protocol::new("skip_multi_input_test"); diff --git a/src/tests/builder_persistance_test.rs b/src/tests/builder_persistance_test.rs index 046166b..1ec69f8 100644 --- a/src/tests/builder_persistance_test.rs +++ b/src/tests/builder_persistance_test.rs @@ -174,7 +174,7 @@ mod tests { "A", value, &internal_key, - &[script.clone()], + std::slice::from_ref(&script), &SpendMode::All { key_path_sign: SignMode::Single, }, @@ -225,7 +225,7 @@ mod tests { "A", "B", value, - &[script.clone()], + std::slice::from_ref(&script), 600, &script_expired, &script_renew, diff --git a/src/tests/output_test.rs b/src/tests/output_test.rs index eb1c03c..ac7b8d1 100644 --- a/src/tests/output_test.rs +++ b/src/tests/output_test.rs @@ -73,16 +73,16 @@ mod tests { let normal_output = OutputType::segwit_key(1000, &public_key.into()).unwrap(); // Test auto_value() flags - assert_eq!(auto_output.auto_value(), true); - assert_eq!(auto_output.recover_value(), false); + assert!(auto_output.auto_value()); + assert!(!auto_output.recover_value()); // Test recover_value() flags - assert_eq!(recover_output.auto_value(), false); - assert_eq!(recover_output.recover_value(), true); + assert!(!recover_output.auto_value()); + assert!(recover_output.recover_value()); // Test normal value has no flags - assert_eq!(normal_output.auto_value(), false); - assert_eq!(normal_output.recover_value(), false); + assert!(!normal_output.auto_value()); + assert!(!normal_output.recover_value()); // Test dust_limit() returns >= 540 sats assert!(auto_output.dust_limit().to_sat() >= 540); @@ -100,8 +100,8 @@ mod tests { // Test with SegwitScript let recover_script_output = OutputType::segwit_script(AmountType::Recover, &script).unwrap(); - assert_eq!(recover_script_output.auto_value(), false); - assert_eq!(recover_script_output.recover_value(), true); + assert!(!recover_script_output.auto_value()); + assert!(recover_script_output.recover_value()); assert!(recover_script_output.dust_limit().to_sat() >= 540); } } diff --git a/src/types/connection.rs b/src/types/connection.rs index c16bb3e..517ef2a 100644 --- a/src/types/connection.rs +++ b/src/types/connection.rs @@ -19,21 +19,21 @@ pub enum OutputSpec { Last, } -impl Into for OutputType { - fn into(self) -> OutputSpec { - OutputSpec::Auto(self) +impl From for OutputSpec { + fn from(val: OutputType) -> Self { + OutputSpec::Auto(val) } } -impl Into for usize { - fn into(self) -> OutputSpec { - OutputSpec::Index(self) +impl From for OutputSpec { + fn from(val: usize) -> Self { + OutputSpec::Index(val) } } -impl Into for usize { - fn into(self) -> InputSpec { - InputSpec::Index(self) +impl From for InputSpec { + fn from(val: usize) -> Self { + InputSpec::Index(val) } } diff --git a/src/types/input.rs b/src/types/input.rs index 4b55acb..916a14b 100644 --- a/src/types/input.rs +++ b/src/types/input.rs @@ -6,7 +6,8 @@ use serde::{Deserialize, Serialize}; use crate::{ errors::{GraphError, ProtocolBuilderError}, - scripts::SignMode, types::output::SignatureType, + scripts::SignMode, + types::output::SignatureType, }; use super::OutputType; @@ -265,6 +266,10 @@ impl InputArgs { Self::Segwit { args } => args.len(), } } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -364,7 +369,6 @@ impl InputType { pub fn set_value(&mut self, value: Amount) { if let Some(output_type) = &mut self.output_type { output_type.set_value(value); - return; } } diff --git a/src/types/output.rs b/src/types/output.rs index 12c07c1..a3fb52d 100644 --- a/src/types/output.rs +++ b/src/types/output.rs @@ -129,9 +129,9 @@ impl Utxo { } } } -impl Into for Utxo { - fn into(self) -> SpeedupData { - SpeedupData::new(self) +impl From for SpeedupData { + fn from(val: Utxo) -> Self { + SpeedupData::new(val) } } @@ -317,7 +317,7 @@ impl OutputType { return Err(ProtocolBuilderError::DustOutput { value, dust_limit: self.dust_limit(), - output_type: self.clone(), + output_type: Box::new(self.clone()), }); } Ok(value)