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

Function GetValidFedpegScripts

src/pegins.cpp:461–505  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

459}
460
461std::vector<std::pair<CScript, CScript>> GetValidFedpegScripts(const CBlockIndex* pblockindex, const Consensus::Params& params, bool nextblock_validation)
462{
463 assert(pblockindex);
464
465 std::vector<std::pair<CScript, CScript>> fedpegscripts;
466
467 const int32_t epoch_length = (int32_t) params.dynamic_epoch_length;
468 const int32_t epoch_age = pblockindex->nHeight % epoch_length;
469 const int32_t epoch_start_height = pblockindex->nHeight - epoch_age;
470
471 // In mempool and general "enforced next block" RPC we need to look ahead one block
472 // to see if we're on a boundary. If so, put that epoch's fedpegscript in place
473 if (nextblock_validation && epoch_age == epoch_length - 1) {
474 DynaFedParamEntry next_param = ComputeNextBlockFullCurrentParameters(pblockindex, params);
475 fedpegscripts.push_back(std::make_pair(next_param.m_fedpeg_program, next_param.m_fedpegscript));
476 }
477
478 // Next we walk backwards up to M epoch starts
479 for (int32_t i = 0; i < (int32_t) params.total_valid_epochs; i++) {
480 // We are within total_valid_epochs of the genesis
481 if (i * epoch_length > epoch_start_height) {
482 break;
483 }
484
485 const CBlockIndex* p_epoch_start = pblockindex->GetAncestor(epoch_start_height-i*epoch_length);
486
487 // We're done here, for whatever reason.
488 if (!p_epoch_start) {
489 break;
490 }
491
492 if (node::fTrimHeaders) {
493 LOCK(cs_main);
494 ForceUntrimHeader(p_epoch_start);
495 }
496 if (!p_epoch_start->dynafed_params().IsNull()) {
497 fedpegscripts.push_back(std::make_pair(p_epoch_start->dynafed_params().m_current.m_fedpeg_program, p_epoch_start->dynafed_params().m_current.m_fedpegscript));
498 } else {
499 fedpegscripts.push_back(std::make_pair(GetScriptForDestination(ScriptHash(GetScriptForDestination(WitnessV0ScriptHash(params.fedpegScript)))), params.fedpegScript));
500 }
501 }
502 // Only return up to the latest total_valid_epochs fedpegscripts, which are enforced
503 fedpegscripts.resize(std::min(fedpegscripts.size(), params.total_valid_epochs));
504 return fedpegscripts;
505}
506
507template<typename T_tx_ref, typename T_merkle_block>
508CScriptWitness CreatePeginWitnessInner(const CAmount& value, const CAsset& asset, const uint256& genesis_hash, const CScript& claim_script, const T_tx_ref& tx_ref, const T_merkle_block& merkle_block)

Callers 14

removeForBlockMethod · 0.85
checkMethod · 0.85
PreChecksMethod · 0.85
DisconnectBlockMethod · 0.85
ConnectBlockMethod · 0.85
ConnectTipMethod · 0.85
FundTransactionFunction · 0.85
getpeginaddressFunction · 0.85
blindrawtransactionFunction · 0.85
rawblindrawtransactionFunction · 0.85
tweakfedpegscriptFunction · 0.85
CreatePegInInputInnerFunction · 0.85

Calls 9

GetScriptForDestinationFunction · 0.85
ScriptHashClass · 0.85
WitnessV0ScriptHashClass · 0.85
GetAncestorMethod · 0.80
push_backMethod · 0.45
IsNullMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected