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

Commit d3e4f43

Browse files
authored
[enhancement] Readme inclusion, update and Docs.rs imp (#107)
Signed-off-by: neoz666 <neoz.blockchain@gmail.com>
1 parent 0c68071 commit d3e4f43

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

README.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,37 @@ Bitcoin specific example is given [here](./examples/bitcoin_crate/).
2121
An example usage is given below
2222

2323
```rust
24-
let utxos: Vec<UTXO> = vec![<utxo1>, <utxo2>, ..., <utxon>]; // List of the available UTXOs
25-
let output_groups: Vec<OutputGroup> = utxos.iter().map(|utxo| convert_utxo_to_output(utxo)).collect();
24+
use rust_coinselect::{
25+
types::{CoinSelectionOpt, ExcessStrategy, OutputGroup},
26+
selectcoin::select_coin,
27+
};
28+
29+
// List of the available UTXOs
30+
// let utxos: Vec<UTXO> = vec![<utxo1>, <utxo2>, ..., <utxon>];
31+
32+
let output_groups = vec![
33+
OutputGroup { value: 1_000_000, weight: 100, input_count: 1, creation_sequence: None },
34+
OutputGroup { value: 2_000_000, weight: 100, input_count: 1, creation_sequence: None },
35+
];
36+
2637
let options = CoinSelectionOpt {
27-
target_value: 4_000_000u64,
28-
target_fee_rate: 0.5f32,
38+
target_value: 1_500_000u64,
39+
target_feerate: 0.5f32,
2940
long_term_feerate: Some(0.3f32),
3041
min_absolute_fee: 1000u64,
3142
base_weight: 72u64,
3243
change_weight: 18u64,
3344
change_cost: 250u64,
34-
cost_per_input: 300u64,
35-
cost_per_output: 250u64,
45+
avg_input_weight: 300u64,
46+
avg_output_weight: 250u64,
3647
min_change_value: 1_000u64,
3748
excess_strategy: ExcessStrategy::ToChange,
3849
};
3950

40-
let selection_output = select_coin(&output_groups, options);
41-
println!("Estimated waste = {}", selection_output.waste);
42-
println!("Indexes of the selected utxos = {}", selection_output.selected_inputs);
51+
if let Ok(selection_output) = select_coin(&output_groups, &options) {
52+
println!("Indexes of the selected utxos = {:?}", selection_output.selected_inputs);
53+
}
4354

44-
let selected_utxos: Vec<UTXO> = selection_output.iter().map(|index| utxos[index]).collect();
4555
```
4656

4757
The `convert_utxo_to_output` logic should be implemented by the user for the respective blockchain protocol.

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
#![doc = include_str!("../README.md")]
2+
#![doc = include_str!("../README.md")]
3+
4+
/// Collection of coin selection algorithms including Knapsack, Branch and Bound (BNB), First-In First-Out (FIFO), Single-Random-Draw (SRD), and Lowest Larger
15
pub mod algorithms;
6+
/// Wrapper API that runs all coin selection algorithms in parallel and returns the result with lowest waste
27
pub mod selectcoin;
8+
/// Core types and structs used throughout the library including OutputGroup and CoinSelectionOpt
39
pub mod types;
10+
/// Helper functions with tests for fee calculation, weight computation, and waste metrics
411
pub mod utils;

0 commit comments

Comments
 (0)