2017-11-09 19:34:51 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
|
|
|
|
* Copyright (C) 2009-2010 Satoshi Nakamoto
|
|
|
|
|
* Copyright (C) 2009-2015 The Bitcoin Core developers
|
2021-01-20 19:21:53 +01:00
|
|
|
* Copyright (C) 2016-2021 Tom Zander <tom@flowee.org>
|
2017-11-09 19:34:51 +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/>.
|
|
|
|
|
*/
|
2013-04-13 00:13:08 -05:00
|
|
|
|
2018-01-16 10:47:52 +00:00
|
|
|
#ifndef FLOWEE_MINER_H
|
|
|
|
|
#define FLOWEE_MINER_H
|
2013-07-31 09:43:35 -04:00
|
|
|
|
2021-11-02 10:08:27 +01:00
|
|
|
#include "primitives/MutableBlock.h"
|
2014-10-12 03:26:42 +00:00
|
|
|
|
2016-05-05 14:36:07 +01:00
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
#include <boost/thread.hpp>
|
2013-04-13 00:13:08 -05:00
|
|
|
|
|
|
|
|
class CBlockIndex;
|
2018-01-15 15:26:12 +00:00
|
|
|
namespace Validation { class Engine; }
|
2015-04-10 12:49:01 +02:00
|
|
|
class CChainParams;
|
2013-04-13 00:13:08 -05:00
|
|
|
class CReserveKey;
|
|
|
|
|
class CScript;
|
|
|
|
|
class CWallet;
|
2016-05-05 14:36:07 +01:00
|
|
|
namespace Consensus { struct Params; }
|
2013-07-31 09:43:35 -04:00
|
|
|
|
2014-10-12 03:26:42 +00:00
|
|
|
struct CBlockTemplate
|
|
|
|
|
{
|
2021-11-02 09:36:09 +01:00
|
|
|
MutableBlock block;
|
2021-01-20 19:21:53 +01:00
|
|
|
std::vector<int64_t> vTxFees;
|
2014-10-12 03:26:42 +00:00
|
|
|
};
|
2014-05-10 14:54:20 +02:00
|
|
|
|
2016-05-05 14:36:07 +01:00
|
|
|
|
|
|
|
|
class Mining
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* parse /a the public address and return a script used to make it
|
|
|
|
|
* a coinbase.
|
|
|
|
|
* @throws runtime_error when the input is not usable
|
|
|
|
|
*/
|
|
|
|
|
static CScript ScriptForCoinbase(const std::string &publicAddress);
|
|
|
|
|
/** Run the miner threads */
|
|
|
|
|
static void GenerateBitcoins(bool fGenerate, int nThreads, const CChainParams& chainparams, const std::string &GetCoinbase);
|
|
|
|
|
static void Stop();
|
|
|
|
|
|
|
|
|
|
static Mining *instance();
|
|
|
|
|
Mining();
|
|
|
|
|
~Mining();
|
|
|
|
|
|
2018-01-15 15:26:12 +00:00
|
|
|
/**
|
|
|
|
|
* Generate a new block, without valid proof-of-work, using the global settings
|
|
|
|
|
*/
|
|
|
|
|
CBlockTemplate* CreateNewBlock() const;
|
2016-05-05 14:36:07 +01:00
|
|
|
/** Generate a new block, without valid proof-of-work */
|
2018-01-15 15:26:12 +00:00
|
|
|
CBlockTemplate* CreateNewBlock(Validation::Engine &validationEngine) const;
|
2016-05-05 14:36:07 +01:00
|
|
|
/** Modify the extranonce in a block */
|
2021-11-02 09:36:09 +01:00
|
|
|
void IncrementExtraNonce(MutableBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
|
2021-11-02 10:49:17 +01:00
|
|
|
static int64_t UpdateTime(BlockHeaderFields* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
|
2016-05-05 14:36:07 +01:00
|
|
|
|
|
|
|
|
CScript GetCoinbase() const;
|
|
|
|
|
void SetCoinbase(const CScript &coinbase);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
boost::thread_group* m_minerThreads;
|
|
|
|
|
static Mining *s_instance;
|
|
|
|
|
mutable std::mutex m_lock;
|
|
|
|
|
CScript m_coinbase;
|
2016-11-21 16:25:50 +01:00
|
|
|
std::vector<unsigned char> m_coinbaseComment;
|
2016-05-05 14:36:07 +01:00
|
|
|
|
|
|
|
|
uint256 m_hashPrevBlock;
|
|
|
|
|
};
|
2013-07-31 09:43:35 -04:00
|
|
|
|
2018-01-16 10:47:52 +00:00
|
|
|
#endif
|