Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/coinselection.h
// Copyright (c) 2017 The Bitcoin Core developers | // Copyright (c) 2017 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_WALLET_COINSELECTION_H | #ifndef BITCOIN_WALLET_COINSELECTION_H | ||||
#define BITCOIN_WALLET_COINSELECTION_H | #define BITCOIN_WALLET_COINSELECTION_H | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <random.h> | #include <random.h> | ||||
class CFeeRate; | |||||
//! target minimum change amount | //! target minimum change amount | ||||
static constexpr Amount MIN_CHANGE{COIN / 100}; | static constexpr Amount MIN_CHANGE{COIN / 100}; | ||||
//! final minimum change amount after paying for fees | //! final minimum change amount after paying for fees | ||||
static const Amount MIN_FINAL_CHANGE = MIN_CHANGE / 2; | static const Amount MIN_FINAL_CHANGE = MIN_CHANGE / 2; | ||||
class CInputCoin { | class CInputCoin { | ||||
public: | public: | ||||
CInputCoin(const CTransactionRef &tx, unsigned int i) { | CInputCoin(const CTransactionRef &tx, unsigned int i) { | ||||
Show All 12 Lines | public: | ||||
CInputCoin(const CTransactionRef &tx, unsigned int i, int input_bytes) | CInputCoin(const CTransactionRef &tx, unsigned int i, int input_bytes) | ||||
: CInputCoin(tx, i) { | : CInputCoin(tx, i) { | ||||
m_input_bytes = input_bytes; | m_input_bytes = input_bytes; | ||||
} | } | ||||
COutPoint outpoint; | COutPoint outpoint; | ||||
CTxOut txout; | CTxOut txout; | ||||
Amount effective_value; | Amount effective_value; | ||||
Amount m_fee{Amount::zero()}; | |||||
Amount m_long_term_fee{Amount::zero()}; | |||||
/** | /** | ||||
* Pre-computed estimated size of this output as a fully-signed input in a | * Pre-computed estimated size of this output as a fully-signed input in a | ||||
* transaction. Can be -1 if it could not be calculated. | * transaction. Can be -1 if it could not be calculated. | ||||
*/ | */ | ||||
int m_input_bytes{-1}; | int m_input_bytes{-1}; | ||||
bool operator<(const CInputCoin &rhs) const { | bool operator<(const CInputCoin &rhs) const { | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | OutputGroup(const CInputCoin &output, int depth, bool from_me, | ||||
: OutputGroup() { | : OutputGroup() { | ||||
Insert(output, depth, from_me, ancestors, descendants); | Insert(output, depth, from_me, ancestors, descendants); | ||||
} | } | ||||
void Insert(const CInputCoin &output, int depth, bool from_me, | void Insert(const CInputCoin &output, int depth, bool from_me, | ||||
size_t ancestors, size_t descendants); | size_t ancestors, size_t descendants); | ||||
std::vector<CInputCoin>::iterator Discard(const CInputCoin &output); | std::vector<CInputCoin>::iterator Discard(const CInputCoin &output); | ||||
bool | bool | ||||
EligibleForSpending(const CoinEligibilityFilter &eligibility_filter) const; | EligibleForSpending(const CoinEligibilityFilter &eligibility_filter) const; | ||||
//! Update the OutputGroup's fee, long_term_fee, and effective_value based | |||||
//! on the given feerates | |||||
void SetFees(const CFeeRate effective_feerate, | |||||
const CFeeRate long_term_feerate); | |||||
OutputGroup GetPositiveOnlyGroup(); | |||||
}; | }; | ||||
bool SelectCoinsBnB(std::vector<OutputGroup> &utxo_pool, | bool SelectCoinsBnB(std::vector<OutputGroup> &utxo_pool, | ||||
const Amount &target_value, const Amount &cost_of_change, | const Amount &target_value, const Amount &cost_of_change, | ||||
std::set<CInputCoin> &out_set, Amount &value_ret, | std::set<CInputCoin> &out_set, Amount &value_ret, | ||||
const Amount not_input_fees); | const Amount not_input_fees); | ||||
// Original coin selection algorithm as a fallback | // Original coin selection algorithm as a fallback | ||||
bool KnapsackSolver(const Amount nTargetValue, std::vector<OutputGroup> &groups, | bool KnapsackSolver(const Amount nTargetValue, std::vector<OutputGroup> &groups, | ||||
std::set<CInputCoin> &setCoinsRet, Amount &nValueRet); | std::set<CInputCoin> &setCoinsRet, Amount &nValueRet); | ||||
#endif // BITCOIN_WALLET_COINSELECTION_H | #endif // BITCOIN_WALLET_COINSELECTION_H |