2019-03-31 15:11:03 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2021-06-20 22:44:44 +02:00
|
|
|
* Copyright (C) 2019 Tom Zander <tom@flowee.org>
|
2019-03-31 15:11:03 +02:00
|
|
|
*
|
|
|
|
|
* 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>
|
2019-03-31 15:11:03 +02:00
|
|
|
#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-03-31 15:11:03 +02:00
|
|
|
{
|
2019-04-06 18:19:57 +02:00
|
|
|
Q_OBJECT
|
2019-03-31 15:11:03 +02:00
|
|
|
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);
|
2019-03-31 15:11:03 +02:00
|
|
|
|
|
|
|
|
int blockheight();
|
2019-11-06 22:55:17 +01:00
|
|
|
void blockFinished(int blockheight);
|
2019-10-16 22:42:44 +02:00
|
|
|
void insert(const Streaming::ConstBuffer &outScriptHashed, int outputIndex, int blockHeight, int offsetInBlock);
|
2019-03-31 15:11:03 +02:00
|
|
|
|
|
|
|
|
struct TxData {
|
|
|
|
|
int offsetInBlock = 0;
|
2019-04-11 14:59:14 +02:00
|
|
|
int blockHeight = -1;
|
2019-03-31 15:11:03 +02:00
|
|
|
short outputIndex = -1;
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-16 22:42:44 +02:00
|
|
|
std::vector<TxData> find(const uint256 &address) const;
|
2019-03-31 15:11:03 +02:00
|
|
|
|
2019-06-26 21:39:07 +02:00
|
|
|
void run() override;
|
2019-04-06 18:19:57 +02:00
|
|
|
|
2019-03-31 15:11:03 +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;
|
2025-02-05 11:13:00 +01:00
|
|
|
|
2019-03-31 15:11:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|