| 75 | BaseIndex::DB& TxIndex::GetDB() const { return *m_db; } |
| 76 | |
| 77 | bool 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 | } |