From 8e7cf04ad2cbb2c61756475f7882472ba1826d06 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 28 Jun 2021 22:34:35 -0400 Subject: [PATCH] Fix upstream KMD crash bug in getblocktemplate when disablewallet=1 Originally https://github.com/DeckerSU/komodo/commit/dc8e1695c23908a2e797a48f1e7b428070c336b7 --- src/miner.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 165497694..7ce7cf404 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -857,19 +857,26 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG; } else { { - if (!reservekey.GetReservedKey(pubkey)) - { - return NULL; - } - scriptPubKey.resize(35); - ptr = (uint8_t *)pubkey.begin(); - scriptPubKey[0] = 33; - for (i=0; i<33; i++) { - scriptPubKey[i+1] = ptr[i]; - } - scriptPubKey[34] = OP_CHECKSIG; - } - } + // Support mining with -disablewallet and minetolocalwallet=0 + if (!GetBoolArg("-disablewallet", false)) { + // wallet enabled + if (!reservekey.GetReservedKey(pubkey)) + return NULL; + scriptPubKey.clear(); + scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; + } else { + // wallet disabled + CTxDestination dest = DecodeDestination(GetArg("-mineraddress", "")); + if (IsValidDestination(dest)) { + // CKeyID keyID = boost::get(dest); + // scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG; + scriptPubKey = GetScriptForDestination(dest); + } else { + return NULL; + } + } + } + } return CreateNewBlock(pubkey, scriptPubKey, gpucount, isStake); }