Bitcoin ABC  0.26.3
P2P Digital Currency
Go to the documentation of this file.
1 // Copyright (c) 2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or
8 #include <wallet/coinselection.h>
9 #include <wallet/transaction.h>
10 #include <wallet/wallet.h>
16 int GetTxSpendSize(const CWallet &wallet, const CWalletTx &wtx,
17  unsigned int out, bool use_max_sig = false);
19 class COutput {
20 public:
21  const CWalletTx *tx;
22  int i;
23  int nDepth;
32  bool fSpendable;
35  bool fSolvable;
49  bool fSafe;
51  COutput(const CWallet &wallet, const CWalletTx &wtx, int iIn, int nDepthIn,
52  bool fSpendableIn, bool fSolvableIn, bool fSafeIn,
53  bool use_max_sig_in = false) {
54  tx = &wtx;
55  i = iIn;
56  nDepth = nDepthIn;
57  fSpendable = fSpendableIn;
58  fSolvable = fSolvableIn;
59  fSafe = fSafeIn;
60  nInputBytes = -1;
61  use_max_sig = use_max_sig_in;
62  // If known and signable by the given wallet, compute nInputBytes
63  // Failure will keep this value -1
64  if (fSpendable) {
66  }
67  }
69  std::string ToString() const;
71  inline CInputCoin GetInputCoin() const {
72  return CInputCoin(tx->tx, i, nInputBytes);
73  }
74 };
77 int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *pwallet,
78  bool use_max_sig = false);
87  const CWallet *wallet,
88  const std::vector<CTxOut> &txouts,
89  bool use_max_sig = false);
91  const CWallet *wallet,
92  bool use_max_sig = false)
93  EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet);
98 void AvailableCoins(const CWallet &wallet, std::vector<COutput> &vCoins,
99  bool fOnlySafe = true,
100  const CCoinControl *coinControl = nullptr,
101  const Amount nMinimumAmount = SATOSHI,
102  const Amount nMaximumAmount = MAX_MONEY,
103  const Amount nMinimumSumAmount = MAX_MONEY,
104  const uint64_t nMaximumCount = 0)
105  EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
108  const CCoinControl *coinControl = nullptr);
114  const CTransaction &tx, int output)
115  EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
121 std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet &wallet)
122  EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
124 std::vector<OutputGroup> GroupOutputs(const CWallet &wallet,
125  const std::vector<COutput> &outputs,
126  bool single_coin,
127  const size_t max_ancestors);
141 bool SelectCoinsMinConf(const CWallet &wallet, const Amount nTargetValue,
142  const CoinEligibilityFilter &eligibility_filter,
143  std::vector<OutputGroup> groups,
144  std::set<CInputCoin> &setCoinsRet, Amount &nValueRet,
146  bool &bnb_used);
157 bool SelectCoins(const CWallet &wallet,
158  const std::vector<COutput> &vAvailableCoins,
159  const Amount nTargetValue, std::set<CInputCoin> &setCoinsRet,
160  Amount &nValueRet, const CCoinControl &coin_control,
162  EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
170 bool CreateTransaction(CWallet &wallet, const std::vector<CRecipient> &vecSend,
171  CTransactionRef &tx, Amount &nFeeRet,
172  int &nChangePosInOut, bilingual_str &error,
173  const CCoinControl &coin_control, bool sign = true);
180  int &nChangePosInOut, bilingual_str &error,
181  bool lockUnspents,
182  const std::set<int> &setSubtractFeeFromOutputs,
183  CCoinControl coinControl);
static constexpr Amount SATOSHI
Definition: amount.h:143
static constexpr Amount MAX_MONEY
No amount larger than this (in satoshi) is valid.
Definition: amount.h:165
Coin Control Features.
Definition: coincontrol.h:21
A mutable version of CTransaction.
Definition: transaction.h:280
Definition: spend.h:19
int nDepth
Definition: spend.h:23
bool fSafe
Whether this output is considered safe to spend.
Definition: spend.h:49
bool fSolvable
Whether we know how to spend this output, ignoring the lack of keys.
Definition: spend.h:35
int nInputBytes
Pre-computed estimated size of this output as a fully-signed input in a transaction.
Definition: spend.h:29
bool fSpendable
Whether we have the private keys to spend this output.
Definition: spend.h:32
const CWalletTx * tx
Definition: spend.h:21
CInputCoin GetInputCoin() const
Definition: spend.h:71
std::string ToString() const
Definition: spend.cpp:28
int i
Definition: spend.h:22
bool use_max_sig
Whether to use the maximum sized, 72 byte signature when calculating the size of the input spend.
Definition: spend.h:42
COutput(const CWallet &wallet, const CWalletTx &wtx, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn, bool use_max_sig_in=false)
Definition: spend.h:51
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:194
An output of a transaction.
Definition: transaction.h:130
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:251
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:65
CTransactionRef tx
Definition: transaction.h:160
static std::vector< COutput > vCoins
CoinSelectionParams coin_selection_params(false, 0, 0, CFeeRate(Amount::zero()), 0)
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:321
bool CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, Amount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, bool sign=true)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Definition: spend.cpp:954
const CTxOut & FindNonChangeParentOutput(const CWallet &wallet, const CTransaction &tx, int output) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
Find non-change parent output.
Definition: spend.cpp:227
bool SelectCoinsMinConf(const CWallet &wallet, const Amount nTargetValue, const CoinEligibilityFilter &eligibility_filter, std::vector< OutputGroup > groups, std::set< CInputCoin > &setCoinsRet, Amount &nValueRet, const CoinSelectionParams &coin_selection_params, bool &bnb_used)
Shuffle and select coins until nTargetValue is reached while avoiding small change; This method is st...
Definition: spend.cpp:368
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
Return list of available coins and locked coins grouped by non-change output address.
Definition: spend.cpp:247
Amount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl=nullptr)
Definition: spend.cpp:212
bool FundTransaction(CWallet &wallet, CMutableTransaction &tx, Amount &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: spend.cpp:993
bool SelectCoins(const CWallet &wallet, const std::vector< COutput > &vAvailableCoins, const Amount nTargetValue, std::set< CInputCoin > &setCoinsRet, Amount &nValueRet, const CCoinControl &coin_control, CoinSelectionParams &coin_selection_params, bool &bnb_used) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
Select a set of coins such that nValueRet >= nTargetValue and at least all coins from coin_control ar...
Definition: spend.cpp:432
std::vector< OutputGroup > GroupOutputs(const CWallet &wallet, const std::vector< COutput > &outputs, bool single_coin, const size_t max_ancestors)
Definition: spend.cpp:301
void AvailableCoins(const CWallet &wallet, std::vector< COutput > &vCoins, bool fOnlySafe=true, const CCoinControl *coinControl=nullptr, const Amount nMinimumAmount=SATOSHI, const Amount nMaximumAmount=MAX_MONEY, const Amount nMinimumSumAmount=MAX_MONEY, const uint64_t nMaximumCount=0) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
populate vCoins with vector of available COutputs.
Definition: spend.cpp:70
int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *pwallet, bool use_max_sig=false)
Get the marginal bytes of spending the specified output.
Definition: spend.cpp:33
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector< CTxOut > &txouts, bool use_max_sig=false)
Calculate the size of the transaction assuming all signatures are max size Use DummySignatureCreator,...
Definition: spend.cpp:44
int GetTxSpendSize(const CWallet &wallet, const CWalletTx &wtx, unsigned int out, bool use_max_sig=false)
Get the marginal bytes if spending the specified output from this transaction.
Definition: spend.cpp:23
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:93
Definition: amount.h:19
Bilingual messages:
Definition: translation.h:17
bool error(const char *fmt, const Args &...args)
Definition: system.h:45
Definition: threadsafety.h:56