@@ -29,10 +29,12 @@ struct TxStateConfirmed {
29
29
int position_in_block;
30
30
31
31
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); }
32
33
};
33
34
34
35
// ! State of transaction added to mempool.
35
36
struct TxStateInMempool {
37
+ std::string toString () const { return strprintf (" InMempool" ); }
36
38
};
37
39
38
40
// ! State of rejected transaction that conflicts with a confirmed block.
@@ -41,6 +43,7 @@ struct TxStateConflicted {
41
43
int conflicting_block_height;
42
44
43
45
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); }
44
47
};
45
48
46
49
// ! State of transaction not confirmed or conflicting with a known block and
@@ -51,6 +54,7 @@ struct TxStateInactive {
51
54
bool abandoned;
52
55
53
56
explicit TxStateInactive (bool abandoned = false ) : abandoned(abandoned) {}
57
+ std::string toString () const { return strprintf (" Inactive (abandoned=%i)" , abandoned); }
54
58
};
55
59
56
60
// ! State of transaction loaded in an unrecognized state with unexpected hash or
@@ -62,6 +66,7 @@ struct TxStateUnrecognized {
62
66
int index;
63
67
64
68
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); }
65
70
};
66
71
67
72
// ! All possible CWalletTx states
@@ -109,6 +114,12 @@ static inline int TxStateSerializedIndex(const TxState& state)
109
114
}, state);
110
115
}
111
116
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
+ }
112
123
113
124
/* *
114
125
* Cachable amount subdivided into watchonly and spendable parts.
0 commit comments