2017-12-08 19:19:57 +01:00
|
|
|
// Copyright (c) 2017-2018 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_INDEX_TXINDEX_H
|
|
|
|
#define BITCOIN_INDEX_TXINDEX_H
|
|
|
|
|
2018-05-16 02:20:17 +02:00
|
|
|
#include <chain.h>
|
2018-05-16 00:57:48 +02:00
|
|
|
#include <index/base.h>
|
2018-05-16 02:20:17 +02:00
|
|
|
#include <txdb.h>
|
2017-12-08 19:19:57 +01:00
|
|
|
|
2018-05-15 23:47:37 +02:00
|
|
|
/**
|
|
|
|
* TxIndex is used to look up transactions included in the blockchain by hash.
|
|
|
|
* The index is written to a LevelDB database and records the filesystem
|
|
|
|
* location of each transaction by transaction hash.
|
|
|
|
*/
|
|
|
|
class TxIndex final : public BaseIndex
|
|
|
|
{
|
2018-05-16 02:20:17 +02:00
|
|
|
protected:
|
|
|
|
class DB;
|
|
|
|
|
2018-05-15 23:47:37 +02:00
|
|
|
private:
|
2018-05-16 02:20:17 +02:00
|
|
|
const std::unique_ptr<DB> m_db;
|
2018-05-15 23:47:37 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/// Override base class init to migrate from old database.
|
|
|
|
bool Init() override;
|
|
|
|
|
|
|
|
bool WriteBlock(const CBlock& block, const CBlockIndex* pindex) override;
|
|
|
|
|
2018-05-16 02:20:17 +02:00
|
|
|
BaseIndex::DB& GetDB() const override;
|
2018-05-15 23:47:37 +02:00
|
|
|
|
2018-05-16 00:45:20 +02:00
|
|
|
const char* GetName() const override { return "txindex"; }
|
|
|
|
|
2018-05-15 23:47:37 +02:00
|
|
|
public:
|
|
|
|
/// Constructs the index, which becomes available to be queried.
|
2018-05-16 02:26:49 +02:00
|
|
|
explicit TxIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
|
2018-05-15 23:47:37 +02:00
|
|
|
|
2018-05-16 02:20:17 +02:00
|
|
|
// Destructor is declared because this class contains a unique_ptr to an incomplete type.
|
|
|
|
virtual ~TxIndex() override;
|
|
|
|
|
2018-05-15 23:47:37 +02:00
|
|
|
/// Look up a transaction by hash.
|
|
|
|
///
|
|
|
|
/// @param[in] tx_hash The hash 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, CTransactionRef& tx) const;
|
|
|
|
};
|
|
|
|
|
2017-12-08 20:29:59 +01:00
|
|
|
/// The global transaction index, used in GetTransaction. May be null.
|
|
|
|
extern std::unique_ptr<TxIndex> g_txindex;
|
|
|
|
|
2017-12-08 19:19:57 +01:00
|
|
|
#endif // BITCOIN_INDEX_TXINDEX_H
|