Files

94 lines
2.4 KiB
C++
Raw Permalink Normal View History

/*
* This file is part of the Flowee project
2021-06-20 22:44:44 +02:00
* Copyright (C) 2019 Tom Zander <tom@flowee.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ADDRESSINDEXER_H
#define ADDRESSINDEXER_H
2019-04-05 13:50:41 +02:00
#include <QList>
2019-06-26 21:39:07 +02:00
#include <QThread>
#include <qsqldatabase.h>
#include <qsqlquery.h>
#include <streaming/ConstBuffer.h>
#include "HashStorage.h"
2019-06-26 21:39:07 +02:00
#include <boost/filesystem/path.hpp>
2020-02-16 15:29:25 +01:00
#include <vector>
#include <deque>
2019-06-26 21:39:07 +02:00
2019-04-06 15:16:37 +02:00
class QSettings;
2019-04-06 18:19:57 +02:00
class DirtyData;
2019-06-26 21:39:07 +02:00
class Indexer;
2019-04-06 15:16:37 +02:00
2019-08-13 22:21:22 +02:00
class TableSpecification;
2019-06-26 21:39:07 +02:00
class AddressIndexer : public QThread
{
2019-04-06 18:19:57 +02:00
Q_OBJECT
public:
2019-06-26 21:39:07 +02:00
AddressIndexer(const boost::filesystem::path &basedir, Indexer *datasource);
2019-09-12 15:21:48 +02:00
~AddressIndexer() override;
2019-04-06 15:16:37 +02:00
void loadSetting(const QSettings &settings);
int blockheight();
2019-11-06 22:55:17 +01:00
void blockFinished(int blockheight);
void insert(const Streaming::ConstBuffer &outScriptHashed, int outputIndex, int blockHeight, int offsetInBlock);
struct TxData {
int offsetInBlock = 0;
2019-04-11 14:59:14 +02:00
int blockHeight = -1;
short outputIndex = -1;
};
std::vector<TxData> find(const uint256 &address) const;
2019-06-26 21:39:07 +02:00
void run() override;
2019-04-06 18:19:57 +02:00
private:
void createTables();
2019-06-26 21:39:07 +02:00
void commitAllData();
2019-04-06 18:19:57 +02:00
struct Entry {
short outIndex;
int height, row, offsetInBlock;
};
std::vector<std::deque<Entry> > m_uncommittedData;
int m_uncommittedCount = 0;
2019-06-26 21:39:07 +02:00
int m_height = -1;
2019-04-06 18:19:57 +02:00
2019-06-26 21:39:07 +02:00
HashStorage m_addresses;
QString m_basedir;
Indexer *m_dataSource;
2019-04-06 18:19:57 +02:00
2019-06-26 21:39:07 +02:00
QSqlDatabase m_insertDb;
QSqlDatabase m_selectDb;
QList<QSqlQuery> m_insertQuery;
2019-08-14 22:10:06 +02:00
QAtomicInt m_flushRequested;
2019-08-28 13:40:50 +02:00
enum TopOfChain {
InInitialSync = 0,
InitialSyncFinished = 1,
FlushRequested = 2
};
QAtomicInt m_topOfChain;
2019-08-13 22:21:22 +02:00
TableSpecification *m_spec = nullptr;
2025-02-12 15:35:24 +01:00
QString m_postgresCsv;
};
#endif