aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/mining.cpp
diff options
context:
space:
mode:
authorDaniel Kraft <d@domob.eu>2016-06-18 19:38:28 +0200
committerDaniel Kraft <d@domob.eu>2016-06-18 19:38:28 +0200
commit9fce0629b437441cb09c14055ee810b8ee6b7978 (patch)
treed7bfbb98986afba0d89a97d5c9824398d8a1feda /src/rpc/mining.cpp
parented2cd59e258f756b2eaed7909a60956ade6ef7ee (diff)
downloadbitcoin-9fce0629b437441cb09c14055ee810b8ee6b7978.tar.xz
[c++11] Use std::unique_ptr for block creation.
CreateNewBlock returns a pointer for which the caller takes ownership. Use std::unique_ptr to make this explicit and simplify handling of these objects in getblocktemplate.
Diffstat (limited to 'src/rpc/mining.cpp')
-rw-r--r--src/rpc/mining.cpp10
1 files changed, 3 insertions, 7 deletions
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index 94eeea91f3..162f4a0721 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -22,6 +22,7 @@
#include "utilstrencodings.h"
#include "validationinterface.h"
+#include <memory>
#include <stdint.h>
#include <boost/assign/list_of.hpp>
@@ -508,12 +509,12 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
// Update block
static CBlockIndex* pindexPrev;
static int64_t nStart;
- static CBlockTemplate* pblocktemplate;
+ static std::unique_ptr<CBlockTemplate> pblocktemplate;
if (pindexPrev != chainActive.Tip() ||
(mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5))
{
// Clear pindexPrev so future calls make a new block, despite any failures from here on
- pindexPrev = NULL;
+ pindexPrev = nullptr;
// Store the pindexBest used before CreateNewBlock, to avoid races
nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
@@ -521,11 +522,6 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
nStart = GetTime();
// Create new block
- if(pblocktemplate)
- {
- delete pblocktemplate;
- pblocktemplate = NULL;
- }
CScript scriptDummy = CScript() << OP_TRUE;
pblocktemplate = BlockAssembler(Params()).CreateNewBlock(scriptDummy);
if (!pblocktemplate)