[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.
This commit is contained in:
Daniel Kraft
2016-06-18 19:38:28 +02:00
parent ed2cd59e25
commit 9fce0629b4
5 changed files with 15 additions and 24 deletions

View File

@@ -29,6 +29,7 @@
#include <boost/thread.hpp>
#include <boost/tuple/tuple.hpp>
#include <queue>
#include <utility>
using namespace std;
@@ -102,14 +103,14 @@ void BlockAssembler::resetBlock()
blockFinished = false;
}
CBlockTemplate* BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
std::unique_ptr<CBlockTemplate> 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)