Rename may_use_utxos to optional_uxtos
This commit is contained in:
parent
43a51a1ec3
commit
84aee3baab
@ -54,7 +54,7 @@
|
|||||||
//! &self,
|
//! &self,
|
||||||
//! database: &D,
|
//! database: &D,
|
||||||
//! required_utxos: Vec<(UTXO, usize)>,
|
//! required_utxos: Vec<(UTXO, usize)>,
|
||||||
//! may_use_utxos: Vec<(UTXO, usize)>,
|
//! optional_utxos: Vec<(UTXO, usize)>,
|
||||||
//! fee_rate: FeeRate,
|
//! fee_rate: FeeRate,
|
||||||
//! amount_needed: u64,
|
//! amount_needed: u64,
|
||||||
//! fee_amount: f32,
|
//! fee_amount: f32,
|
||||||
@ -62,7 +62,7 @@
|
|||||||
//! let mut selected_amount = 0;
|
//! let mut selected_amount = 0;
|
||||||
//! let mut additional_weight = 0;
|
//! let mut additional_weight = 0;
|
||||||
//! let all_utxos_selected = required_utxos
|
//! let all_utxos_selected = required_utxos
|
||||||
//! .into_iter().chain(may_use_utxos)
|
//! .into_iter().chain(optional_utxos)
|
||||||
//! .scan((&mut selected_amount, &mut additional_weight), |(selected_amount, additional_weight), (utxo, weight)| {
|
//! .scan((&mut selected_amount, &mut additional_weight), |(selected_amount, additional_weight), (utxo, weight)| {
|
||||||
//! let txin = TxIn {
|
//! let txin = TxIn {
|
||||||
//! previous_output: utxo.outpoint,
|
//! previous_output: utxo.outpoint,
|
||||||
@ -141,8 +141,8 @@ pub trait CoinSelectionAlgorithm<D: Database>: std::fmt::Debug {
|
|||||||
/// details for a specific UTXO
|
/// details for a specific UTXO
|
||||||
/// - `required_utxos`: the utxos that must be spent regardless of `amount_needed` with their
|
/// - `required_utxos`: the utxos that must be spent regardless of `amount_needed` with their
|
||||||
/// weight cost
|
/// weight cost
|
||||||
/// - `may_be_spent`: the utxos that may be spent to satisfy `amount_needed` with their weight
|
/// - `optional_utxos`: the remaining available utxos to satisfy `amount_needed` with their
|
||||||
/// cost
|
/// weight cost
|
||||||
/// - `fee_rate`: fee rate to use
|
/// - `fee_rate`: fee rate to use
|
||||||
/// - `amount_needed`: the amount in satoshi to select
|
/// - `amount_needed`: the amount in satoshi to select
|
||||||
/// - `fee_amount`: the amount of fees in satoshi already accumulated from adding outputs and
|
/// - `fee_amount`: the amount of fees in satoshi already accumulated from adding outputs and
|
||||||
@ -151,7 +151,7 @@ pub trait CoinSelectionAlgorithm<D: Database>: std::fmt::Debug {
|
|||||||
&self,
|
&self,
|
||||||
database: &D,
|
database: &D,
|
||||||
required_utxos: Vec<(UTXO, usize)>,
|
required_utxos: Vec<(UTXO, usize)>,
|
||||||
may_use_utxos: Vec<(UTXO, usize)>,
|
optional_utxos: Vec<(UTXO, usize)>,
|
||||||
fee_rate: FeeRate,
|
fee_rate: FeeRate,
|
||||||
amount_needed: u64,
|
amount_needed: u64,
|
||||||
fee_amount: f32,
|
fee_amount: f32,
|
||||||
@ -170,7 +170,7 @@ impl<D: Database> CoinSelectionAlgorithm<D> for DumbCoinSelection {
|
|||||||
&self,
|
&self,
|
||||||
_database: &D,
|
_database: &D,
|
||||||
required_utxos: Vec<(UTXO, usize)>,
|
required_utxos: Vec<(UTXO, usize)>,
|
||||||
mut may_use_utxos: Vec<(UTXO, usize)>,
|
mut optional_utxos: Vec<(UTXO, usize)>,
|
||||||
fee_rate: FeeRate,
|
fee_rate: FeeRate,
|
||||||
amount_needed: u64,
|
amount_needed: u64,
|
||||||
mut fee_amount: f32,
|
mut fee_amount: f32,
|
||||||
@ -184,14 +184,14 @@ impl<D: Database> CoinSelectionAlgorithm<D> for DumbCoinSelection {
|
|||||||
fee_rate
|
fee_rate
|
||||||
);
|
);
|
||||||
|
|
||||||
// We put the "must_use" UTXOs first and make sure the "may_use" are sorted, initially
|
// We put the "required UTXOs" first and make sure the optional UTXOs are sorted,
|
||||||
// smallest to largest, before being reversed with `.rev()`.
|
// initially smallest to largest, before being reversed with `.rev()`.
|
||||||
let utxos = {
|
let utxos = {
|
||||||
may_use_utxos.sort_unstable_by_key(|(utxo, _)| utxo.txout.value);
|
optional_utxos.sort_unstable_by_key(|(utxo, _)| utxo.txout.value);
|
||||||
required_utxos
|
required_utxos
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|utxo| (true, utxo))
|
.map(|utxo| (true, utxo))
|
||||||
.chain(may_use_utxos.into_iter().rev().map(|utxo| (false, utxo)))
|
.chain(optional_utxos.into_iter().rev().map(|utxo| (false, utxo)))
|
||||||
};
|
};
|
||||||
|
|
||||||
// Keep including inputs until we've got enough.
|
// Keep including inputs until we've got enough.
|
||||||
|
@ -348,7 +348,7 @@ where
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (required_utxos, may_use_utxos) = self.get_must_may_use_utxos(
|
let (required_utxos, optional_utxos) = self.get_must_may_use_utxos(
|
||||||
builder.change_policy,
|
builder.change_policy,
|
||||||
&builder.unspendable,
|
&builder.unspendable,
|
||||||
&builder.utxos,
|
&builder.utxos,
|
||||||
@ -364,7 +364,7 @@ where
|
|||||||
} = builder.coin_selection.coin_select(
|
} = builder.coin_selection.coin_select(
|
||||||
self.database.borrow().deref(),
|
self.database.borrow().deref(),
|
||||||
required_utxos,
|
required_utxos,
|
||||||
may_use_utxos,
|
optional_utxos,
|
||||||
fee_rate,
|
fee_rate,
|
||||||
outgoing,
|
outgoing,
|
||||||
fee_amount,
|
fee_amount,
|
||||||
@ -604,7 +604,7 @@ where
|
|||||||
.cloned()
|
.cloned()
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let (mut required_utxos, may_use_utxos) = self.get_must_may_use_utxos(
|
let (mut required_utxos, optional_utxos) = self.get_must_may_use_utxos(
|
||||||
builder.change_policy,
|
builder.change_policy,
|
||||||
&builder.unspendable,
|
&builder.unspendable,
|
||||||
&builder_extra_utxos[..],
|
&builder_extra_utxos[..],
|
||||||
@ -646,7 +646,7 @@ where
|
|||||||
} = builder.coin_selection.coin_select(
|
} = builder.coin_selection.coin_select(
|
||||||
self.database.borrow().deref(),
|
self.database.borrow().deref(),
|
||||||
required_utxos,
|
required_utxos,
|
||||||
may_use_utxos,
|
optional_utxos,
|
||||||
new_feerate,
|
new_feerate,
|
||||||
amount_needed,
|
amount_needed,
|
||||||
initial_fee,
|
initial_fee,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user