aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/spend.h
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2021-02-10 16:06:01 -0500
committerRussell Yanofsky <russ@yanofsky.org>2021-05-26 06:32:51 -0500
commitc7bd5842e467c4fc286399379572bbdec6b26a4f (patch)
treeabe503bdb5da1d724f57ac95919409c8d74528ac /src/wallet/spend.h
parentecddd1248258fb904ba88b5255ecbc624eec4f37 (diff)
downloadbitcoin-c7bd5842e467c4fc286399379572bbdec6b26a4f.tar.xz
MOVEONLY: CWallet transaction code out of wallet.cpp/.h
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After #20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in https://github.com/bitcoin/bitcoin/pull/21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
Diffstat (limited to 'src/wallet/spend.h')
-rw-r--r--src/wallet/spend.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/wallet/spend.h b/src/wallet/spend.h
new file mode 100644
index 0000000000..03f9a7c2b5
--- /dev/null
+++ b/src/wallet/spend.h
@@ -0,0 +1,64 @@
+// Copyright (c) 2021 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_SPEND_H
+#define BITCOIN_WALLET_SPEND_H
+
+#include <wallet/coinselection.h>
+#include <wallet/transaction.h>
+#include <wallet/wallet.h>
+
+class COutput
+{
+public:
+ const CWalletTx *tx;
+
+ /** Index in tx->vout. */
+ int i;
+
+ /**
+ * Depth in block chain.
+ * If > 0: the tx is on chain and has this many confirmations.
+ * If = 0: the tx is waiting confirmation.
+ * If < 0: a conflicting tx is on chain and has this many confirmations. */
+ int nDepth;
+
+ /** Pre-computed estimated size of this output as a fully-signed input in a transaction. Can be -1 if it could not be calculated */
+ int nInputBytes;
+
+ /** Whether we have the private keys to spend this output */
+ bool fSpendable;
+
+ /** Whether we know how to spend this output, ignoring the lack of keys */
+ bool fSolvable;
+
+ /** Whether to use the maximum sized, 72 byte signature when calculating the size of the input spend. This should only be set when watch-only outputs are allowed */
+ bool use_max_sig;
+
+ /**
+ * Whether this output is considered safe to spend. Unconfirmed transactions
+ * from outside keys and unconfirmed replacement transactions are considered
+ * unsafe and will not be used to fund new spending transactions.
+ */
+ bool fSafe;
+
+ COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn, bool use_max_sig_in = false)
+ {
+ tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; fSolvable = fSolvableIn; fSafe = fSafeIn; nInputBytes = -1; use_max_sig = use_max_sig_in;
+ // If known and signable by the given wallet, compute nInputBytes
+ // Failure will keep this value -1
+ if (fSpendable && tx) {
+ nInputBytes = tx->GetSpendSize(i, use_max_sig);
+ }
+ }
+
+ std::string ToString() const;
+
+ inline CInputCoin GetInputCoin() const
+ {
+ return CInputCoin(tx->tx, i, nInputBytes);
+ }
+};
+
+#endif // BITCOIN_WALLET_SPEND_H