MCPcopy Create free account
hub / github.com/ElementsProject/elements / generateBlocks

Function generateBlocks

src/rpc/mining.cpp:170–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170static UniValue generateBlocks(ChainstateManager& chainman, const CTxMemPool& mempool, const CScript& coinbase_script, int nGenerate, uint64_t nMaxTries)
171{
172 int nHeightEnd = 0;
173 int nHeight = 0;
174
175 { // Don't keep cs_main locked
176 LOCK(cs_main);
177 nHeight = chainman.ActiveChain().Height();
178 nHeightEnd = nHeight+nGenerate;
179 }
180 unsigned int nExtraNonce = 0;
181 UniValue blockHashes(UniValue::VARR);
182 while (nHeight < nHeightEnd && !ShutdownRequested())
183 {
184 std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(chainman.ActiveChainstate(), mempool, Params()).CreateNewBlock(coinbase_script));
185 if (!pblocktemplate.get())
186 throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
187 CBlock *pblock = &pblocktemplate->block;
188
189 uint256 block_hash;
190 if (!GenerateBlock(chainman, *pblock, nMaxTries, nExtraNonce, block_hash)) {
191 break;
192 }
193
194 if (!block_hash.IsNull()) {
195 ++nHeight;
196 blockHashes.push_back(block_hash.GetHex());
197 }
198 }
199 return blockHashes;
200}
201
202static bool getScriptFromDescriptor(const std::string& descriptor, CScript& script, std::string& error)
203{

Callers 2

generatetodescriptorFunction · 0.85
generatetoaddressFunction · 0.85

Calls 11

ShutdownRequestedFunction · 0.85
BlockAssemblerClass · 0.85
JSONRPCErrorFunction · 0.85
GenerateBlockFunction · 0.85
HeightMethod · 0.80
CreateNewBlockMethod · 0.80
ParamsClass · 0.50
getMethod · 0.45
IsNullMethod · 0.45
push_backMethod · 0.45
GetHexMethod · 0.45

Tested by

no test coverage detected