Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 057602b

Browse files
authored
Publish v0.1.1 post-updates and cleanup (#111)
* Publish v0.1.1 for updates and cleanup * Pushed changes to tests Signed-off-by: neoz666 <neoz.blockchain@gmail.com> * Pushed updates to version Signed-off-by: neoz666 <neoz.blockchain@gmail.com> --------- Signed-off-by: neoz666 <neoz.blockchain@gmail.com>
1 parent 56fe864 commit 057602b

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust-coinselect"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
description = "A blockchain-agnostic coin selection library built in Rust."
66
readme = "README.md"

examples/bitcoin_crate/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "coinselect-example-bitcoin"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55

66
[dependencies]

src/types.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,18 @@ pub struct CoinSelectionOpt {
6969
/// Strategy to decide what to do with the excess amount.
7070
#[derive(Clone, Debug, PartialEq, Eq)]
7171
pub enum ExcessStrategy {
72+
/// Adds the excess amount to the transaction fee. This increases the fee rate
73+
/// and may lead to faster confirmation, but wastes the excess amount.
7274
ToFee,
75+
76+
/// Adds the excess amount to the recipient's output. This avoids creating a change
77+
/// output and reduces transaction size, but may reveal information about the
78+
/// wallet's available UTXOs.
7379
ToRecipient,
80+
81+
/// Creates a change output with the excess amount. This preserves privacy and
82+
/// allows reuse of the excess amount in future transactions, but increases
83+
/// transaction size and creates dust UTXOs if the amount is too small.
7484
ToChange,
7585
}
7686

src/utils.rs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ pub fn calculate_accumulated_weight(
4949
accumulated_weight
5050
}
5151

52-
// #[inline]
53-
// pub fn calculate_fee(weight: u64, rate: f32) -> u64 {
54-
// (weight as f32 * rate).ceil() as u64
55-
// }
56-
5752
impl fmt::Display for SelectionError {
5853
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5954
match self {
@@ -124,6 +119,15 @@ mod tests {
124119
}
125120
}
126121

122+
/// Tests the fee calculation function with various input scenarios.
123+
/// Fee calculation is critical for coin selection as it determines the effective value
124+
/// of each UTXO after accounting for the cost to spend it.
125+
///
126+
/// Test vectors cover:
127+
/// - Normal fee calculation with positive rate
128+
/// - Error case with negative fee rate
129+
/// - Error case with abnormally high fee rate (>1000 sat/vB)
130+
/// - Edge case with zero fee rate
127131
#[test]
128132
fn test_calculate_fee() {
129133
struct TestVector {
@@ -169,6 +173,19 @@ mod tests {
169173
}
170174
}
171175

176+
/// Tests the effective value calculation which determines the actual spendable amount
177+
/// of a UTXO after subtracting the fee required to spend it.
178+
///
179+
/// Effective value is crucial for coin selection as it helps:
180+
/// - Avoid selecting UTXOs that cost more in fees than their value
181+
/// - Compare UTXOs based on their true spendable amount
182+
/// - Calculate the actual amount available for spending
183+
///
184+
/// Test vectors cover:
185+
/// - Edge case where fees exceed UTXO value
186+
/// - Normal case with positive effective value
187+
/// - Error cases with invalid fee rates
188+
/// - Large value UTXO calculations
172189
#[test]
173190
fn test_effective_value() {
174191
struct TestVector {
@@ -249,6 +266,19 @@ mod tests {
249266
}
250267
}
251268

269+
/// Tests the waste metric calculation which helps optimize coin selection.
270+
/// Waste represents the cost of creating a change output plus any excess amount
271+
/// that goes to fees or is added to recipient outputs.
272+
///
273+
/// The waste metric considers:
274+
/// - Long-term vs current fee rates
275+
/// - Cost of creating change outputs
276+
/// - Excess amounts based on selected strategy (fee/change/recipient)
277+
///
278+
/// Test vectors cover:
279+
/// - Change output creation (ToChange strategy)
280+
/// - Fee payment (ToFee strategy)
281+
/// - Insufficient funds scenario
252282
#[test]
253283
fn test_calculate_waste() {
254284
struct TestVector {
@@ -261,15 +291,15 @@ mod tests {
261291

262292
let options = setup_options(100).clone();
263293
let test_vectors = [
264-
// Test for excess srategy to drain(change output)
294+
// Test for excess strategy to drain(change output)
265295
TestVector {
266296
options: options.clone(),
267297
accumulated_value: 1000,
268298
accumulated_weight: 50,
269299
estimated_fee: 20,
270300
result: options.change_cost,
271301
},
272-
// Test for excess srategy to miners
302+
// Test for excess strategy to miners
273303
TestVector {
274304
options: CoinSelectionOpt {
275305
excess_strategy: ExcessStrategy::ToFee,

0 commit comments

Comments
 (0)