Bitcoin ABC 0.31.2
P2P Digital Currency
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <util/result.h>
10#include <wallet/transaction.h>
11#include <wallet/wallet.h>
12
13#include <optional>
14
19int GetTxSpendSize(const CWallet &wallet, const CWalletTx &wtx,
20 unsigned int out, bool use_max_sig = false);
21
22class COutput {
23public:
24 const CWalletTx *tx;
25 int i;
26 int nDepth;
27
33
36
39
46
52 bool fSafe;
53
54 COutput(const CWallet &wallet, const CWalletTx &wtx, int iIn, int nDepthIn,
55 bool fSpendableIn, bool fSolvableIn, bool fSafeIn,
56 bool use_max_sig_in = false) {
57 tx = &wtx;
58 i = iIn;
59 nDepth = nDepthIn;
60 fSpendable = fSpendableIn;
61 fSolvable = fSolvableIn;
62 fSafe = fSafeIn;
63 nInputBytes = -1;
64 use_max_sig = use_max_sig_in;
65 // If known and signable by the given wallet, compute nInputBytes
66 // Failure will keep this value -1
67 if (fSpendable) {
69 }
70 }
71
72 std::string ToString() const;
73
74 inline CInputCoin GetInputCoin() const {
75 return CInputCoin(tx->tx, i, nInputBytes);
76 }
77};
78
80int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *pwallet,
81 bool use_max_sig = false);
82
89int64_t CalculateMaximumSignedTxSize(const CTransaction &tx,
90 const CWallet *wallet,
91 const std::vector<CTxOut> &txouts,
92 bool use_max_sig = false);
93int64_t CalculateMaximumSignedTxSize(const CTransaction &tx,
94 const CWallet *wallet,
95 bool use_max_sig = false)
97
101void AvailableCoins(const CWallet &wallet, std::vector<COutput> &vCoins,
102 const CCoinControl *coinControl = nullptr,
103 const Amount nMinimumAmount = SATOSHI,
104 const Amount nMaximumAmount = MAX_MONEY,
105 const Amount nMinimumSumAmount = MAX_MONEY,
106 const uint64_t nMaximumCount = 0)
108
110 const CCoinControl *coinControl = nullptr);
111
116 const CTransaction &tx, int output)
118
123std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet &wallet)
125
126std::vector<OutputGroup>
127GroupOutputs(const CWallet &wallet, const std::vector<COutput> &outputs,
128 bool separate_coins, const CFeeRate &effective_feerate,
129 const CFeeRate &long_term_feerate,
130 const CoinEligibilityFilter &filter, bool positive_only);
131
144bool SelectCoinsMinConf(const CWallet &wallet, const Amount nTargetValue,
145 const CoinEligibilityFilter &eligibility_filter,
146 std::vector<COutput> coins,
147 std::set<CInputCoin> &setCoinsRet, Amount &nValueRet,
149 bool &bnb_used);
150
160bool SelectCoins(const CWallet &wallet,
161 const std::vector<COutput> &vAvailableCoins,
162 const Amount nTargetValue, std::set<CInputCoin> &setCoinsRet,
163 Amount &nValueRet, const CCoinControl &coin_control,
166
171
173 : tx(tx), fee(fee), change_pos(change_pos) {}
174};
175
182CreateTransaction(CWallet &wallet, const std::vector<CRecipient> &vecSend,
183 int change_pos, const CCoinControl &coin_control,
184 bool sign = true);
185
191 int &nChangePosInOut, bilingual_str &error,
192 bool lockUnspents,
193 const std::set<int> &setSubtractFeeFromOutputs,
194 CCoinControl coinControl);
195
196#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:22
int nDepth
Definition: spend.h:26
bool fSafe
Whether this output is considered safe to spend.
Definition: spend.h:52
bool fSolvable
Whether we know how to spend this output, ignoring the lack of keys.
Definition: spend.h:38
int nInputBytes
Pre-computed estimated size of this output as a fully-signed input in a transaction.
Definition: spend.h:32
bool fSpendable
Whether we have the private keys to spend this output.
Definition: spend.h:35
const CWalletTx * tx
Definition: spend.h:24
CInputCoin GetInputCoin() const
Definition: spend.h:74
std::string ToString() const
Definition: spend.cpp:31
int i
Definition: spend.h:25
bool use_max_sig
Whether to use the maximum sized, 72 byte signature when calculating the size of the input spend.
Definition: spend.h:45
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:54
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:269
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
util::Result< CreatedTransactionResult > CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, int change_pos, 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:991
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:1027
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
CreatedTransactionResult(CTransactionRef tx, Amount fee, int change_pos)
Definition: spend.h:172
CTransactionRef tx
Definition: spend.h:168
Bilingual messages:
Definition: translation.h:17
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56