Files

129 lines
3.7 KiB
C++
Raw Permalink Normal View History

2019-03-17 22:52:09 +01:00
/*
* This file is part of the Flowee project
2026-04-09 18:56:13 +02:00
* Copyright (C) 2016-2026 Tom Zander <tom@flowee.org>
2019-03-17 22:52:09 +01: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 TXVULCANO_H
#define TXVULCANO_H
#include <QString>
2019-03-17 22:52:09 +01:00
#include "Wallet.h"
#include <streaming/BufferPool.h>
#include <networkmanager/NetworkManager.h>
#include <networkmanager/NetworkConnection.h>
2025-02-08 19:05:26 +01:00
#include <boost/asio/io_context.hpp>
#include <primitives/Tx.h>
2019-03-17 22:52:09 +01:00
2026-04-09 18:56:13 +02:00
#include <boost/asio/steady_timer.hpp>
2019-03-18 12:36:19 +01:00
#include <qlist.h>
#include <qmutex.h>
#include <qthread.h>
2019-03-17 22:52:09 +01:00
#include <vector>
namespace Streaming {
class MessageBuilder;
}
class TxVulcano : public QObject
2019-03-17 22:52:09 +01:00
{
Q_OBJECT
2019-03-17 22:52:09 +01:00
public:
2025-02-08 19:05:26 +01:00
TxVulcano(boost::asio::io_context &ioContext, const QString &walletname);
~TxVulcano();
2019-03-17 22:52:09 +01:00
void tryConnect(const EndPoint &ep);
2019-03-18 12:36:19 +01:00
void setMaxBlockSize(int sizeInMb);
inline void setMaxNumTransactions(int num) {
assert(num > 0);
m_transactionsToCreate = num;
}
2019-03-17 22:52:09 +01:00
2020-11-21 13:07:57 +01:00
/**
* A setup where the TxVulcano owns the addresses
* means we can ask the Hub to mine some blocks with addresses we create
* as coinbase. This implies we run on regtest.
*/
void setAddressesAreOwned(bool yes);
bool canRunGenerate() const;
void setCanRunGenerate(bool canRunGenerate);
bool addPrivKey(const QString &key);
signals:
void newBlockFound(const Message &message);
private slots:
// handle incoming GetBlockReply messages
void processNewBlock(const Message &message);
void createTransactions_priv();
2019-03-17 22:52:09 +01:00
private:
void connectionEstablished(const EndPoint &ep);
void disconnected();
void incomingMessage(const Message &message);
2020-11-21 13:07:57 +01:00
// requires m_walletMutex to be locked by caller
void requestNextBlocksChunk();
2019-03-17 22:52:09 +01:00
void createTransactions(const boost::system::error_code& error);
std::vector<char> createOutScript(const std::vector<char> &address);
void buildGetBlockRequest(Streaming::MessageBuilder &builder, bool &first) const;
void nowCurrent(); // called when the client has seen all blocks the upstread knows about
void generate(int blockCount = 1); // generate a block;
NetworkManager m_networkManager;
NetworkConnection m_connection;
bool m_serverSupportsAsync = false;
2019-03-17 22:52:09 +01:00
2023-12-21 15:13:56 +01:00
std::shared_ptr<Streaming::BufferPool> m_Txpool;
std::shared_ptr<Streaming::BufferPool> m_pool;
2019-03-17 22:52:09 +01:00
2019-03-18 12:36:19 +01:00
// limits
2019-03-17 22:52:09 +01:00
int m_transactionsToCreate;
int m_transactionsCreated;
2019-03-18 12:36:19 +01:00
int m_blockSizeLeft;
int m_lastPrintedBlockSizeLeft = 0;
2019-03-18 12:36:19 +01:00
QList<int> m_nextBlockSize;
2026-04-09 18:56:13 +02:00
boost::asio::steady_timer m_timer;
2019-03-17 22:52:09 +01:00
struct UnvalidatedTransaction {
Tx transaction;
int unconfirmedDepth = 0;
std::vector<int> pubKeys;
};
QMutex m_miscMutex;
2019-03-17 22:52:09 +01:00
std::map<int, UnvalidatedTransaction> m_transactionsInProgress;
int m_lastId = 0;
2020-11-21 13:07:57 +01:00
bool m_canRunGenerate = false; // i.e. we run on regtest where mining is an API command.
2019-03-17 22:52:09 +01:00
2022-08-20 19:18:34 +02:00
QRecursiveMutex m_walletMutex;
2019-03-17 22:52:09 +01:00
Wallet m_wallet;
int m_lastSeenBlock = -1;
int m_highestBlock = -1; // the block that we learned that the remote has.
2020-11-22 17:09:55 +01:00
bool m_outOfCoin = false; // set to true if there are no unspent coins
QThread m_workerThread;
2019-03-17 22:52:09 +01:00
};
#endif