mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-13 22:41:25 +02:00
32325d1777tests: Add test for mempool-invalid wallet tx (Anthony Towns)25e063d950wallet: Add separate balance info for non-mempool wallet txs (Anthony Towns)81e763f1e5wallet: Have GetBalance report used amount directly without two calls (Anthony Towns) Pull request description: Changes `getbalances` to report the sum of txos spent by transactions that aren't confirmed nor in the mempool (eg due to being part of too long a mempool chain, or spending non-standard outputs, or having a datacarrier output that exceeds `-datacarriersize`, etc). Those values are added to the trusted/untrusted_pending/immature/used fields as appropriate (where previously they were skipped), and subtracted from the new nonmempool field, so that the sum of all fields remains the same. For example: ``` $ bitcoin-cli -regtest getbalances { "mine": { "trusted": 6049.99999220, "untrusted_pending": 0.00000000, "immature": 3200.00000780, "nonmempool": -100.00000000 }, "lastprocessedblock": { "hash": "3ab4582226d5e8ad76438db48d76e822c31bce2cdbc7ba82a5d974a277515d0d", "height": 221 } } ``` Closes #11887 ACKs for top commit: achow101: ACK32325d1777w0xlt: lgtm ACK32325d1777musaHaruna: Code Review ACK [32325d1](32325d1777) Tree-SHA512: 142581944d1b3213067e219e3b8205f27b89007e545149c01b801bad38fe730c5b2bfdfe6a2064c3649889f66ec48ec7616982564d00e3d83837249e925d8f16
60 lines
3.0 KiB
C++
60 lines
3.0 KiB
C++
// Copyright (c) 2021-present The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_WALLET_RECEIVE_H
|
|
#define BITCOIN_WALLET_RECEIVE_H
|
|
|
|
#include <consensus/amount.h>
|
|
#include <primitives/transaction_identifier.h>
|
|
#include <wallet/transaction.h>
|
|
#include <wallet/wallet.h>
|
|
|
|
namespace wallet {
|
|
bool InputIsMine(const CWallet& wallet, const CTxIn& txin) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
|
|
|
/** Returns whether all of the inputs belong to the wallet*/
|
|
bool AllInputsMine(const CWallet& wallet, const CTransaction& tx);
|
|
|
|
CAmount OutputGetCredit(const CWallet& wallet, const CTxOut& txout);
|
|
CAmount TxGetCredit(const CWallet& wallet, const CTransaction& tx);
|
|
|
|
bool ScriptIsChange(const CWallet& wallet, const CScript& script) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
|
bool OutputIsChange(const CWallet& wallet, const CTxOut& txout) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
|
CAmount OutputGetChange(const CWallet& wallet, const CTxOut& txout) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
|
CAmount TxGetChange(const CWallet& wallet, const CTransaction& tx);
|
|
|
|
CAmount CachedTxGetCredit(const CWallet& wallet, const CWalletTx& wtx, bool avoid_reuse)
|
|
EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
|
CAmount CachedTxGetDebit(const CWallet& wallet, const CWalletTx& wtx, bool avoid_reuse);
|
|
CAmount CachedTxGetChange(const CWallet& wallet, const CWalletTx& wtx);
|
|
struct COutputEntry
|
|
{
|
|
CTxDestination destination;
|
|
CAmount amount;
|
|
int vout;
|
|
};
|
|
void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
|
|
std::list<COutputEntry>& listReceived,
|
|
std::list<COutputEntry>& listSent,
|
|
CAmount& nFee,
|
|
bool include_change);
|
|
bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx);
|
|
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<Txid>& trusted_parents) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
|
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx);
|
|
|
|
struct Balance {
|
|
CAmount m_mine_trusted{0}; //!< Trusted, at depth=GetBalance.min_depth or more
|
|
CAmount m_mine_untrusted_pending{0}; //!< Untrusted, but in mempool (pending)
|
|
CAmount m_mine_immature{0}; //!< Immature coinbases in the main chain
|
|
CAmount m_mine_used{0}; //!< Trusted/untrusted/immature funds in utxos that have already been spent from (only populated if AVOID REUSE wallet flag is set)
|
|
CAmount m_mine_nonmempool{0}; //!< Coins spent by wallet txs that are not in the mempool
|
|
};
|
|
Balance GetBalance(const CWallet& wallet, int min_depth = 0, bool avoid_reuse = true, bool include_nonmempool = false);
|
|
|
|
std::map<CTxDestination, CAmount> GetAddressBalances(const CWallet& wallet);
|
|
std::set<std::set<CTxDestination>> GetAddressGroupings(const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
|
} // namespace wallet
|
|
|
|
#endif // BITCOIN_WALLET_RECEIVE_H
|