1 <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Trait for generalized coin selection algorithms"><meta name="keywords" content="rust, rustlang, rust-lang, CoinSelectionAlgorithm"><title>CoinSelectionAlgorithm in bdk::wallet::coin_selection - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script src="../../../crates.js"></script><script defer src="../../../main.js"></script>
2 <noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../../../bdk/index.html"><div class="logo-container"><img src="https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png" alt="logo"></div>
3 </a><h2 class="location"></h2>
5 <nav class="sidebar"><a class="sidebar-logo" href="../../../bdk/index.html"><div class="logo-container">
6 <img src="https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png" alt="logo"></div>
7 </a><h2 class="location"><a href="#">CoinSelectionAlgorithm</a></h2><div class="sidebar-elems"><div class="block items"><h3 class="sidebar-title"><a href="#required-methods">Required Methods</a></h3><div class="sidebar-links"><a href="#tymethod.coin_select">coin_select</a></div><h3 class="sidebar-title"><a href="#implementors">Implementors</a></h3></div><h2 class="location">In <a href="../../index.html">bdk</a>::<wbr><a href="../index.html">wallet</a>::<wbr><a href="index.html">coin_selection</a></h2><div id="sidebar-vars" data-name="CoinSelectionAlgorithm" data-ty="trait" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../bdk/index.html">
8 <img src="https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png" alt="logo"></a><nav class="sub"><div class="theme-picker hidden"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="22" height="22" alt="Pick another theme!" src="../../../brush.svg"></button><div id="theme-choices" role="menu"></div></div><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
9 <h1 class="fqn"><span class="in-band">Trait <a href="../../index.html">bdk</a>::<wbr><a href="../index.html">wallet</a>::<wbr><a href="index.html">coin_selection</a>::<wbr><a class="trait" href="#">CoinSelectionAlgorithm</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../../src/bdk/wallet/coin_selection.rs.html#146-168" title="goto source code">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="docblock item-decl"><pre class="rust trait"><code>pub trait CoinSelectionAlgorithm<D: <a class="trait" href="../../database/trait.Database.html" title="trait bdk::database::Database">Database</a>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> {
10 fn <a href="#tymethod.coin_select" class="fnname">coin_select</a>(<br> &self, <br> database: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>D, <br> required_utxos: <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="../../struct.WeightedUtxo.html" title="struct bdk::WeightedUtxo">WeightedUtxo</a>>, <br> optional_utxos: <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="../../struct.WeightedUtxo.html" title="struct bdk::WeightedUtxo">WeightedUtxo</a>>, <br> fee_rate: <a class="struct" href="../../struct.FeeRate.html" title="struct bdk::FeeRate">FeeRate</a>, <br> amount_needed: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>, <br> fee_amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a><br> ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.CoinSelectionResult.html" title="struct bdk::wallet::coin_selection::CoinSelectionResult">CoinSelectionResult</a>, <a class="enum" href="../../enum.Error.html" title="enum bdk::Error">Error</a>>;
11 }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Trait for generalized coin selection algorithms</p>
12 <p>This trait can be implemented to make the <a href="../struct.Wallet.html"><code>Wallet</code></a> use a customized coin
13 selection algorithm when it creates transactions.</p>
14 <p>For an example see <a href="index.html">this module</a>’s documentation.</p>
15 </div></details><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle" open><summary><div id="tymethod.coin_select" class="method has-srclink"><div class="rightside"><a class="srclink" href="../../../src/bdk/wallet/coin_selection.rs.html#159-167" title="goto source code">source</a></div><h4 class="code-header">fn <a href="#tymethod.coin_select" class="fnname">coin_select</a>(<br> &self, <br> database: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>D, <br> required_utxos: <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="../../struct.WeightedUtxo.html" title="struct bdk::WeightedUtxo">WeightedUtxo</a>>, <br> optional_utxos: <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="../../struct.WeightedUtxo.html" title="struct bdk::WeightedUtxo">WeightedUtxo</a>>, <br> fee_rate: <a class="struct" href="../../struct.FeeRate.html" title="struct bdk::FeeRate">FeeRate</a>, <br> amount_needed: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>, <br> fee_amount: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a><br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.CoinSelectionResult.html" title="struct bdk::wallet::coin_selection::CoinSelectionResult">CoinSelectionResult</a>, <a class="enum" href="../../enum.Error.html" title="enum bdk::Error">Error</a>></h4></div></summary><div class="docblock"><p>Perform the coin selection</p>
17 <li><code>database</code>: a reference to the wallet’s database that can be used to lookup additional
18 details for a specific UTXO</li>
19 <li><code>required_utxos</code>: the utxos that must be spent regardless of <code>amount_needed</code> with their
21 <li><code>optional_utxos</code>: the remaining available utxos to satisfy <code>amount_needed</code> with their
23 <li><code>fee_rate</code>: fee rate to use</li>
24 <li><code>amount_needed</code>: the amount in satoshi to select</li>
25 <li><code>fee_amount</code>: the amount of fees in satoshi already accumulated from adding outputs and
26 the transaction’s header</li>
28 </div></details></div><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><div id="impl-CoinSelectionAlgorithm%3CD%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../../src/bdk/wallet/coin_selection.rs.html#293-371" title="goto source code">source</a></div><a href="#impl-CoinSelectionAlgorithm%3CD%3E" class="anchor"></a><h3 class="code-header in-band">impl<D: <a class="trait" href="../../database/trait.Database.html" title="trait bdk::database::Database">Database</a>> <a class="trait" href="trait.CoinSelectionAlgorithm.html" title="trait bdk::wallet::coin_selection::CoinSelectionAlgorithm">CoinSelectionAlgorithm</a><D> for <a class="struct" href="struct.BranchAndBoundCoinSelection.html" title="struct bdk::wallet::coin_selection::BranchAndBoundCoinSelection">BranchAndBoundCoinSelection</a></h3></div><div id="impl-CoinSelectionAlgorithm%3CD%3E-1" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../../src/bdk/wallet/coin_selection.rs.html#177-243" title="goto source code">source</a></div><a href="#impl-CoinSelectionAlgorithm%3CD%3E-1" class="anchor"></a><h3 class="code-header in-band">impl<D: <a class="trait" href="../../database/trait.Database.html" title="trait bdk::database::Database">Database</a>> <a class="trait" href="trait.CoinSelectionAlgorithm.html" title="trait bdk::wallet::coin_selection::CoinSelectionAlgorithm">CoinSelectionAlgorithm</a><D> for <a class="struct" href="struct.LargestFirstCoinSelection.html" title="struct bdk::wallet::coin_selection::LargestFirstCoinSelection">LargestFirstCoinSelection</a></h3></div></div><script type="text/javascript" src="../../../implementors/bdk/wallet/coin_selection/trait.CoinSelectionAlgorithm.js" async></script></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="bdk" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.60.0-nightly (51126be1b 2022-01-24)" ></div>