mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Merge 4b1fb50def into merged_master (Bitcoin PR bitcoin/bitcoin#22528)
This commit is contained in:
commit
ea7450b099
6 changed files with 61 additions and 50 deletions
|
|
@ -4,9 +4,12 @@
|
|||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <consensus/validation.h>
|
||||
#include <index/txindex.h>
|
||||
#include <net.h>
|
||||
#include <net_processing.h>
|
||||
#include <node/blockstorage.h>
|
||||
#include <node/context.h>
|
||||
#include <txmempool.h>
|
||||
#include <validation.h>
|
||||
#include <validationinterface.h>
|
||||
#include <node/transaction.h>
|
||||
|
|
@ -119,3 +122,38 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
|||
|
||||
return TransactionError::OK;
|
||||
}
|
||||
|
||||
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
if (mempool && !block_index) {
|
||||
CTransactionRef ptx = mempool->get(hash);
|
||||
if (ptx) return ptx;
|
||||
}
|
||||
if (g_txindex) {
|
||||
CTransactionRef tx;
|
||||
uint256 block_hash;
|
||||
if (g_txindex->FindTx(hash, block_hash, tx)) {
|
||||
if (!block_index || block_index->GetBlockHash() == block_hash) {
|
||||
// Don't return the transaction if the provided block hash doesn't match.
|
||||
// The case where a transaction appears in multiple blocks (e.g. reorgs or
|
||||
// BIP30) is handled by the block lookup below.
|
||||
hashBlock = block_hash;
|
||||
return tx;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (block_index) {
|
||||
CBlock block;
|
||||
if (ReadBlockFromDisk(block, block_index, consensusParams)) {
|
||||
for (const auto& tx : block.vtx) {
|
||||
if (tx->GetHash() == hash) {
|
||||
hashBlock = block_index->GetBlockHash();
|
||||
return tx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,12 @@
|
|||
#include <primitives/transaction.h>
|
||||
#include <util/error.h>
|
||||
|
||||
class CBlockIndex;
|
||||
class CTxMemPool;
|
||||
struct NodeContext;
|
||||
namespace Consensus {
|
||||
struct Params;
|
||||
}
|
||||
|
||||
/** Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
|
||||
* Also used by the GUI when broadcasting a completed PSBT.
|
||||
|
|
@ -38,4 +43,19 @@ static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
|
|||
*/
|
||||
[[nodiscard]] TransactionError BroadcastTransaction(NodeContext& node, CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback);
|
||||
|
||||
/**
|
||||
* Return transaction with a given hash.
|
||||
* If mempool is provided and block_index is not provided, check it first for the tx.
|
||||
* If -txindex is available, check it next for the tx.
|
||||
* Finally, if block_index is provided, check for tx by reading entire block from disk.
|
||||
*
|
||||
* @param[in] block_index The block to read from disk, or nullptr
|
||||
* @param[in] mempool If provided, check mempool for tx
|
||||
* @param[in] hash The txid
|
||||
* @param[in] consensusParams The params
|
||||
* @param[out] hashBlock The block hash, if the tx was found via -txindex or block_index
|
||||
* @returns The tx if found, otherwise nullptr
|
||||
*/
|
||||
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
|
||||
|
||||
#endif // BITCOIN_NODE_TRANSACTION_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue