diff options
author | Andrew Chow <github@achow101.com> | 2023-10-17 15:21:49 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-10-17 15:28:05 -0400 |
commit | fbcf1029a7ba47d07a4566cf1f9d2e7b4870304a (patch) | |
tree | cfe83991d7905e05afda8946cfac57052641ff25 /src | |
parent | ff6be778f94b65c6bf9748bdb1adce006d04d5dd (diff) | |
parent | 8a553c94098c96cb3679468c2b460be145a0eabf (diff) |
Merge bitcoin/bitcoin#28544: wallet: Add TxStateString function for debugging and logging
8a553c94098c96cb3679468c2b460be145a0eabf wallet: Add TxStateString function for debugging and logging (Ryan Ofsky)
Pull request description:
I found this useful while debugging silent conflict between #10102 and #27469 recently
ACKs for top commit:
ishaanam:
utACK 8a553c94098c96cb3679468c2b460be145a0eabf
achow101:
ACK 8a553c94098c96cb3679468c2b460be145a0eabf
furszy:
Code ACK 8a553c9
Tree-SHA512: 87965c66bcb59a21e7639878bb567e583a0e624735721ff7ad1104eed6bb9fba60607d0e3de7be3304232b3a55f48bab7039ea9c26b0e81963e59f9acd94f666
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/transaction.h | 11 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h index 1a79d7db4e..3b9cde9832 100644 --- a/src/wallet/transaction.h +++ b/src/wallet/transaction.h @@ -29,10 +29,12 @@ struct TxStateConfirmed { int position_in_block; explicit TxStateConfirmed(const uint256& block_hash, int height, int index) : confirmed_block_hash(block_hash), confirmed_block_height(height), position_in_block(index) {} + std::string toString() const { return strprintf("Confirmed (block=%s, height=%i, index=%i)", confirmed_block_hash.ToString(), confirmed_block_height, position_in_block); } }; //! State of transaction added to mempool. struct TxStateInMempool { + std::string toString() const { return strprintf("InMempool"); } }; //! State of rejected transaction that conflicts with a confirmed block. @@ -41,6 +43,7 @@ struct TxStateConflicted { int conflicting_block_height; explicit TxStateConflicted(const uint256& block_hash, int height) : conflicting_block_hash(block_hash), conflicting_block_height(height) {} + std::string toString() const { return strprintf("Conflicted (block=%s, height=%i)", conflicting_block_hash.ToString(), conflicting_block_height); } }; //! State of transaction not confirmed or conflicting with a known block and @@ -51,6 +54,7 @@ struct TxStateInactive { bool abandoned; explicit TxStateInactive(bool abandoned = false) : abandoned(abandoned) {} + std::string toString() const { return strprintf("Inactive (abandoned=%i)", abandoned); } }; //! State of transaction loaded in an unrecognized state with unexpected hash or @@ -62,6 +66,7 @@ struct TxStateUnrecognized { int index; TxStateUnrecognized(const uint256& block_hash, int index) : block_hash(block_hash), index(index) {} + std::string toString() const { return strprintf("Unrecognized (block=%s, index=%i)", block_hash.ToString(), index); } }; //! All possible CWalletTx states @@ -109,6 +114,12 @@ static inline int TxStateSerializedIndex(const TxState& state) }, state); } +//! Return TxState or SyncTxState as a string for logging or debugging. +template<typename T> +std::string TxStateString(const T& state) +{ + return std::visit([](const auto& s) { return s.toString(); }, state); +} /** * Cachable amount subdivided into watchonly and spendable parts. diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5d2f9e2fb6..cb8671c8e7 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1130,7 +1130,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const } //// debug print - WalletLogPrintf("AddToWallet %s %s%s\n", hash.ToString(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : "")); + WalletLogPrintf("AddToWallet %s %s%s %s\n", hash.ToString(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : ""), TxStateString(state)); // Write to disk if (fInsertedNew || fUpdated) |