Bitcoin ABC 0.30.7
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
10#include <wallet/wallet.h>
11
16int GetTxSpendSize(const CWallet &wallet, const CWalletTx &wtx,
17 unsigned int out, bool use_max_sig = false);
18
19class COutput {
20public:
21 const CWalletTx *tx;
22 int i;
23 int nDepth;
24
30
33
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
77int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *pwallet,
78 bool use_max_sig = false);
79
86int64_t CalculateMaximumSignedTxSize(const CTransaction &tx,
87 const CWallet *wallet,
88 const std::vector<CTxOut> &txouts,
89 bool use_max_sig = false);
90int64_t CalculateMaximumSignedTxSize(const CTransaction &tx,
91 const CWallet *wallet,
92 bool use_max_sig = false)
94
98void 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)
105
107 const CCoinControl *coinControl = nullptr);
108
113 const CTransaction &tx, int output)
115
120std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet &wallet)
122
123std::vector<OutputGroup>
124GroupOutputs(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
141bool 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
157bool 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,
163
170bool 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:31
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
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:254
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)
bool error(const char *fmt, const Args &...args)
Definition: logging.h:263
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
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:993
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:422
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:73
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:252
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:232
Amount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl=nullptr)
Definition: spend.cpp:217
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:1032
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:474
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:307
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:36
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:47
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:26
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
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56