From 50d99bb4187f9b915298c37195972dec4728cfef Mon Sep 17 00:00:00 2001 From: furszy Date: Tue, 6 Apr 2021 15:48:56 -0300 Subject: [PATCH] [Miner] Enable PoW block creations with custom coinbase script --- src/miner.cpp | 10 ++++++---- src/miner.h | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 7e2e1499425cf..38ada115751b1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -42,9 +42,12 @@ int64_t nHPSTimerStart = 0; std::unique_ptr CreateNewBlockWithKey(CReserveKey* reservekey, CWallet* pwallet) { CPubKey pubkey; - if (!reservekey->GetReservedKey(pubkey)) - return nullptr; + if (!reservekey->GetReservedKey(pubkey)) return nullptr; + return CreateNewBlockWithScript(GetScriptForDestination(pubkey.GetID()), pwallet); +} +std::unique_ptr CreateNewBlockWithScript(const CScript& coinbaseScript, CWallet* pwallet) +{ const int nHeightNext = chainActive.Tip()->nHeight + 1; // If we're building a late PoW block, don't continue @@ -56,8 +59,7 @@ std::unique_ptr CreateNewBlockWithKey(CReserveKey* reservekey, C return nullptr; } - CScript scriptPubKey = GetScriptForDestination(pubkey.GetID()); - return BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, pwallet, false); + return BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(coinbaseScript, pwallet, false); } bool ProcessBlockFound(const std::shared_ptr& pblock, CWallet& wallet, Optional& reservekey) diff --git a/src/miner.h b/src/miner.h index c4feb04cfe09f..6a141e9920678 100644 --- a/src/miner.h +++ b/src/miner.h @@ -26,8 +26,9 @@ static const bool DEFAULT_PRINTPRIORITY = false; #ifdef ENABLE_WALLET /** Run the miner threads */ void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads); - /** Generate a new block, without valid proof-of-work */ + /** Generate a new PoW block, without valid proof-of-work */ std::unique_ptr CreateNewBlockWithKey(CReserveKey* reservekey, CWallet* pwallet); + std::unique_ptr CreateNewBlockWithScript(const CScript& coinbaseScript, CWallet* pwallet); void BitcoinMiner(CWallet* pwallet, bool fProofOfStake); void ThreadStakeMinter();