36 std::string& err_string,
48 std::promise<void> promise;
49 Txid txid = tx->GetHash();
50 Wtxid wtxid = tx->GetWitnessHash();
51 bool callback_set =
false;
59 for (
size_t o = 0; o < tx->vout.size(); o++) {
66 if (
auto mempool_tx =
node.mempool->get(txid); mempool_tx) {
74 wtxid = mempool_tx->GetWitnessHash();
83 }
else if (result.
m_base_fees.value() > max_tx_fee) {
88 switch (broadcast_method) {
94 node.chainman->ProcessTransaction(tx,
false);
104 node.mempool->AddUnbroadcastTx(txid);
109 if (wait_callback &&
node.validation_signals) {
118 node.validation_signals->CallFunctionInValidationInterfaceQueue([&promise] {
129 promise.get_future().wait();
132 switch (broadcast_method) {
136 node.peerman->RelayTransaction(txid, wtxid);
145 if (mempool && !block_index) {
152 if (
g_txindex->FindTx(hash, block_hash, tx)) {
153 if (!block_index || block_index->
GetBlockHash() == block_hash) {
157 hashBlock = block_hash;
164 if (blockman.
ReadBlock(block, *block_index)) {
165 for (
const auto& tx : block.
vtx) {
166 if (tx->GetHash() == hash) {
int64_t CAmount
Amount in satoshis (Can be negative)
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
uint256 GetBlockHash() const
CCoinsView that adds a memory cache for transactions to another CCoinsView.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
An outpoint - a combination of a transaction hash and an index n into its vout.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
CTransactionRef get(const Txid &hash) const
bool IsSpent() const
Either this coin never existed (see e.g.
std::string ToString() const
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
bool ReadBlock(CBlock &block, const FlatFilePos &pos, const std::optional< uint256 > &expected_hash) const
Functions for disk access for blocks.
@ TX_MISSING_INPUTS
transaction was missing some of its inputs
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
TxBroadcast
How to broadcast a local transaction.
@ MEMPOOL_AND_BROADCAST_TO_ALL
Add the transaction to the mempool and broadcast to all peers for which tx relay is enabled.
@ MEMPOOL_NO_BROADCAST
Add the transaction to the mempool, but don't broadcast to anybody.
TransactionError BroadcastTransaction(NodeContext &node, const CTransactionRef tx, std::string &err_string, const CAmount &max_tx_fee, TxBroadcast broadcast_method, bool wait_callback)
Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const Txid &hash, const BlockManager &blockman, uint256 &hashBlock)
Return transaction with a given hash.
static TransactionError HandleATMPError(const TxValidationState &state, std::string &err_string_out)
is a home for public enum and struct type definitions that are used internally by node code,...
std::shared_ptr< const CTransaction > CTransactionRef
Validation result for a transaction evaluated by MemPoolAccept (single or package).
const ResultType m_result_type
Result type.
const std::optional< CAmount > m_base_fees
Raw base fees in satoshis.
const TxValidationState m_state
Contains information about why the transaction failed.
NodeContext struct containing references to chain state and connection state.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.