@@ -141,7 +141,7 @@ CScript calculate_contract(const CScript& federation_script, const CScript& scri
141141}
142142
143143template <typename T>
144- static bool CheckPeginTx (const std::vector<unsigned char >& tx_data, T& pegtx, const COutPoint& prevout, const CAmount claim_amount, const CScript& claim_script, const std::vector<CScript>& fedpegscripts)
144+ static bool CheckPeginTx (const std::vector<unsigned char >& tx_data, T& pegtx, const COutPoint& prevout, const CAmount claim_amount, const CScript& claim_script, const std::vector<std::pair< CScript, CScript> >& fedpegscripts)
145145{
146146 try {
147147 CDataStream pegtx_stream (tx_data, SER_NETWORK, PROTOCOL_VERSION);
@@ -171,12 +171,15 @@ static bool CheckPeginTx(const std::vector<unsigned char>& tx_data, T& pegtx, co
171171 return false ;
172172 }
173173
174- // Check that the witness program matches the p2ch on the p2sh-p2wsh transaction output
175- // We support multiple scripts as a grace period for peg-in users
176- for (const auto & fedpegscript : fedpegscripts) {
177- CScript tweaked_fedpegscript = calculate_contract (fedpegscript, claim_script);
178- CScript witness_output (GetScriptForWitness (tweaked_fedpegscript));
179- CScript expected_script (CScript () << OP_HASH160 << ToByteVector (ScriptHash (CScriptID (witness_output))) << OP_EQUAL);
174+ // Check that the witness program matches the p2ch on the (p2sh-)p2wsh
175+ // transaction output. We support multiple scripts as a grace period for peg-in users
176+ for (const auto & scripts : fedpegscripts) {
177+ CScript tweaked_fedpegscript = calculate_contract (scripts.second , claim_script);
178+ // TODO: Remove script/standard.h dep for GetScriptFor*
179+ CScript expected_script (GetScriptForWitness (tweaked_fedpegscript));
180+ if (scripts.first .IsPayToScriptHash ()) {
181+ expected_script = GetScriptForDestination (ScriptHash (expected_script));
182+ }
180183 if (pegtx->vout [prevout.n ].scriptPubKey == expected_script) {
181184 return true ;
182185 }
@@ -228,7 +231,7 @@ bool CheckParentProofOfWork(uint256 hash, unsigned int nBits, const Consensus::P
228231 return true ;
229232}
230233
231- bool IsValidPeginWitness (const CScriptWitness& pegin_witness, const std::vector<CScript>& fedpegscripts, const COutPoint& prevout, std::string& err_msg, bool check_depth) {
234+ bool IsValidPeginWitness (const CScriptWitness& pegin_witness, const std::vector<std::pair< CScript, CScript> >& fedpegscripts, const COutPoint& prevout, std::string& err_msg, bool check_depth) {
232235 // 0) Return false if !consensus.has_parent_chain
233236 if (!Params ().GetConsensus ().has_parent_chain ) {
234237 err_msg = " Parent chain is not enabled on this network." ;
@@ -447,11 +450,11 @@ bool MatchLiquidWatchman(const CScript& script)
447450 return (it == script.end ());
448451}
449452
450- std::vector<CScript> GetValidFedpegScripts (const CBlockIndex* pblockindex, const Consensus::Params& params, bool nextblock_validation)
453+ std::vector<std::pair< CScript, CScript> > GetValidFedpegScripts (const CBlockIndex* pblockindex, const Consensus::Params& params, bool nextblock_validation)
451454{
452455 assert (pblockindex);
453456
454- std::vector<CScript> fedpegscripts;
457+ std::vector<std::pair< CScript, CScript> > fedpegscripts;
455458
456459 const int32_t epoch_length = params.dynamic_epoch_length ;
457460 const int32_t epoch_age = pblockindex->nHeight % epoch_length;
@@ -460,7 +463,8 @@ std::vector<CScript> GetValidFedpegScripts(const CBlockIndex* pblockindex, const
460463 // In mempool and general "enforced next block" RPC we need to look ahead one block
461464 // to see if we're on a boundary. If so, put that epoch's fedpegscript in place
462465 if (nextblock_validation && epoch_age == epoch_length - 1 ) {
463- fedpegscripts.push_back (ComputeNextBlockFullCurrentParameters (pblockindex, params).m_fedpegscript );
466+ DynaFedParamEntry next_param = ComputeNextBlockFullCurrentParameters (pblockindex, params);
467+ fedpegscripts.push_back (std::make_pair (next_param.m_fedpeg_program , next_param.m_fedpegscript ));
464468 }
465469
466470 // Next we walk backwards up to two epoch start blocks
@@ -469,17 +473,17 @@ std::vector<CScript> GetValidFedpegScripts(const CBlockIndex* pblockindex, const
469473
470474 if (p_current_epoch_start) {
471475 if (!p_current_epoch_start->dynafed_params .IsNull ()) {
472- fedpegscripts.push_back (p_current_epoch_start->dynafed_params .m_current .m_fedpegscript );
476+ fedpegscripts.push_back (std::make_pair ( p_current_epoch_start->dynafed_params .m_current .m_fedpeg_program , p_current_epoch_start-> dynafed_params . m_current . m_fedpegscript ) );
473477 } else {
474- fedpegscripts.push_back (params.fedpegScript );
478+ fedpegscripts.push_back (std::make_pair ( GetScriptForDestination ( ScriptHash ( GetScriptForDestination ( WitnessV0ScriptHash ( params.fedpegScript )))), params. fedpegScript ) );
475479 }
476480 }
477481
478482 if (p_prev_epoch_start) {
479483 if (!p_prev_epoch_start->dynafed_params .IsNull ()) {
480- fedpegscripts.push_back (p_prev_epoch_start->dynafed_params .m_current .m_fedpegscript );
484+ fedpegscripts.push_back (std::make_pair ( p_prev_epoch_start->dynafed_params .m_current .m_fedpeg_program , p_prev_epoch_start-> dynafed_params . m_current . m_fedpegscript ) );
481485 } else {
482- fedpegscripts.push_back (params.fedpegScript );
486+ fedpegscripts.push_back (std::make_pair ( GetScriptForDestination ( ScriptHash ( GetScriptForDestination ( WitnessV0ScriptHash ( params.fedpegScript )))), params. fedpegScript ) );
483487 }
484488 }
485489
0 commit comments