diff --git a/src/lib.rs b/src/lib.rs index 2996e2d4..3b72845c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,7 +62,7 @@ pub fn select_coins( fee_rate: FeeRate, weighted_utxos: &mut [WeightedUtxo], ) -> Option> { - match select_coins_bnb(target, cost_of_change, weighted_utxos.to_vec()) { + match select_coins_bnb(target, cost_of_change, fee_rate, weighted_utxos.to_vec()) { Some(_res) => Some(Vec::new()), None => select_coins_srd(target, fee_rate, weighted_utxos, &mut thread_rng()), } @@ -150,6 +150,7 @@ pub fn select_coins( pub fn select_coins_bnb( target: Amount, cost_of_change: Amount, + _fee_rate: FeeRate, mut weighted_utxos: Vec, ) -> Option> { // Total_Tries in Core: @@ -320,11 +321,9 @@ mod tests { use bitcoin::Weight; use core::str::FromStr; - const SATISFACTION_SIZE: Weight = Weight::from_wu(204); - fn create_weighted_utxos() -> Vec { let utxo_one = WeightedUtxo { - satisfaction_weight: SATISFACTION_SIZE, + satisfaction_weight: Weight::ZERO, utxo: TxOut { value: Amount::from_str("1 cBTC").unwrap(), script_pubkey: ScriptBuf::new(), @@ -332,7 +331,7 @@ mod tests { }; let utxo_two = WeightedUtxo { - satisfaction_weight: SATISFACTION_SIZE, + satisfaction_weight: Weight::ZERO, utxo: TxOut { value: Amount::from_str("2 cBTC").unwrap(), script_pubkey: ScriptBuf::new(), @@ -340,7 +339,7 @@ mod tests { }; let utxo_three = WeightedUtxo { - satisfaction_weight: SATISFACTION_SIZE, + satisfaction_weight: Weight::ZERO, utxo: TxOut { value: Amount::from_str("3 cBTC").unwrap(), script_pubkey: ScriptBuf::new(), @@ -348,7 +347,7 @@ mod tests { }; let utxo_four = WeightedUtxo { - satisfaction_weight: SATISFACTION_SIZE, + satisfaction_weight: Weight::ZERO, utxo: TxOut { value: Amount::from_str("4 cBTC").unwrap(), script_pubkey: ScriptBuf::new(), @@ -363,14 +362,15 @@ mod tests { let target = Amount::from_str("1 cBTC").unwrap(); let weighted_utxos = vec![WeightedUtxo { - satisfaction_weight: SATISFACTION_SIZE, + satisfaction_weight: Weight::ZERO, utxo: TxOut { value: Amount::from_str("1 cBTC").unwrap(), script_pubkey: ScriptBuf::new(), }, }]; - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![0]; assert_eq!(index_list, expected_index_list); } @@ -381,14 +381,14 @@ mod tests { let weighted_utxos = vec![ WeightedUtxo { - satisfaction_weight: SATISFACTION_SIZE, + satisfaction_weight: Weight::ZERO, utxo: TxOut { value: Amount::from_str("4 cBTC").unwrap(), script_pubkey: ScriptBuf::new(), }, }, WeightedUtxo { - satisfaction_weight: SATISFACTION_SIZE, + satisfaction_weight: Weight::ZERO, utxo: TxOut { value: Amount::from_str("3 cBTC").unwrap(), script_pubkey: ScriptBuf::new(), @@ -396,7 +396,8 @@ mod tests { }, ]; - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![0]; assert_eq!(index_list, expected_index_list); } @@ -407,14 +408,14 @@ mod tests { let weighted_utxos = vec![ WeightedUtxo { - satisfaction_weight: SATISFACTION_SIZE, + satisfaction_weight: Weight::ZERO, utxo: TxOut { value: Amount::from_str("4 cBTC").unwrap(), script_pubkey: ScriptBuf::new(), }, }, WeightedUtxo { - satisfaction_weight: SATISFACTION_SIZE, + satisfaction_weight: Weight::ZERO, utxo: TxOut { value: Amount::from_str("3 cBTC").unwrap(), script_pubkey: ScriptBuf::new(), @@ -422,7 +423,8 @@ mod tests { }, ]; - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![0, 1]; assert_eq!(index_list, expected_index_list); } @@ -431,7 +433,8 @@ mod tests { fn one() { let target = Amount::from_str("1 cBTC").unwrap(); let weighted_utxos = create_weighted_utxos(); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![3]; assert_eq!(index_list, expected_index_list); } @@ -440,7 +443,8 @@ mod tests { fn two() { let target = Amount::from_str("2 cBTC").unwrap(); let weighted_utxos = create_weighted_utxos(); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![2]; assert_eq!(index_list, expected_index_list); } @@ -449,7 +453,8 @@ mod tests { fn three() { let target = Amount::from_str("3 cBTC").unwrap(); let weighted_utxos = create_weighted_utxos(); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![2, 3]; assert_eq!(index_list, expected_index_list); } @@ -458,7 +463,8 @@ mod tests { fn four() { let target = Amount::from_str("4 cBTC").unwrap(); let weighted_utxos = create_weighted_utxos(); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![1, 3]; assert_eq!(index_list, expected_index_list); } @@ -467,7 +473,8 @@ mod tests { fn five() { let target = Amount::from_str("5 cBTC").unwrap(); let weighted_utxos = create_weighted_utxos(); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![1, 2]; assert_eq!(index_list, expected_index_list); } @@ -476,7 +483,8 @@ mod tests { fn six() { let target = Amount::from_str("6 cBTC").unwrap(); let weighted_utxos = create_weighted_utxos(); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![1, 2, 3]; assert_eq!(index_list, expected_index_list); } @@ -485,7 +493,8 @@ mod tests { fn seven() { let target = Amount::from_str("7 cBTC").unwrap(); let weighted_utxos = create_weighted_utxos(); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![0, 2, 3]; assert_eq!(index_list, expected_index_list); } @@ -494,7 +503,8 @@ mod tests { fn eight() { let target = Amount::from_str("8 cBTC").unwrap(); let weighted_utxos = create_weighted_utxos(); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![0, 1, 3]; assert_eq!(index_list, expected_index_list); } @@ -503,7 +513,8 @@ mod tests { fn nine() { let target = Amount::from_str("9 cBTC").unwrap(); let weighted_utxos = create_weighted_utxos(); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![0, 1, 2]; assert_eq!(index_list, expected_index_list); } @@ -512,7 +523,8 @@ mod tests { fn ten() { let target = Amount::from_str("10 cBTC").unwrap(); let weighted_utxos = create_weighted_utxos(); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); let expected_index_list = vec![0, 1, 2, 3]; assert_eq!(index_list, expected_index_list); } @@ -526,18 +538,21 @@ mod tests { let cost_of_change = target; let weighted_utxos = vec![WeightedUtxo { - satisfaction_weight: SATISFACTION_SIZE, + satisfaction_weight: Weight::ZERO, utxo: TxOut { value: Amount::from_str("1.5 cBTC").unwrap(), script_pubkey: ScriptBuf::new(), }, }]; - let index_list = select_coins_bnb(target, cost_of_change, weighted_utxos.clone()).unwrap(); + let index_list = + select_coins_bnb(target, cost_of_change, FeeRate::ZERO, weighted_utxos.clone()) + .unwrap(); let expected_index_list = vec![0]; assert_eq!(index_list, expected_index_list); - let index_list = select_coins_bnb(target, Amount::ZERO, weighted_utxos).unwrap(); + let index_list = + select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, weighted_utxos).unwrap(); assert_eq!(index_list, vec![]); } }