MCPcopy Create free account
hub / github.com/ElementsProject/elements / FindTx

Method FindTx

src/index/txindex.cpp:77–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75BaseIndex::DB& TxIndex::GetDB() const { return *m_db; }
76
77bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRef& tx) const
78{
79 CDiskTxPos postx;
80 if (!m_db->ReadTxPos(tx_hash, postx)) {
81 return false;
82 }
83
84 CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
85 if (file.IsNull()) {
86 return error("%s: OpenBlockFile failed", __func__);
87 }
88 CBlockHeader header;
89 try {
90 file >> header;
91 if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
92 return error("%s: fseek(...) failed", __func__);
93 }
94 file >> tx;
95 } catch (const std::exception& e) {
96 return error("%s: Deserialize or I/O error - %s", __func__, e.what());
97 }
98 if (tx->GetHash() != tx_hash) {
99 return error("%s: txid mismatch", __func__);
100 }
101 block_hash = header.GetHash();
102 return true;
103}

Callers 2

BOOST_FIXTURE_TEST_CASEFunction · 0.80
GetTransactionFunction · 0.80

Calls 6

OpenBlockFileFunction · 0.85
errorFunction · 0.85
ReadTxPosMethod · 0.80
IsNullMethod · 0.45
GetMethod · 0.45
GetHashMethod · 0.45

Tested by 1

BOOST_FIXTURE_TEST_CASEFunction · 0.64