Bitcoin Core 22.99.0
P2P Digital Currency
Functions | Variables
spend.cpp File Reference
#include <consensus/amount.h>
#include <consensus/validation.h>
#include <interfaces/chain.h>
#include <policy/policy.h>
#include <script/signingprovider.h>
#include <util/check.h>
#include <util/fees.h>
#include <util/moneystr.h>
#include <util/rbf.h>
#include <util/translation.h>
#include <wallet/coincontrol.h>
#include <wallet/fees.h>
#include <wallet/receive.h>
#include <wallet/spend.h>
#include <wallet/transaction.h>
#include <wallet/wallet.h>
Include dependency graph for spend.cpp:

Go to the source code of this file.

Functions

int GetTxSpendSize (const CWallet &wallet, const CWalletTx &wtx, unsigned int out, bool use_max_sig)
 Get the marginal bytes if spending the specified output from this transaction. More...
 
int CalculateMaximumSignedInputSize (const CTxOut &txout, const SigningProvider *provider, bool use_max_sig)
 
int CalculateMaximumSignedInputSize (const CTxOut &txout, const CWallet *wallet, bool use_max_sig)
 
TxSize CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, const std::vector< CTxOut > &txouts, const CCoinControl *coin_control)
 Calculate the size of the transaction assuming all signatures are max size Use DummySignatureCreator, which inserts 71 byte signatures everywhere. More...
 
TxSize CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, const CCoinControl *coin_control)
 
void AvailableCoins (const CWallet &wallet, std::vector< COutput > &vCoins, const CCoinControl *coinControl, const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount)
 populate vCoins with vector of available COutputs. More...
 
CAmount GetAvailableBalance (const CWallet &wallet, const CCoinControl *coinControl)
 
const CTxOut & FindNonChangeParentOutput (const CWallet &wallet, const CTransaction &tx, int output)
 Find non-change parent output. More...
 
std::map< CTxDestination, std::vector< COutput > > ListCoins (const CWallet &wallet)
 Return list of available coins and locked coins grouped by non-change output address. More...
 
std::vector< OutputGroup > GroupOutputs (const CWallet &wallet, const std::vector< COutput > &outputs, const CoinSelectionParams &coin_sel_params, const CoinEligibilityFilter &filter, bool positive_only)
 
bool AttemptSelection (const CWallet &wallet, const CAmount &nTargetValue, const CoinEligibilityFilter &eligibility_filter, std::vector< COutput > coins, std::set< CInputCoin > &setCoinsRet, CAmount &nValueRet, const CoinSelectionParams &coin_selection_params)
 Shuffle and select coins until nTargetValue is reached while avoiding small change; This method is stochastic for some inputs and upon completion the coin set and corresponding actual target value is assembled param@[in] coins Set of UTXOs to consider. More...
 
bool SelectCoins (const CWallet &wallet, const std::vector< COutput > &vAvailableCoins, const CAmount &nTargetValue, std::set< CInputCoin > &setCoinsRet, CAmount &nValueRet, const CCoinControl &coin_control, CoinSelectionParams &coin_selection_params)
 Select a set of coins such that nValueRet >= nTargetValue and at least all coins from coin_control are selected; never select unconfirmed coins if they are not ours param@[out] setCoinsRet Populated with inputs including pre-selected inputs from coin_control and Coin Selection if successful. More...
 
static bool IsCurrentForAntiFeeSniping (interfaces::Chain &chain, const uint256 &block_hash)
 
