|
|
|
@ -43,11 +43,11 @@ struct TxStateInMempool {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//! State of rejected transaction that conflicts with a confirmed block.
|
|
|
|
|
struct TxStateConflicted {
|
|
|
|
|
struct TxStateBlockConflicted {
|
|
|
|
|
uint256 conflicting_block_hash;
|
|
|
|
|
int conflicting_block_height;
|
|
|
|
|
|
|
|
|
|
explicit TxStateConflicted(const uint256& block_hash, int height) : conflicting_block_hash(block_hash), conflicting_block_height(height) {}
|
|
|
|
|
explicit TxStateBlockConflicted(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); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -75,7 +75,7 @@ struct TxStateUnrecognized {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//! All possible CWalletTx states
|
|
|
|
|
using TxState = std::variant<TxStateConfirmed, TxStateInMempool, TxStateConflicted, TxStateInactive, TxStateUnrecognized>;
|
|
|
|
|
using TxState = std::variant<TxStateConfirmed, TxStateInMempool, TxStateBlockConflicted, TxStateInactive, TxStateUnrecognized>;
|
|
|
|
|
|
|
|
|
|
//! Subset of states transaction sync logic is implemented to handle.
|
|
|
|
|
using SyncTxState = std::variant<TxStateConfirmed, TxStateInMempool, TxStateInactive>;
|
|
|
|
@ -90,7 +90,7 @@ static inline TxState TxStateInterpretSerialized(TxStateUnrecognized data)
|
|
|
|
|
} else if (data.index >= 0) {
|
|
|
|
|
return TxStateConfirmed{data.block_hash, /*height=*/-1, data.index};
|
|
|
|
|
} else if (data.index == -1) {
|
|
|
|
|
return TxStateConflicted{data.block_hash, /*height=*/-1};
|
|
|
|
|
return TxStateBlockConflicted{data.block_hash, /*height=*/-1};
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
@ -102,7 +102,7 @@ static inline uint256 TxStateSerializedBlockHash(const TxState& state)
|
|
|
|
|
[](const TxStateInactive& inactive) { return inactive.abandoned ? uint256::ONE : uint256::ZERO; },
|
|
|
|
|
[](const TxStateInMempool& in_mempool) { return uint256::ZERO; },
|
|
|
|
|
[](const TxStateConfirmed& confirmed) { return confirmed.confirmed_block_hash; },
|
|
|
|
|
[](const TxStateConflicted& conflicted) { return conflicted.conflicting_block_hash; },
|
|
|
|
|
[](const TxStateBlockConflicted& conflicted) { return conflicted.conflicting_block_hash; },
|
|
|
|
|
[](const TxStateUnrecognized& unrecognized) { return unrecognized.block_hash; }
|
|
|
|
|
}, state);
|
|
|
|
|
}
|
|
|
|
@ -114,7 +114,7 @@ static inline int TxStateSerializedIndex(const TxState& state)
|
|
|
|
|
[](const TxStateInactive& inactive) { return inactive.abandoned ? -1 : 0; },
|
|
|
|
|
[](const TxStateInMempool& in_mempool) { return 0; },
|
|
|
|
|
[](const TxStateConfirmed& confirmed) { return confirmed.position_in_block; },
|
|
|
|
|
[](const TxStateConflicted& conflicted) { return -1; },
|
|
|
|
|
[](const TxStateBlockConflicted& conflicted) { return -1; },
|
|
|
|
|
[](const TxStateUnrecognized& unrecognized) { return unrecognized.index; }
|
|
|
|
|
}, state);
|
|
|
|
|
}
|
|
|
|
@ -335,9 +335,9 @@ public:
|
|
|
|
|
void updateState(interfaces::Chain& chain);
|
|
|
|
|
|
|
|
|
|
bool isAbandoned() const { return state<TxStateInactive>() && state<TxStateInactive>()->abandoned; }
|
|
|
|
|
bool isConflicted() const { return state<TxStateConflicted>(); }
|
|
|
|
|
bool isBlockConflicted() const { return state<TxStateBlockConflicted>(); }
|
|
|
|
|
bool isInactive() const { return state<TxStateInactive>(); }
|
|
|
|
|
bool isUnconfirmed() const { return !isAbandoned() && !isConflicted() && !isConfirmed(); }
|
|
|
|
|
bool isUnconfirmed() const { return !isAbandoned() && !isBlockConflicted() && !isConfirmed(); }
|
|
|
|
|
bool isConfirmed() const { return state<TxStateConfirmed>(); }
|
|
|
|
|
const Txid& GetHash() const LIFETIMEBOUND { return tx->GetHash(); }
|
|
|
|
|
const Wtxid& GetWitnessHash() const LIFETIMEBOUND { return tx->GetWitnessHash(); }
|
|
|
|
|