diff --git a/src/branch_and_bound.rs b/src/branch_and_bound.rs index 20e14f24..41bb6366 100644 --- a/src/branch_and_bound.rs +++ b/src/branch_and_bound.rs @@ -312,20 +312,24 @@ mod tests { use std::iter::zip; fn create_coin_from_eff_values(eff_values: Vec) -> Vec { - let no_op = - TxOut { value: Amount::ZERO, script_pubkey: ScriptBuf::new() }; + let no_op = TxOut { value: Amount::ZERO, script_pubkey: ScriptBuf::new() }; let fee_rate = FeeRate::ZERO; let long_term_fee_rate = FeeRate::ZERO; eff_values .iter() - .map(|e| Coin { utxo: no_op.clone(), effective_value: *e, waste: SignedAmount::ZERO, fee_rate, long_term_fee_rate }) + .map(|e| Coin { + utxo: no_op.clone(), + effective_value: *e, + waste: SignedAmount::ZERO, + fee_rate, + long_term_fee_rate, + }) .collect() } fn create_coin_with_waste(waste: SignedAmount) -> Vec { - let no_op = - TxOut { value: Amount::ZERO, script_pubkey: ScriptBuf::new() }; + let no_op = TxOut { value: Amount::ZERO, script_pubkey: ScriptBuf::new() }; let fee_rate = FeeRate::ZERO; let long_term_fee_rate = FeeRate::ZERO; @@ -334,7 +338,7 @@ mod tests { effective_value: Amount::from_str("1 cBTC").unwrap(), waste, fee_rate, - long_term_fee_rate + long_term_fee_rate, }; let coin_two = Coin { @@ -342,7 +346,7 @@ mod tests { effective_value: Amount::from_str("2 cBTC").unwrap(), waste, fee_rate, - long_term_fee_rate + long_term_fee_rate, }; let coin_three = Coin { @@ -350,7 +354,7 @@ mod tests { effective_value: Amount::from_str("3 cBTC").unwrap(), waste, fee_rate, - long_term_fee_rate + long_term_fee_rate, }; let coin_four = Coin { @@ -358,7 +362,7 @@ mod tests { effective_value: Amount::from_str("4 cBTC").unwrap(), waste, fee_rate, - long_term_fee_rate + long_term_fee_rate, }; vec![coin_one, coin_two, coin_three, coin_four] @@ -390,10 +394,7 @@ mod tests { let target = Amount::from_str("1 cBTC").unwrap(); let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO); - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 1); assert_eq!(list[0].utxo.value, Amount::from_str("1 cBTC").unwrap()); @@ -404,10 +405,7 @@ mod tests { let target = Amount::from_str("2 cBTC").unwrap(); let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO); - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 1); assert_eq!(list[0].utxo.value, Amount::from_str("2 cBTC").unwrap()); @@ -418,10 +416,7 @@ mod tests { let target = Amount::from_str("3 cBTC").unwrap(); let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO); - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 2); assert_eq!(list[0].utxo.value, Amount::from_str("2 cBTC").unwrap()); @@ -433,10 +428,7 @@ mod tests { let target = Amount::from_str("4 cBTC").unwrap(); let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO); - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 2); assert_eq!(list[0].utxo.value, Amount::from_str("3 cBTC").unwrap()); @@ -448,10 +440,7 @@ mod tests { let target = Amount::from_str("5 cBTC").unwrap(); let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO); - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 2); assert_eq!(list[0].utxo.value, Amount::from_str("3 cBTC").unwrap()); @@ -463,10 +452,7 @@ mod tests { let target = Amount::from_str("6 cBTC").unwrap(); let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO); - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 3); assert_eq!(list[0].utxo.value, Amount::from_str("3 cBTC").unwrap()); @@ -479,10 +465,7 @@ mod tests { let target = Amount::from_str("7 cBTC").unwrap(); let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO); - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 3); assert_eq!(list[0].utxo.value, Amount::from_str("4 cBTC").unwrap()); @@ -495,10 +478,7 @@ mod tests { let target = Amount::from_str("8 cBTC").unwrap(); let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO); - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 3); assert_eq!(list[0].utxo.value, Amount::from_str("4 cBTC").unwrap()); @@ -511,10 +491,7 @@ mod tests { let target = Amount::from_str("9 cBTC").unwrap(); let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO); - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 3); assert_eq!(list[0].utxo.value, Amount::from_str("4 cBTC").unwrap()); @@ -527,10 +504,7 @@ mod tests { let target = Amount::from_str("10 cBTC").unwrap(); let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO); - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 4); assert_eq!(list[0].utxo.value, Amount::from_str("4 cBTC").unwrap()); @@ -552,10 +526,7 @@ mod tests { let coin = Coin::new(tx_out, FeeRate::ZERO, FeeRate::ZERO, Weight::ZERO).unwrap(); let coins = &[coin]; - let list: Vec<_> = - select_coins_bnb(target, cost_of_change, coins) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, cost_of_change, coins).unwrap().collect(); assert_eq!(list.len(), 1); assert_eq!(list[0].utxo.value, Amount::from_str("1.5 cBTC").unwrap()); @@ -582,8 +553,7 @@ mod tests { // the possible combinations are 2,4 or 1,2,3 // fees are cheap, so use 1,2,3 - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 3); assert_eq!(list[0].effective_value, Amount::from_str("3 cBTC").unwrap()); @@ -603,8 +573,7 @@ mod tests { // the possible combinations are 2,4 or 1,2,3 // fees are expensive, so use 2,4 - let list: Vec<_> = - select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); + let list: Vec<_> = select_coins_bnb(target, Amount::ZERO, &coin).unwrap().collect(); assert_eq!(list.len(), 2); assert_eq!(list[0].effective_value, Amount::from_str("4 cBTC").unwrap()); @@ -654,10 +623,7 @@ mod tests { ]; let coins = create_coin_from_eff_values(eff_vals); - let list: Vec<_> = - select_coins_bnb(target, cost_of_change, &coins) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, cost_of_change, &coins).unwrap().collect(); assert_eq!(list.len(), 3); assert_eq!(list[0].effective_value, Amount::from_str("3 cBTC").unwrap()); @@ -680,10 +646,7 @@ mod tests { ]; let coins = create_coin_from_eff_values(eff_vals); - let list: Vec<_> = - select_coins_bnb(target, cost_of_change, &coins) - .unwrap() - .collect(); + let list: Vec<_> = select_coins_bnb(target, cost_of_change, &coins).unwrap().collect(); assert_eq!(list.len(), 3); assert_eq!(list[0].effective_value, Amount::from_str("10 cBTC").unwrap()); @@ -704,11 +667,7 @@ mod tests { let eff_vals: Vec<_> = vals.map(Amount::from_sat).collect(); let coins = create_coin_from_eff_values(eff_vals); - let list = select_coins_bnb( - Amount::from_sat(target), - Amount::ONE_SAT, - &coins, - ); + let list = select_coins_bnb(Amount::from_sat(target), Amount::ONE_SAT, &coins); assert!(list.is_none()); } @@ -731,12 +690,7 @@ mod tests { // Add a value that will match the target before iteration exhaustion occurs. eff_vals.push(Amount::from_sat(target)); let coins = create_coin_from_eff_values(eff_vals); - let mut list = select_coins_bnb( - Amount::from_sat(target), - Amount::ONE_SAT, - &coins, - ) - .unwrap(); + let mut list = select_coins_bnb(Amount::from_sat(target), Amount::ONE_SAT, &coins).unwrap(); assert_eq!(list.len(), 1); assert_eq!(list.next().unwrap().effective_value, Amount::from_sat(target)); diff --git a/src/lib.rs b/src/lib.rs index 11351ab0..a82e72ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,7 @@ pub struct Coin { /// TODO pub fee_rate: FeeRate, /// TODO - pub long_term_fee_rate: FeeRate + pub long_term_fee_rate: FeeRate, } /// TODO @@ -110,8 +110,7 @@ pub fn select_coins( coins: &[Coin], ) -> Option> { { - let bnb = - select_coins_bnb(target, cost_of_change, coins); + let bnb = select_coins_bnb(target, cost_of_change, coins); if bnb.is_some() { bnb