diff --git a/src/index/txindex.h b/src/index/txindex.h --- a/src/index/txindex.h +++ b/src/index/txindex.h @@ -9,9 +9,9 @@ #include /** - * TxIndex is used to look up transactions included in the blockchain by hash. + * TxIndex is used to look up transactions included in the blockchain by ID. * The index is written to a LevelDB database and records the filesystem - * location of each transaction by transaction hash. + * location of each transaction by transaction ID. */ class TxIndex final : public BaseIndex { protected: @@ -39,14 +39,14 @@ // incomplete type. virtual ~TxIndex() override; - /// Look up a transaction by hash. + /// Look up a transaction by identifier. /// - /// @param[in] tx_hash The hash of the transaction to be returned. + /// @param[in] txid The ID of the transaction to be returned. /// @param[out] block_hash The hash of the block the transaction is found /// in. /// @param[out] tx The transaction itself. /// @return true if transaction is found, false otherwise - bool FindTx(const uint256 &tx_hash, uint256 &block_hash, + bool FindTx(const TxId &txid, uint256 &block_hash, CTransactionRef &tx) const; }; diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -54,12 +54,12 @@ explicit DB(size_t n_cache_size, bool f_memory = false, bool f_wipe = false); - /// Read the disk location of the transaction data with the given hash. - /// Returns false if the transaction hash is not indexed. - bool ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const; + /// Read the disk location of the transaction data with the given ID. + /// Returns false if the transaction ID is not indexed. + bool ReadTxPos(const TxId &txid, CDiskTxPos &pos) const; /// Write a batch of transaction positions to the DB. - bool WriteTxs(const std::vector> &v_pos); + bool WriteTxs(const std::vector> &v_pos); /// Migrate txindex data from the block tree DB, where it may be for older /// nodes that have not been upgraded yet to the new database. @@ -71,12 +71,12 @@ : BaseIndex::DB(GetDataDir() / "indexes" / "txindex", n_cache_size, f_memory, f_wipe) {} -bool TxIndex::DB::ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const { +bool TxIndex::DB::ReadTxPos(const TxId &txid, CDiskTxPos &pos) const { return Read(std::make_pair(DB_TXINDEX, txid), pos); } bool TxIndex::DB::WriteTxs( - const std::vector> &v_pos) { + const std::vector> &v_pos) { CDBBatch batch(*this); for (const auto &tuple : v_pos) { batch.Write(std::make_pair(DB_TXINDEX, tuple.first), tuple.second); @@ -168,7 +168,7 @@ // Log progress every 10%. if (++count % 256 == 0) { // Since txids are uniformly random and traversed in increasing - // order, the high 16 bits of the hash can be used to estimate the + // order, the high 16 bits of the ID can be used to estimate the // current progress. const uint256 &txid = key.second; uint32_t high_nibble = @@ -248,10 +248,10 @@ bool TxIndex::WriteBlock(const CBlock &block, const CBlockIndex *pindex) { CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size())); - std::vector> vPos; + std::vector> vPos; vPos.reserve(block.vtx.size()); for (const auto &tx : block.vtx) { - vPos.emplace_back(tx->GetHash(), pos); + vPos.emplace_back(tx->GetId(), pos); pos.nTxOffset += ::GetSerializeSize(*tx, SER_DISK, CLIENT_VERSION); } return m_db->WriteTxs(vPos); @@ -261,10 +261,10 @@ return *m_db; } -bool TxIndex::FindTx(const uint256 &tx_hash, uint256 &block_hash, +bool TxIndex::FindTx(const TxId &txid, uint256 &block_hash, CTransactionRef &tx) const { CDiskTxPos postx; - if (!m_db->ReadTxPos(tx_hash, postx)) { + if (!m_db->ReadTxPos(txid, postx)) { return false; } @@ -280,7 +280,7 @@ } catch (const std::exception &e) { return error("%s: Deserialize or I/O error - %s", __func__, e.what()); } - if (tx->GetHash() != tx_hash) { + if (tx->GetId() != txid) { return error("%s: txid mismatch", __func__); } block_hash = header.GetHash();