aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/transaction.h
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2023-09-27 10:35:45 -0400
committerRyan Ofsky <ryan@ofsky.org>2023-09-27 13:47:38 -0400
commit8a553c94098c96cb3679468c2b460be145a0eabf (patch)
tree15cf95f77cbe83896659b7b1b6e04e2735426bba /src/wallet/transaction.h
parentdcfbf3c2107c3cb9d343ebfa0eee78278dea8d66 (diff)
downloadbitcoin-8a553c94098c96cb3679468c2b460be145a0eabf.tar.xz
wallet: Add TxStateString function for debugging and logging
Co-authored-by: furszy <matiasfurszyfer@protonmail.com>
Diffstat (limited to 'src/wallet/transaction.h')
-rw-r--r--src/wallet/transaction.h11
1 files changed, 11 insertions, 0 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.