From 9fce0629b437441cb09c14055ee810b8ee6b7978 Mon Sep 17 00:00:00 2001 From: Daniel Kraft Date: Sat, 18 Jun 2016 19:38:28 +0200 Subject: [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. --- src/miner.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/miner.cpp') diff --git a/src/miner.cpp b/src/miner.cpp index 989ad11a26..d38ccedf55 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -29,6 +29,7 @@ #include #include #include +#include using namespace std; @@ -102,14 +103,14 @@ void BlockAssembler::resetBlock() blockFinished = false; } -CBlockTemplate* BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn) +std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn) { resetBlock(); pblocktemplate.reset(new CBlockTemplate()); if(!pblocktemplate.get()) - return NULL; + return nullptr; pblock = &pblocktemplate->block; // pointer for convenience // Add dummy coinbase tx as first transaction @@ -164,7 +165,7 @@ CBlockTemplate* BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn) throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, FormatStateMessage(state))); } - return pblocktemplate.release(); + return std::move(pblocktemplate); } bool BlockAssembler::isStillDependent(CTxMemPool::txiter iter) -- cgit v1.2.3