util: Add Assert identity function

The utility is primarily useful to dereference pointer types, which are
known to be not null at that time.

For example, the ArgsManager is known to exist when the wallets are
started. Instead of silently relying on that assumption, Assert can be
used to abort the program and avoid UB should the assumption ever be
violated.
This commit is contained in:
MarcoFalke
2020-06-08 08:47:10 -04:00
parent fa457fbd33
commit fa6ef701ad
4 changed files with 15 additions and 4 deletions

View File

@@ -11,6 +11,7 @@
#include <node/context.h>
#include <pow.h>
#include <script/standard.h>
#include <util/check.h>
#include <validation.h>
CTxIn generatetoaddress(const NodeContext& node, const std::string& address)
@@ -39,9 +40,8 @@ CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
{
assert(node.mempool);
auto block = std::make_shared<CBlock>(
BlockAssembler{*node.mempool, Params()}
BlockAssembler{*Assert(node.mempool), Params()}
.CreateNewBlock(coinbase_scriptPubKey)
->block);