2018-09-06 10:52:50 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2021-02-28 22:16:05 +01:00
|
|
|
* Copyright (C) 2018-202l Tom Zander <tom@flowee.org>
|
2018-09-06 10:52:50 +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 ABSTRACTCOMMAND_H
|
|
|
|
|
#define ABSTRACTCOMMAND_H
|
|
|
|
|
|
2018-09-09 13:03:43 +02:00
|
|
|
#include <uint256.h>
|
|
|
|
|
|
2018-09-07 22:24:09 +02:00
|
|
|
#include <QCommandLineParser>
|
2018-09-06 10:52:50 +02:00
|
|
|
#include <QString>
|
|
|
|
|
#include <QTextStream>
|
2020-03-01 17:10:24 +01:00
|
|
|
#include <deque>
|
2018-09-06 10:52:50 +02:00
|
|
|
|
2018-09-09 13:03:43 +02:00
|
|
|
#include <streaming/ConstBuffer.h>
|
|
|
|
|
|
2018-09-06 10:52:50 +02:00
|
|
|
class QCommandLineParser;
|
2018-09-09 13:03:43 +02:00
|
|
|
class QFile;
|
2018-09-06 10:52:50 +02:00
|
|
|
|
|
|
|
|
namespace Flowee
|
|
|
|
|
{
|
|
|
|
|
enum ReturnCodes {
|
|
|
|
|
// note that Unix requires 'Ok' to be zero.
|
|
|
|
|
Ok = 0,
|
|
|
|
|
InvalidOptions = 1,
|
2018-09-08 11:40:29 +02:00
|
|
|
NeedForce = 2,
|
2018-09-08 18:57:41 +02:00
|
|
|
CommandFailed = 3
|
2018-09-06 10:52:50 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Log
|
|
|
|
|
{
|
|
|
|
|
enum Section {
|
|
|
|
|
UnspentCli = 11000
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AbstractCommand {
|
|
|
|
|
public:
|
|
|
|
|
AbstractCommand();
|
|
|
|
|
virtual ~AbstractCommand();
|
|
|
|
|
|
|
|
|
|
Flowee::ReturnCodes start(const QStringList &args);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
enum DBFileType {
|
2018-09-07 19:30:57 +02:00
|
|
|
InfoFile, // the .info file, multiple per database file
|
|
|
|
|
DBFile, // the data-n.db file, multiple in a datadir
|
|
|
|
|
Datadir, // the directory 'unspent' where all UTXO is stored
|
|
|
|
|
Unknown
|
2018-09-06 10:52:50 +02:00
|
|
|
};
|
|
|
|
|
class DatabaseFile {
|
|
|
|
|
public:
|
2018-09-07 19:30:57 +02:00
|
|
|
DatabaseFile();
|
2018-09-08 11:40:29 +02:00
|
|
|
DatabaseFile(const QString &filepath, DBFileType filetype, int index = -1);
|
2018-09-07 19:30:57 +02:00
|
|
|
DatabaseFile(const DatabaseFile &other) = default;
|
|
|
|
|
|
|
|
|
|
QList<DatabaseFile> infoFiles() const;
|
|
|
|
|
QList<DatabaseFile> databaseFiles() const;
|
2018-09-06 10:52:50 +02:00
|
|
|
|
|
|
|
|
QString filepath() const;
|
|
|
|
|
DBFileType filetype() const;
|
|
|
|
|
|
2020-03-05 22:25:01 +01:00
|
|
|
/// return the index if applicable. Indexes are used in info-files.
|
2018-09-08 11:40:29 +02:00
|
|
|
int index() const;
|
|
|
|
|
|
2018-09-06 10:52:50 +02:00
|
|
|
private:
|
|
|
|
|
QString m_filepath;
|
|
|
|
|
DBFileType m_filetype;
|
2018-09-08 11:40:29 +02:00
|
|
|
int m_index = -1;
|
2018-09-06 10:52:50 +02:00
|
|
|
};
|
|
|
|
|
|
2018-09-07 22:24:09 +02:00
|
|
|
virtual void addArguments(QCommandLineParser &commandLineParser);
|
2020-03-05 22:25:01 +01:00
|
|
|
virtual Flowee::ReturnCodes preParseArguments(QStringList &positionalArguments) {
|
|
|
|
|
Q_UNUSED(positionalArguments)
|
|
|
|
|
return Flowee::Ok;
|
|
|
|
|
}
|
2018-09-06 10:52:50 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* return long (multiline) Description of the command.
|
|
|
|
|
*/
|
|
|
|
|
virtual QString commandDescription() const = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Run the commmand
|
|
|
|
|
* @return the exit code as used by the comamnd.
|
|
|
|
|
*/
|
|
|
|
|
virtual Flowee::ReturnCodes run() = 0;
|
|
|
|
|
|
2021-02-28 22:16:05 +01:00
|
|
|
const QList<DatabaseFile>& dbDataFiles() const;
|
2018-09-06 10:52:50 +02:00
|
|
|
|
2018-09-10 11:15:08 +02:00
|
|
|
/**
|
|
|
|
|
* Find the files representing the highest consistent version
|
|
|
|
|
* in the selection of dbDataFile().
|
|
|
|
|
* At most one info file is returned per datafile.
|
|
|
|
|
*/
|
2018-09-09 22:08:28 +02:00
|
|
|
QList<DatabaseFile> highestDataFiles();
|
|
|
|
|
|
2018-09-06 10:52:50 +02:00
|
|
|
QTextStream out, err;
|
|
|
|
|
|
2018-09-09 22:08:28 +02:00
|
|
|
QCommandLineParser &commandLineParser();
|
2018-09-07 22:24:09 +02:00
|
|
|
|
2018-09-09 22:08:28 +02:00
|
|
|
bool readJumptables(const QString &filepath, int startPos, uint32_t *tables);
|
2018-09-09 13:03:43 +02:00
|
|
|
uint256 calcChecksum(uint32_t *tables) const;
|
|
|
|
|
|
|
|
|
|
struct CheckPoint {
|
|
|
|
|
uint256 lastBlockId;
|
|
|
|
|
uint256 jumptableHash;
|
|
|
|
|
int firstBlockHeight = -1;
|
|
|
|
|
int lastBlockHeight = -1;
|
|
|
|
|
int positionInFile = -1;
|
|
|
|
|
int jumptableFilepos = -1;
|
2020-03-01 17:10:24 +01:00
|
|
|
int changesSincePrune = -1;
|
2020-03-01 21:05:53 +01:00
|
|
|
int initialBucketSize = -1;
|
2020-03-01 17:10:24 +01:00
|
|
|
bool isTip = false;
|
|
|
|
|
std::deque<uint256> invalidBlockHashes;
|
2018-09-09 13:03:43 +02:00
|
|
|
};
|
|
|
|
|
CheckPoint readInfoFile(const QString &filepath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Leaf {
|
|
|
|
|
int blockHeight = -1;
|
|
|
|
|
int offsetInBlock = -1;
|
|
|
|
|
int outIndex = 0;
|
|
|
|
|
uint256 txid;
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-20 22:59:52 +02:00
|
|
|
Leaf readLeaf(Streaming::ConstBuffer buf, quint64 cheapHash, bool *failed = nullptr);
|
2018-09-09 13:40:14 +02:00
|
|
|
|
2018-09-20 22:59:52 +02:00
|
|
|
struct LeafRef {
|
|
|
|
|
quint64 cheapHash;
|
|
|
|
|
int pos;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::vector<LeafRef> readBucket(Streaming::ConstBuffer buf, int bucketOffsetInFile, bool *failed = nullptr);
|
2018-09-09 13:03:43 +02:00
|
|
|
|
2018-09-06 10:52:50 +02:00
|
|
|
private:
|
2018-09-07 22:24:09 +02:00
|
|
|
QCommandLineParser m_parser;
|
2020-03-01 23:13:48 +01:00
|
|
|
QList<DatabaseFile> m_dataFiles;
|
2018-09-06 10:52:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|