5#ifndef BITCOIN_WALLET_TRANSACTION_H
6#define BITCOIN_WALLET_TRANSACTION_H
79using TxState = std::variant<TxStateConfirmed, TxStateInMempool, TxStateBlockConflicted, TxStateInactive, TxStateUnrecognized>;
82using SyncTxState = std::variant<TxStateConfirmed, TxStateInMempool, TxStateInactive>;
91 }
else if (
data.index >= 0) {
93 }
else if (
data.index == -1) {
105 [](
const TxStateConfirmed& confirmed) {
return confirmed.confirmed_block_hash; },
115 [](
const TxStateInactive& inactive) {
return inactive.abandoned ? -1 : 0; },
117 [](
const TxStateConfirmed& confirmed) {
return confirmed.position_in_block; },
127 return std::visit([](
const auto&
s) {
return s.toString(); }, state);
178 template<
typename Stream>
183 std::vector<uint256> vMerkleBranch;
223 std::vector<std::pair<std::string, std::string> >
vOrderForm;
282 template<
typename Stream>
287 mapValueCopy[
"fromaccount"] =
"";
295 std::vector<uint8_t> dummy_vector1;
296 std::vector<uint8_t> dummy_vector2;
297 bool dummy_bool =
false;
298 uint32_t dummy_int = 0;
304 template<
typename Stream>
309 std::vector<uint256> dummy_vector1;
310 std::vector<CMerkleTx> dummy_vector2;
319 const auto it_op =
mapValue.find(
"n");
320 nOrderPos = (it_op !=
mapValue.end()) ? LocaleIndependentAtoi<int64_t>(it_op->second) : -1;
321 const auto it_ts =
mapValue.find(
"timesmart");
322 nTimeSmart = (it_ts !=
mapValue.end()) ?
static_cast<unsigned int>(LocaleIndependentAtoi<int64_t>(it_ts->second)) : 0;
351 template<
typename T>
const T*
state()
const {
return std::get_if<T>(&
m_state); }
358 bool isAbandoned()
const {
return state<TxStateInactive>() && state<TxStateInactive>()->abandoned; }
397 Assume(std::ranges::find(wtx.
tx->vout, output) != wtx.
tx->vout.end());
int64_t CAmount
Amount in satoshis (Can be negative)
#define Assert(val)
Identity function.
#define Assume(val)
Assume is the identity function.
An output of a transaction.
std::string ToString() const
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
static const uint256 ZERO
Legacy class used for deserializing vtxPrev for backwards compatibility.
void Unserialize(Stream &s)
A transaction with a bunch of additional info that only the owner cares about.
bool isBlockConflicted() const
const Txid & GetHash() const LIFETIMEBOUND
bool IsEquivalentTo(const CWalletTx &tx) const
True if only scriptSigs are different.
std::vector< std::pair< std::string, std::string > > vOrderForm
std::set< Txid > mempool_conflicts
mapValue_t mapValue
Key/value map with information about the transaction.
void updateState(interfaces::Chain &chain)
Update transaction state when attaching to a chain, filling in heights of conflicted and confirmed bl...
@ AMOUNTTYPE_ENUM_ELEMENTS
void Serialize(Stream &s) const
int64_t nOrderPos
position in ordered transaction list
bool isUnconfirmed() const
void CopyFrom(const CWalletTx &)
unsigned int nTimeReceived
time received by this node
void Unserialize(Stream &s)
void SetTx(CTransactionRef arg)
bool isMempoolConflicted() const
CachableAmount m_amounts[AMOUNTTYPE_ENUM_ELEMENTS]
CWalletTx & operator=(const CWalletTx &)=default
std::optional< Txid > truc_child_in_mempool
int64_t GetTxTime() const
CWalletTx(CTransactionRef tx, const TxState &state)
bool m_is_cache_empty
This flag is true if all m_amounts caches are empty.
std::multimap< int64_t, CWalletTx * >::const_iterator m_it_wtxOrdered
CWalletTx(const CWalletTx &)=default
unsigned int nTimeSmart
Stable timestamp that never changes, and reflects the order a transaction was added to the wallet.
const Wtxid & GetWitnessHash() const LIFETIMEBOUND
void MarkDirty()
make sure balances are recalculated
WalletTXO(const CWalletTx &wtx, const CTxOut &output)
const CWalletTx & GetWalletTx() const
const CTxOut & GetTxOut() const
#define T(expected, seed, data)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
std::variant< TxStateConfirmed, TxStateInMempool, TxStateInactive > SyncTxState
Subset of states transaction sync logic is implemented to handle.
std::variant< TxStateConfirmed, TxStateInMempool, TxStateBlockConflicted, TxStateInactive, TxStateUnrecognized > TxState
All possible CWalletTx states.
std::map< std::string, std::string > mapValue_t
static int TxStateSerializedIndex(const TxState &state)
Get TxState serialized block index. Inverse of TxStateInterpretSerialized.
static TxState TxStateInterpretSerialized(TxStateUnrecognized data)
Try to interpret deserialized TxStateUnrecognized data as a recognized state.
static uint256 TxStateSerializedBlockHash(const TxState &state)
Get TxState serialized block hash. Inverse of TxStateInterpretSerialized.
std::string TxStateString(const T &state)
Return TxState or SyncTxState as a string for logging or debugging.
static constexpr TransactionSerParams TX_WITH_WITNESS
std::shared_ptr< const CTransaction > CTransactionRef
Overloaded helper for std::visit.
Cachable amount subdivided into avoid reuse and all balances.
std::optional< CAmount > m_avoid_reuse_value
std::optional< CAmount > m_all_value
bool IsCached(bool avoid_reuse)
CAmount Get(bool avoid_reuse)
void Set(bool avoid_reuse, CAmount value)
State of rejected transaction that conflicts with a confirmed block.
std::string toString() const
int conflicting_block_height
uint256 conflicting_block_hash
TxStateBlockConflicted(const uint256 &block_hash, int height)
State of transaction confirmed in a block.
int confirmed_block_height
std::string toString() const
TxStateConfirmed(const uint256 &block_hash, int height, int index)
uint256 confirmed_block_hash
State of transaction added to mempool.
std::string toString() const
State of transaction not confirmed or conflicting with a known block and not in the mempool.
std::string toString() const
TxStateInactive(bool abandoned=false)
State of transaction loaded in an unrecognized state with unexpected hash or index values.
TxStateUnrecognized(const uint256 &block_hash, int index)
std::string toString() const
bool operator()(const CWalletTx *a, const CWalletTx *b) const
is a home for public enum and struct type definitions that are used by internally by wallet code,...