diff options
| author | Jim Posen <[email protected]> | 2018-03-30 00:39:08 -0700 |
|---|---|---|
| committer | Jim Posen <[email protected]> | 2018-04-25 11:25:15 -0700 |
| commit | a03f804f2aa0261ed3a47103dfe989ebd9302480 (patch) | |
| tree | 0bb7e5c43cc73c6bf0a439e2f7c55632a029a547 /src/index/txindex.cpp | |
| parent | [validation] Replace tx index code in validation code with TxIndex. (diff) | |
| download | discoin-a03f804f2aa0261ed3a47103dfe989ebd9302480.tar.xz discoin-a03f804f2aa0261ed3a47103dfe989ebd9302480.zip | |
[index] Move disk IO logic from GetTransaction to TxIndex::FindTx.
Diffstat (limited to 'src/index/txindex.cpp')
| -rw-r--r-- | src/index/txindex.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index 7992d8533..2a661f033 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -254,9 +254,30 @@ bool TxIndex::BlockUntilSyncedToCurrentChain() return true; } -bool TxIndex::FindTx(const uint256& txid, CDiskTxPos& pos) const +bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRef& tx) const { - return m_db->ReadTxPos(txid, pos); + CDiskTxPos postx; + if (!m_db->ReadTxPos(tx_hash, postx)) { + return false; + } + + CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION); + if (file.IsNull()) { + return error("%s: OpenBlockFile failed", __func__); + } + CBlockHeader header; + try { + file >> header; + fseek(file.Get(), postx.nTxOffset, SEEK_CUR); + file >> tx; + } catch (const std::exception& e) { + return error("%s: Deserialize or I/O error - %s", __func__, e.what()); + } + if (tx->GetHash() != tx_hash) { + return error("%s: txid mismatch", __func__); + } + block_hash = header.GetHash(); + return true; } void TxIndex::Interrupt() |