Skip to content

Commit

Permalink
allow for block generation before 0.8 activates
Browse files Browse the repository at this point in the history
  • Loading branch information
backpacker69 committed May 28, 2019
1 parent 7058fa5 commit 03b5eda
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/rpc/mining.cpp
Expand Up @@ -134,7 +134,7 @@ UniValue getnetworkghps(const JSONRPCRequest& request)
return dNetworkGhps;
}

UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript)
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript, CWallet * const pwallet)
{
static const int nInnerLoopCount = 0x10000;
int nHeightEnd = 0;
Expand Down Expand Up @@ -167,6 +167,12 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
if (pblock->nNonce == nInnerLoopCount) {
continue;
}

// peercoin: sign block
// rfc6: we sign proof of work blocks only before 0.8 fork
if (!IsBTC16BIPsEnabled(pblock->GetBlockTime()) && !SignBlock(*pblock, *pwallet))
throw JSONRPCError(-100, "Unable to sign block, wallet locked?");

std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
if (!ProcessNewBlock(Params(), shared_pblock, true, nullptr))
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
Expand Down Expand Up @@ -199,6 +205,11 @@ UniValue generatetoaddress(const JSONRPCRequest& request)
+ HelpExampleCli("generatetoaddress", "11 \"myaddress\"")
);

CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue;
}

int nGenerate = request.params[0].get_int();
uint64_t nMaxTries = 1000000;
if (!request.params[2].isNull()) {
Expand All @@ -213,7 +224,7 @@ UniValue generatetoaddress(const JSONRPCRequest& request)
std::shared_ptr<CReserveScript> coinbaseScript = std::make_shared<CReserveScript>();
coinbaseScript->reserveScript = GetScriptForDestination(destination);

return generateBlocks(coinbaseScript, nGenerate, nMaxTries, false);
return generateBlocks(coinbaseScript, nGenerate, nMaxTries, false, pwallet);
}

UniValue getmininginfo(const JSONRPCRequest& request)
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/mining.h
Expand Up @@ -6,11 +6,12 @@
#define BITCOIN_RPC_MINING_H

#include <script/script.h>
#include <wallet/wallet.h>

#include <univalue.h>

/** Generate blocks (mine) */
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript);
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript, CWallet * const pwallet);

/** Check bounds on a command line confirm target */
unsigned int ParseConfirmTarget(const UniValue& value);
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcwallet.cpp
Expand Up @@ -3238,7 +3238,7 @@ UniValue generate(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available");
}

return generateBlocks(coinbase_script, num_generate, max_tries, true);
return generateBlocks(coinbase_script, num_generate, max_tries, true, pwallet);
}

UniValue rescanblockchain(const JSONRPCRequest& request)
Expand Down

0 comments on commit 03b5eda

Please sign in to comment.