Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
coinselection.h
Go to the documentation of this file.
1// Copyright (c) 2017 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_WALLET_COINSELECTION_H
6#define BITCOIN_WALLET_COINSELECTION_H
7
8#include <consensus/amount.h>
10#include <random.h>
11
13static constexpr Amount MIN_CHANGE{COIN / 100};
16
18public:
19 CInputCoin(const CTransactionRef &tx, unsigned int i) {
20 if (!tx) {
21 throw std::invalid_argument("tx should not be null");
22 }
23 if (i >= tx->vout.size()) {
24 throw std::out_of_range("The output index is out of range");
25 }
26
27 outpoint = COutPoint(tx->GetId(), i);
28 txout = tx->vout[i];
30 }
31
32 CInputCoin(const CTransactionRef &tx, unsigned int i, int input_bytes)
33 : CInputCoin(tx, i) {
35 }
36
42
48
49 bool operator<(const CInputCoin &rhs) const {
50 return outpoint < rhs.outpoint;
51 }
52
53 bool operator!=(const CInputCoin &rhs) const {
54 return outpoint != rhs.outpoint;
55 }
56
57 bool operator==(const CInputCoin &rhs) const {
58 return outpoint == rhs.outpoint;
59 }
60};
61
80
103
104bool SelectCoinsBnB(std::vector<OutputGroup> &utxo_pool,
106 std::set<CInputCoin> &out_set, Amount &value_ret,
107 const Amount not_input_fees);
108
109// Original coin selection algorithm as a fallback
110bool KnapsackSolver(const Amount nTargetValue, std::vector<OutputGroup> &groups,
111 std::set<CInputCoin> &setCoinsRet, Amount &nValueRet);
112
113#endif // BITCOIN_WALLET_COINSELECTION_H
static constexpr Amount COIN
Definition amount.h:144
Fee rate in satoshis per kilobyte: Amount / kB.
Definition feerate.h:21
int m_input_bytes
Pre-computed estimated size of this output as a fully-signed input in a transaction.
bool operator==(const CInputCoin &rhs) const
CInputCoin(const CTransactionRef &tx, unsigned int i)
Amount m_long_term_fee
CInputCoin(const CTransactionRef &tx, unsigned int i, int input_bytes)
Amount effective_value
bool operator!=(const CInputCoin &rhs) const
bool operator<(const CInputCoin &rhs) const
COutPoint outpoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition transaction.h:20
An output of a transaction.
Amount nValue
static constexpr Amount MIN_CHANGE
target minimum change amount
static const Amount MIN_FINAL_CHANGE
final minimum change amount after paying for fees
bool KnapsackSolver(const Amount nTargetValue, std::vector< OutputGroup > &groups, std::set< CInputCoin > &setCoinsRet, Amount &nValueRet)
bool SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const Amount &target_value, const Amount &cost_of_change, std::set< CInputCoin > &out_set, Amount &value_ret, const Amount not_input_fees)
This is the Branch and Bound Coin Selection algorithm designed by Murch.
std::shared_ptr< const CTransaction > CTransactionRef
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
static constexpr Amount zero() noexcept
Definition amount.h:32
CoinEligibilityFilter(int conf_mine_, int conf_theirs_, bool include_partial_groups)
const int conf_theirs
Minimum number of confirmations for outputs received from a different wallet.
CoinEligibilityFilter(int conf_mine_, int conf_theirs_)
const bool m_include_partial_groups
Include partial destination groups when avoid_reuse and there are full groups.
std::vector< CInputCoin > m_outputs
CFeeRate m_long_term_feerate
Amount long_term_fee
CFeeRate m_effective_feerate
void Insert(const CInputCoin &output, int depth, bool from_me, bool positive_only)
OutputGroup(const CFeeRate &effective_feerate, const CFeeRate &long_term_feerate)
Amount effective_value
bool EligibleForSpending(const CoinEligibilityFilter &eligibility_filter) const