bdk_wallet::coin_selection

Trait CoinSelectionAlgorithm

Source
pub trait CoinSelectionAlgorithm: Debug {
    // Required method
    fn coin_select<R: RngCore>(
        &self,
        required_utxos: Vec<WeightedUtxo>,
        optional_utxos: Vec<WeightedUtxo>,
        fee_rate: FeeRate,
        target_amount: Amount,
        drain_script: &Script,
        rand: &mut R,
    ) -> Result<CoinSelectionResult, InsufficientFunds>;
}
Expand description

Trait for generalized coin selection algorithms

This trait can be implemented to make the Wallet use a customized coin selection algorithm when it creates transactions.

For an example see this module’s documentation.

Required Methods§

Source

fn coin_select<R: RngCore>( &self, required_utxos: Vec<WeightedUtxo>, optional_utxos: Vec<WeightedUtxo>, fee_rate: FeeRate, target_amount: Amount, drain_script: &Script, rand: &mut R, ) -> Result<CoinSelectionResult, InsufficientFunds>

Perform the coin selection

  • required_utxos: the utxos that must be spent regardless of target_amount with their weight cost
  • optional_utxos: the remaining available utxos to satisfy target_amount with their weight cost
  • fee_rate: fee rate to use
  • target_amount: the outgoing amount and the fees already accumulated from adding outputs and transaction’s header.
  • drain_script: the script to use in case of change
  • rand: random number generated used by some coin selection algorithms such as SingleRandomDraw

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§