@@ -29,10 +29,12 @@ struct TxStateConfirmed {
2929 int position_in_block;
3030
3131 explicit TxStateConfirmed (const uint256& block_hash, int height, int index) : confirmed_block_hash(block_hash), confirmed_block_height(height), position_in_block(index) {}
32+ std::string toString () const { return strprintf (" Confirmed (block=%s, height=%i, index=%i)" , confirmed_block_hash.ToString (), confirmed_block_height, position_in_block); }
3233};
3334
3435// ! State of transaction added to mempool.
3536struct TxStateInMempool {
37+ std::string toString () const { return strprintf (" InMempool" ); }
3638};
3739
3840// ! State of rejected transaction that conflicts with a confirmed block.
@@ -41,6 +43,7 @@ struct TxStateConflicted {
4143 int conflicting_block_height;
4244
4345 explicit TxStateConflicted (const uint256& block_hash, int height) : conflicting_block_hash(block_hash), conflicting_block_height(height) {}
46+ std::string toString () const { return strprintf (" Conflicted (block=%s, height=%i)" , conflicting_block_hash.ToString (), conflicting_block_height); }
4447};
4548
4649// ! State of transaction not confirmed or conflicting with a known block and
@@ -51,6 +54,7 @@ struct TxStateInactive {
5154 bool abandoned;
5255
5356 explicit TxStateInactive (bool abandoned = false ) : abandoned(abandoned) {}
57+ std::string toString () const { return strprintf (" Inactive (abandoned=%i)" , abandoned); }
5458};
5559
5660// ! State of transaction loaded in an unrecognized state with unexpected hash or
@@ -62,6 +66,7 @@ struct TxStateUnrecognized {
6266 int index;
6367
6468 TxStateUnrecognized (const uint256& block_hash, int index) : block_hash(block_hash), index(index) {}
69+ std::string toString () const { return strprintf (" Unrecognized (block=%s, index=%i)" , block_hash.ToString (), index); }
6570};
6671
6772// ! All possible CWalletTx states
@@ -109,6 +114,12 @@ static inline int TxStateSerializedIndex(const TxState& state)
109114 }, state);
110115}
111116
117+ // ! Return TxState or SyncTxState as a string for logging or debugging.
118+ template <typename T>
119+ std::string TxStateString (const T& state)
120+ {
121+ return std::visit ([](const auto & s) { return s.toString (); }, state);
122+ }
112123
113124/* *
114125 * Cachable amount subdivided into watchonly and spendable parts.
0 commit comments