static uint32_t GetLocktimeForNewTransaction (interfaces::Chain &chain, const uint256 &block_hash, int block_height)
 Return a height-based locktime for new transactions (uses the height of the current chain tip unless we are not synced with the current chain. More...
 
static bool CreateTransactionInternal (CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, FeeCalculation &fee_calc_out, bool sign) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
 
bool CreateTransaction (CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, FeeCalculation &fee_calc_out, bool sign)
 Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also create the change output, when needed. More...
 
bool FundTransaction (CWallet &wallet, CMutableTransaction &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, bool lockUnspents, const std::set< int > &setSubtractFeeFromOutputs, CCoinControl coinControl)
 Insert additional inputs into the transaction by calling CreateTransaction();. More...
 

Variables

static constexpr size_t OUTPUT_GROUP_MAX_ENTRIES {100}
 

Function Documentation

◆ AttemptSelection()

bool AttemptSelection ( const CWallet &  wallet,
const CAmount &  nTargetValue,
const CoinEligibilityFilter &  eligibility_filter,
std::vector< COutput >  coins,
std::set< CInputCoin > &  setCoinsRet,
CAmount &  nValueRet,
const CoinSelectionParams &  coin_selection_params 
)

Shuffle and select coins until nTargetValue is reached while avoiding small change; This method is stochastic for some inputs and upon completion the coin set and corresponding actual target value is assembled param@[in] coins Set of UTXOs to consider.

These will be categorized into OutputGroups and filtered using eligibility_filter before selecting coins. param@[out] setCoinsRet Populated with the coins selected if successful. param@[out] nValueRet Used to return the total value of selected coins.

Definition at line 376 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AvailableCoins()

void AvailableCoins ( const CWallet &  wallet,
std::vector< COutput > &  vCoins,
const CCoinControl *  coinControl,
const CAmount &  nMinimumAmount,
const CAmount &  nMaximumAmount,
const CAmount &  nMinimumSumAmount,
const uint64_t  nMaximumCount 
)

populate vCoins with vector of available COutputs.

Definition at line 88 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalculateMaximumSignedInputSize() [1/2]

int CalculateMaximumSignedInputSize ( const CTxOut &  txout,
const CWallet *  wallet,
bool  use_max_sig 
)

Definition at line 46 of file spend.cpp.

Here is the call graph for this function:

◆ CalculateMaximumSignedInputSize() [2/2]

int CalculateMaximumSignedInputSize ( const CTxOut &  txout,
const SigningProvider *  provider,
bool  use_max_sig 
)

Definition at line 36 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalculateMaximumSignedTxSize() [1/2]

TxSize CalculateMaximumSignedTxSize ( const CTransaction &  tx,
const CWallet *  wallet,
const CCoinControl *  coin_control 
)

Definition at line 65 of file spend.cpp.

Here is the call graph for this function:

◆ CalculateMaximumSignedTxSize() [2/2]

TxSize CalculateMaximumSignedTxSize ( const CTransaction &  tx,
const CWallet *  wallet,
const std::vector< CTxOut > &  txouts,
const CCoinControl *  coin_control = nullptr 
)

Calculate the size of the transaction assuming all signatures are max size Use DummySignatureCreator, which inserts 71 byte signatures everywhere.

NOTE: this requires that all inputs must be in mapWallet (eg the tx should be AllInputsMine).

Definition at line 53 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateTransaction()

bool CreateTransaction ( CWallet &  wallet,
const std::vector< CRecipient > &  vecSend,
CTransactionRef &  tx,
CAmount &  nFeeRet,
int &  nChangePosInOut,
bilingual_str &  error,
const CCoinControl &  coin_control,
FeeCalculation &  fee_calc_out,
bool  sign = true 
)

Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also create the change output, when needed.

Note
passing nChangePosInOut as -1 will result in setting a random position

Definition at line 941 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateTransactionInternal()

static bool CreateTransactionInternal ( CWallet &  wallet,
const std::vector< CRecipient > &  vecSend,
CTransactionRef &  tx,
CAmount &  nFeeRet,
int &  nChangePosInOut,
bilingual_str &  error,
const CCoinControl &  coin_control,
FeeCalculation &  fee_calc_out,
bool  sign 
)
static

Definition at line 636 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindNonChangeParentOutput()

const CTxOut & FindNonChangeParentOutput ( const CWallet &  wallet,
const CTransaction &  tx,
int  output 
)

Find non-change parent output.

Definition at line 231 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FundTransaction()

bool FundTransaction ( CWallet &  wallet,
CMutableTransaction &  tx,
CAmount &  nFeeRet,
int &  nChangePosInOut,
bilingual_str &  error,
bool  lockUnspents,
const std::set< int > &  setSubtractFeeFromOutputs,
CCoinControl  coinControl 
)

Insert additional inputs into the transaction by calling CreateTransaction();.

Definition at line 989 of file spend.cpp.

Here is the call graph for this function:

◆ GetAvailableBalance()

CAmount GetAvailableBalance ( const CWallet &  wallet,
const CCoinControl *  coinControl 
)

Definition at line 216 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLocktimeForNewTransaction()

static uint32_t GetLocktimeForNewTransaction ( interfaces::Chain &  chain,
const uint256 &  block_hash,
int  block_height 
)
static

Return a height-based locktime for new transactions (uses the height of the current chain tip unless we are not synced with the current chain.

Definition at line 594 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTxSpendSize()

int GetTxSpendSize ( const CWallet &  wallet,
const CWalletTx &  wtx,
unsigned int  out,
bool  use_max_sig 
)

Get the marginal bytes if spending the specified output from this transaction.

Definition at line 26 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GroupOutputs()

std::vector< OutputGroup > GroupOutputs ( const CWallet &  wallet,
const std::vector< COutput > &  outputs,
const CoinSelectionParams &  coin_sel_params,
const CoinEligibilityFilter &  filter,
bool  positive_only 
)

Definition at line 290 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsCurrentForAntiFeeSniping()

static bool IsCurrentForAntiFeeSniping ( interfaces::Chain &  chain,
const uint256 &  block_hash 
)
static

Definition at line 576 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ListCoins()

std::map< CTxDestination, std::vector< COutput > > ListCoins ( const CWallet &  wallet)

Return list of available coins and locked coins grouped by non-change output address.

Definition at line 249 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SelectCoins()

bool SelectCoins ( const CWallet &  wallet,
const std::vector< COutput > &  vAvailableCoins,
const CAmount &  nTargetValue,
std::set< CInputCoin > &  setCoinsRet,
CAmount &  nValueRet,
const CCoinControl &  coin_control,
CoinSelectionParams &  coin_selection_params 
)

Select a set of coins such that nValueRet >= nTargetValue and at least all coins from coin_control are selected; never select unconfirmed coins if they are not ours param@[out] setCoinsRet Populated with inputs including pre-selected inputs from coin_control and Coin Selection if successful.

param@[out] nValueRet Total value of selected coins including pre-selected ones from coin_control and Coin Selection if successful.

Definition at line 430 of file spend.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ OUTPUT_GROUP_MAX_ENTRIES

constexpr size_t OUTPUT_GROUP_MAX_ENTRIES {100}
staticconstexpr

Definition at line 24 of file spend.cpp.