Bitcoin ABC  0.28.12
P2P Digital Currency
spend.h
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 http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_WALLET_SPEND_H
6 #define BITCOIN_WALLET_SPEND_H
7 
8 #include <wallet/coinselection.h>
9 #include <wallet/transaction.h>
10 #include <wallet/wallet.h>
11 
16 int GetTxSpendSize(const CWallet &wallet, const CWalletTx &wtx,
17  unsigned int out, bool use_max_sig = false);
18 
19 class COutput {
20 public:
21  const CWalletTx *tx;
22  int i;
23  int nDepth;
24 
30 
32  bool fSpendable;
33 
35  bool fSolvable;
36 
43 
49  bool fSafe;
50 
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  }
68 
69  std::string ToString() const;
70 
71  inline CInputCoin GetInputCoin() const {
72  return CInputCoin(tx->tx, i, nInputBytes);
73  }
74 };
75 
77 int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *pwallet,
78  bool use_max_sig = false);
79 
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);
94 
98 void AvailableCoins(const CWallet &wallet, std::vector<COutput> &vCoins,
99  const CCoinControl *coinControl = nullptr,
100  const Amount nMinimumAmount = SATOSHI,
101  const Amount nMaximumAmount = MAX_MONEY,
102  const Amount nMinimumSumAmount = MAX_MONEY,
103  const uint64_t nMaximumCount = 0)
104  EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
105 
107  const CCoinControl *coinControl = nullptr);
108 
113  const CTransaction &tx, int output)
114  EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
115 
120 std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet &wallet)
121  EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
122 
123 std::vector<OutputGroup>
124 GroupOutputs(const CWallet &wallet, const std::vector<COutput> &outputs,
125  bool separate_coins, const CFeeRate &effective_feerate,
126  const CFeeRate &long_term_feerate,
127  const CoinEligibilityFilter &filter, bool positive_only);
128 
141 bool SelectCoinsMinConf(const CWallet &wallet, const Amount nTargetValue,
142  const CoinEligibilityFilter &eligibility_filter,
143  std::vector<COutput> coins,
144  std::set<CInputCoin> &setCoinsRet, Amount &nValueRet,
146  bool &bnb_used);
147 
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);
163 
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);
174 
180  int &nChangePosInOut, bilingual_str &error,
181  bool lockUnspents,
182  const std::set<int> &setSubtractFeeFromOutputs,
183  CCoinControl coinControl);
184 
185 #endif // BITCOIN_WALLET_SPEND_H
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
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
A mutable version of CTransaction.
Definition: transaction.h:274
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:192
An output of a transaction.
Definition: transaction.h:128
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:253
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, false)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:257
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
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:990
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:229
bool SelectCoinsMinConf(const CWallet &wallet, const Amount nTargetValue, const CoinEligibilityFilter &eligibility_filter, std::vector< COutput > coins, 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:419
void AvailableCoins(const CWallet &wallet, std::vector< COutput > &vCoins, 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
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:249
Amount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl=nullptr)
Definition: spend.cpp:214
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:1029
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:471
std::vector< OutputGroup > GroupOutputs(const CWallet &wallet, const std::vector< COutput > &outputs, bool separate_coins, const CFeeRate &effective_feerate, const CFeeRate &long_term_feerate, const CoinEligibilityFilter &filter, bool positive_only)
Definition: spend.cpp:304
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
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:85
Definition: amount.h:19
Bilingual messages:
Definition: translation.h:17
bool error(const char *fmt, const Args &...args)
Definition: system.h:45
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56