|
20 | 20 | #include <script/standard.h> |
21 | 21 | #include <streams.h> |
22 | 22 | #include <util/system.h> |
| 23 | +#include <dynafed.h> |
23 | 24 |
|
24 | 25 | // |
25 | 26 | // ELEMENTS |
@@ -443,3 +444,44 @@ bool MatchLiquidWatchman(const CScript& script) |
443 | 444 | // No more pushes |
444 | 445 | return (it == script.end()); |
445 | 446 | } |
| 447 | + |
| 448 | +std::vector<CScript> GetValidFedpegScripts(const CBlockIndex* pblockindex, const Consensus::Params& params, bool nextblock_validation) |
| 449 | +{ |
| 450 | + assert(pblockindex); |
| 451 | + |
| 452 | + std::vector<CScript> fedpegscripts; |
| 453 | + |
| 454 | + const int32_t epoch_length = params.dynamic_epoch_length; |
| 455 | + const int32_t epoch_age = pblockindex->nHeight % epoch_length; |
| 456 | + const int32_t epoch_start_height = pblockindex->nHeight - epoch_age; |
| 457 | + |
| 458 | + // In mempool and general "enforced next block" RPC we need to look ahead one block |
| 459 | + // to see if we're on a boundary. If so, put that epoch's fedpegscript in place |
| 460 | + if (nextblock_validation && epoch_age == epoch_length - 1) { |
| 461 | + fedpegscripts.push_back(ComputeNextBlockFullCurrentParameters(pblockindex, params).m_fedpegscript); |
| 462 | + } |
| 463 | + |
| 464 | + // Next we walk backwards up to two epoch start blocks |
| 465 | + const CBlockIndex* p_current_epoch_start = pblockindex->GetAncestor(epoch_start_height); |
| 466 | + const CBlockIndex* p_prev_epoch_start = pblockindex->GetAncestor(epoch_start_height-epoch_length); |
| 467 | + |
| 468 | + if (p_current_epoch_start) { |
| 469 | + if (!p_current_epoch_start->d_params.IsNull()) { |
| 470 | + fedpegscripts.push_back(p_current_epoch_start->d_params.m_current.m_fedpegscript); |
| 471 | + } else { |
| 472 | + fedpegscripts.push_back(params.fedpegScript); |
| 473 | + } |
| 474 | + } |
| 475 | + |
| 476 | + if (p_prev_epoch_start) { |
| 477 | + if (!p_prev_epoch_start->d_params.IsNull()) { |
| 478 | + fedpegscripts.push_back(p_prev_epoch_start->d_params.m_current.m_fedpegscript); |
| 479 | + } else { |
| 480 | + fedpegscripts.push_back(params.fedpegScript); |
| 481 | + } |
| 482 | + } |
| 483 | + |
| 484 | + // Only return up to the latest two of three possible fedpegscripts, which are enforced |
| 485 | + fedpegscripts.resize(std::min((int)fedpegscripts.size(), 2)); |
| 486 | + return fedpegscripts; |
| 487 | +} |
0 commit comments