27 unsigned int out,
bool use_max_sig) {
40 if (!
wallet->DummySignInput(txn.
vin[0], txout, use_max_sig)) {
49 const std::vector<CTxOut> &
txouts,
60 std::vector<CTxOut>
txouts;
61 for (
auto &input : tx.
vin) {
62 const auto mi =
wallet->mapWallet.find(input.prevout.GetTxId());
67 assert(input.prevout.GetN() <
mi->second.tx->vout.size());
68 txouts.emplace_back(
mi->second.tx->vout[input.prevout.GetN()]);
97 for (
const auto &entry :
wallet.mapWallet) {
101 if (
wallet.IsTxImmatureCoinBase(wtx)) {
105 int nDepth =
wallet.GetTxDepthInMainChain(wtx);
135 if (nDepth == 0 && wtx.
mapValue.count(
"replaced_by_txid")) {
147 for (
uint32_t i = 0; i < wtx.
tx->vout.size(); i++) {
167 if (
wallet.IsLockedCoin(outpoint)) {
171 if (
wallet.IsSpent(outpoint)) {
185 std::unique_ptr<SigningProvider> provider =
186 wallet.GetSolvingProvider(wtx.
tx->vout[i].scriptPubKey);
189 provider ?
IsSolvable(*provider, wtx.
tx->vout[i].scriptPubKey)
222 std::vector<COutput>
vCoins;
225 if (out.fSpendable) {
226 balance += out.tx->tx->vout[out.i].nValue;
240 if (it ==
wallet.mapWallet.end() ||
241 it->second.tx->vout.size() <= prevout.
GetN() ||
242 !
wallet.IsMine(it->second.tx->vout[prevout.
GetN()])) {
245 ptx = it->second.tx.get();
251std::map<CTxDestination, std::vector<COutput>>
255 std::map<CTxDestination, std::vector<COutput>> result;
262 if ((coin.fSpendable ||
269 result[address].emplace_back(std::move(coin));
277 wallet.GetLegacyScriptPubKeyMan() &&
282 auto it =
wallet.mapWallet.find(output.GetTxId());
283 if (it !=
wallet.mapWallet.end()) {
284 int depth =
wallet.GetTxDepthInMainChain(it->second);
285 if (depth >= 0 && output.GetN() < it->second.tx->vout.size() &&
286 wallet.IsMine(it->second.tx->vout[output.GetN()]) ==
294 result[address].emplace_back(
295 wallet, it->second, output.GetN(), depth,
306std::vector<OutputGroup>
315 for (
const COutput &output : outputs) {
317 if (!output.fSpendable) {
333 if (
group.m_outputs.size() > 0 &&
334 group.EligibleForSpending(filter)) {
352 for (
const auto &output : outputs) {
354 if (!output.fSpendable) {
412 if (
group.m_outputs.size() > 0 &&
413 group.EligibleForSpending(filter)) {
424 std::vector<COutput> coins,
489 if (!out.fSpendable) {
493 nValueRet += out.tx->tx->vout[out.i].nValue;
508 std::map<TxId, CWalletTx>::const_iterator it =
509 wallet.mapWallet.find(outpoint.GetTxId());
510 if (it !=
wallet.mapWallet.end()) {
513 if (wtx.
tx->vout.size() <= outpoint.GetN()) {
518 wtx.
tx, outpoint.GetN(),
540 for (std::vector<COutput>::iterator it =
vCoins.begin();
568 (
wallet.m_spend_zero_conf_change &&
572 (
wallet.m_spend_zero_conf_change &&
576 (
wallet.m_spend_zero_conf_change &&
580 (
wallet.m_spend_zero_conf_change &&
586 (
wallet.m_spend_zero_conf_change &&
622 :
wallet.m_default_change_type,
627 for (
const auto &recipient :
vecSend) {
629 error =
_(
"Transaction amounts must not be negative");
633 nValue += recipient.nAmount;
635 if (recipient.fSubtractFeeFromAmount) {
641 error =
_(
"Transaction must have at least one recipient");
670 if (!std::get_if<CNoDestination>(&
coin_control.destChange)) {
687 if (!
reservedest.GetReservedDestination(dest,
true)) {
688 error =
_(
"Transaction needs a change address, but we can't "
689 "generate it. Please call keypoolrefill first.");
709 "rate setting (%s)"),
745 for (
const auto &recipient :
vecSend) {
746 CTxOut txout(recipient.nAmount, recipient.scriptPubKey);
748 if (recipient.fSubtractFeeFromAmount) {
769 if (recipient.fSubtractFeeFromAmount &&
772 error =
_(
"The transaction amount is too small to "
775 error =
_(
"The transaction amount is too small to "
776 "send after the fee has been deducted");
779 error =
_(
"Transaction amount too small");
785 txNew.vout.push_back(txout);
797 if (change_spend_size == -1) {
802 size_t(change_spend_size);
814 error =
_(
"Insufficient funds");
840 error =
_(
"Change index out of range");
844 std::vector<CTxOut>::iterator
position =
862 error =
_(
"Signing transaction failed");
914 error =
_(
"Transaction fee and change calculation failed");
963 std::numeric_limits<uint32_t>::max() - 1));
967 error =
_(
"Signing transaction failed");
976 error =
_(
"Transaction too large");
1020 "Fee non-grouped = %lld, grouped = %lld, using %s\n",
nFeeRet,
1037 std::vector<CRecipient>
vecSend;
1040 for (
size_t idx = 0; idx < tx.
vout.size(); idx++) {
1070 for (
size_t idx = 0; idx < tx.
vout.size(); idx++) {
1071 tx.
vout[idx].nValue =
tx_new->vout[idx].nValue;
static constexpr Amount SATOSHI
static constexpr Amount MAX_MONEY
No amount larger than this (in satoshi) is valid.
#define CHECK_NONFATAL(condition)
Identity function.
std::optional< unsigned int > m_confirm_target
Override the default confirmation target if set.
bool m_avoid_partial_spends
Avoid partial use of funds sent to a given address.
Fee rate in satoshis per kilobyte: Amount / kB.
Amount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.
A mutable version of CTransaction.
std::vector< CTxOut > vout
An outpoint - a combination of a transaction hash and an index n into its vout.
const TxId & GetTxId() const
std::string ToString() const
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxIn > vin
An input of a transaction.
An output of a transaction.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
mapValue_t mapValue
Key/value map with information about the transaction.
A wrapper to reserve an address from a wallet.
std::string ToString() const
Helper for findBlock to selectively return pieces of block data.
void emplace_back(Args &&...args)
const int DEFAULT_MAX_DEPTH
const int DEFAULT_MIN_DEPTH
bool KnapsackSolver(const Amount nTargetValue, std::vector< OutputGroup > &groups, std::set< CInputCoin > &setCoinsRet, Amount &nValueRet)
bool SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const Amount &target_value, const Amount &cost_of_change, std::set< CInputCoin > &out_set, Amount &value_ret, const Amount not_input_fees)
This is the Branch and Bound Coin Selection algorithm designed by Murch.
static const Amount MIN_FINAL_CHANGE
final minimum change amount after paying for fees
static std::vector< COutput > vCoins
CoinSelectionParams coin_selection_params(false, 0, 0, CFeeRate(Amount::zero()), 0, false)
bilingual_str TransactionErrorString(const TransactionError error)
isminetype
IsMine() return codes.
bool error(const char *fmt, const Args &...args)
std::string FormatMoney(const Amount amt)
Do not use these functions to represent or parse monetary amounts to or from JSON but use AmountFromV...
void insert(Tdst &dst, const Tsrc &src)
Simplification of std insertion.
Amount GetDustThreshold(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
static constexpr unsigned int MAX_STANDARD_TX_SIZE
The maximum size for transactions we're willing to relay/mine.
static CTransactionRef MakeTransactionRef()
std::shared_ptr< const CTransaction > CTransactionRef
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
bool CachedTxIsFromMe(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< TxId > &trusted_parents)
size_t GetSerializeSize(const T &t, int nVersion=0)
bool IsSolvable(const SigningProvider &provider, const CScript &script)
Check whether we know how to sign for an output like this, assuming we have all private keys.
int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *wallet, bool use_max_sig)
Get the marginal bytes of spending the specified output.
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...
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();.
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector< CTxOut > &txouts, bool use_max_sig)
Calculate the size of the transaction assuming all signatures are max size Use DummySignatureCreator,...
const CTxOut & FindNonChangeParentOutput(const CWallet &wallet, const CTransaction &tx, int output)
Find non-change parent output.
bool CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, Amount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
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)
static bool CreateTransactionInternal(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, Amount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, bool sign)
static const size_t OUTPUT_GROUP_MAX_ENTRIES
void AvailableCoins(const CWallet &wallet, std::vector< COutput > &vCoins, const CCoinControl *coinControl, const Amount nMinimumAmount, const Amount nMaximumAmount, const Amount nMinimumSumAmount, const uint64_t nMaximumCount)
populate vCoins with vector of available COutputs.
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.
Amount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
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)
Select a set of coins such that nValueRet >= nTargetValue and at least all coins from coin_control ar...
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
static constexpr Amount zero() noexcept
const bool m_include_partial_groups
Include partial destination groups when avoid_reuse and there are full groups.
bool m_subtract_fee_outputs
Indicate that we are subtracting the fee from outputs.
bool m_avoid_partial_spends
size_t change_output_size
void Insert(const CInputCoin &output, int depth, bool from_me, bool positive_only)
A TxId is the identifier of a transaction.
#define AssertLockHeld(cs)
bilingual_str _(const char *psz)
Translation function.
static const int PROTOCOL_VERSION
network protocol versioning
Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, const CCoinControl &coin_control)
Estimate the minimum fee considering user set parameters and the required fee.
CFeeRate GetMinimumFeeRate(const CWallet &wallet, const CCoinControl &coin_control)
Estimate the minimum fee rate considering user set parameters and the required fee.
static constexpr size_t DUMMY_P2PKH_INPUT_SIZE
Pre-calculated constants for input size estimation.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
@ WALLET_FLAG_AVOID_REUSE