mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
wallet: Add TxStateString function for debugging and logging
Co-authored-by: furszy <matiasfurszyfer@protonmail.com>
This commit is contained in:
parent
dcfbf3c210
commit
8a553c9409
2 changed files with 12 additions and 1 deletions
|
@ -29,10 +29,12 @@ struct TxStateConfirmed {
|
||||||
int position_in_block;
|
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) {}
|
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.
|
//! State of transaction added to mempool.
|
||||||
struct TxStateInMempool {
|
struct TxStateInMempool {
|
||||||
|
std::string toString() const { return strprintf("InMempool"); }
|
||||||
};
|
};
|
||||||
|
|
||||||
//! State of rejected transaction that conflicts with a confirmed block.
|
//! State of rejected transaction that conflicts with a confirmed block.
|
||||||
|
@ -41,6 +43,7 @@ struct TxStateConflicted {
|
||||||
int conflicting_block_height;
|
int conflicting_block_height;
|
||||||
|
|
||||||
explicit TxStateConflicted(const uint256& block_hash, int height) : conflicting_block_hash(block_hash), conflicting_block_height(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
|
//! State of transaction not confirmed or conflicting with a known block and
|
||||||
|
@ -51,6 +54,7 @@ struct TxStateInactive {
|
||||||
bool abandoned;
|
bool abandoned;
|
||||||
|
|
||||||
explicit TxStateInactive(bool abandoned = false) : abandoned(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
|
//! State of transaction loaded in an unrecognized state with unexpected hash or
|
||||||
|
@ -62,6 +66,7 @@ struct TxStateUnrecognized {
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
TxStateUnrecognized(const uint256& block_hash, int index) : block_hash(block_hash), index(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
|
//! All possible CWalletTx states
|
||||||
|
@ -109,6 +114,12 @@ static inline int TxStateSerializedIndex(const TxState& state)
|
||||||
}, 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.
|
* Cachable amount subdivided into watchonly and spendable parts.
|
||||||
|
|
|
@ -1129,7 +1129,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
|
||||||
}
|
}
|
||||||
|
|
||||||
//// debug print
|
//// 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
|
// Write to disk
|
||||||
if (fInsertedNew || fUpdated)
|
if (fInsertedNew || fUpdated)
|
||||||
|
|
Loading…
Add table
Reference in a new issue