2020-05-19 08:29:31 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2021-06-20 22:44:44 +02:00
|
|
|
* Copyright (C) 2018-2019 Tom Zander <tom@flowee.org>
|
2020-05-19 08:29:31 +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 TRANSACTIONMONITORSERVICE_H
|
|
|
|
|
#define TRANSACTIONMONITORSERVICE_H
|
|
|
|
|
|
2023-11-24 18:01:36 +01:00
|
|
|
#include <primitives/PublicKey.h>
|
2020-05-19 08:29:31 +02:00
|
|
|
|
|
|
|
|
#include <validationinterface.h>
|
|
|
|
|
#include <NetworkService.h>
|
|
|
|
|
#include <NetworkConnection.h>
|
2021-11-02 11:04:59 +01:00
|
|
|
#include <primitives/Tx.h>
|
2020-05-19 08:29:31 +02:00
|
|
|
#include <script/standard.h>
|
|
|
|
|
|
|
|
|
|
#include <set>
|
2023-12-21 15:13:56 +01:00
|
|
|
#include <memory>
|
2020-05-19 08:29:31 +02:00
|
|
|
|
|
|
|
|
class CTxMemPool;
|
|
|
|
|
|
|
|
|
|
class TransactionMonitorService : public ValidationInterface, public NetworkService
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TransactionMonitorService();
|
|
|
|
|
~TransactionMonitorService() override;
|
|
|
|
|
|
|
|
|
|
// the hub pushed a transaction into its mempool
|
2021-02-18 16:03:01 +01:00
|
|
|
void syncTx(const Tx &tx) override;
|
2021-11-02 10:18:24 +01:00
|
|
|
void syncAllTransactionsInBlock(const Block &block, CBlockIndex *index) override;
|
2021-02-18 16:03:01 +01:00
|
|
|
void doubleSpendFound(const Tx &first, const Tx &duplicate) override;
|
|
|
|
|
void doubleSpendFound(const Tx &txInMempool, const DoubleSpendProof &proof) override;
|
2020-05-19 08:29:31 +02:00
|
|
|
|
|
|
|
|
void onIncomingMessage(Remote *con, const Message &message, const EndPoint &ep) override;
|
|
|
|
|
|
|
|
|
|
inline void setMempool(CTxMemPool *mempool) {
|
|
|
|
|
m_mempool = mempool;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
class RemoteWithHashes : public Remote {
|
|
|
|
|
public:
|
|
|
|
|
std::set<uint256> hashes;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// NetworkService interface
|
|
|
|
|
Remote *createRemote() override {
|
|
|
|
|
return new RemoteWithHashes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void updateBools();
|
|
|
|
|
/// Callback for just subscribed addresses to find if there is a hit in the mempool.
|
|
|
|
|
void findTxInMempool(int connectionId, const uint256 &hash);
|
|
|
|
|
|
|
|
|
|
std::mutex m_poolMutex;
|
2023-12-21 15:13:56 +01:00
|
|
|
std::shared_ptr<Streaming::BufferPool> m_pool;
|
2020-05-19 08:29:31 +02:00
|
|
|
|
|
|
|
|
// true if any remote added a watch
|
|
|
|
|
bool m_findByHash = false;
|
|
|
|
|
|
|
|
|
|
CTxMemPool *m_mempool = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|