aboutsummaryrefslogtreecommitdiff
path: root/src/node/transaction.cpp
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2021-07-22 15:01:14 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2021-07-22 15:53:17 +0200
commitabc57e1f0882a1a2bb20474648419979af6e383d (patch)
tree384f1b226cc930327681f235c14a28bc67adb4fa /src/node/transaction.cpp
parent78f4c8b98eada337346ffb206339c3ebae4ff43b (diff)
downloadbitcoin-abc57e1f0882a1a2bb20474648419979af6e383d.tar.xz
refactor: move `GetTransaction(...)` to node/transaction.cpp
can be reviewed with --color-moved
Diffstat (limited to 'src/node/transaction.cpp')
-rw-r--r--src/node/transaction.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp
index f21b390915..0227618edf 100644
--- a/src/node/transaction.cpp
+++ b/src/node/transaction.cpp
@@ -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>
@@ -104,3 +107,35 @@ 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) {
+ 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;
+}