@@ -3395,31 +3395,11 @@ bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& pa
3395
3395
return (height >= params.SegwitHeight );
3396
3396
}
3397
3397
3398
- int GetWitnessCommitmentIndex (const CBlock& block)
3399
- {
3400
- int commitpos = -1 ;
3401
- if (!block.vtx .empty ()) {
3402
- for (size_t o = 0 ; o < block.vtx [0 ]->vout .size (); o++) {
3403
- const CTxOut& vout = block.vtx [0 ]->vout [o];
3404
- if (vout.scriptPubKey .size () >= MINIMUM_WITNESS_COMMITMENT &&
3405
- vout.scriptPubKey [0 ] == OP_RETURN &&
3406
- vout.scriptPubKey [1 ] == 0x24 &&
3407
- vout.scriptPubKey [2 ] == 0xaa &&
3408
- vout.scriptPubKey [3 ] == 0x21 &&
3409
- vout.scriptPubKey [4 ] == 0xa9 &&
3410
- vout.scriptPubKey [5 ] == 0xed ) {
3411
- commitpos = o;
3412
- }
3413
- }
3414
- }
3415
- return commitpos;
3416
- }
3417
-
3418
3398
void UpdateUncommittedBlockStructures (CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams)
3419
3399
{
3420
3400
int commitpos = GetWitnessCommitmentIndex (block);
3421
3401
static const std::vector<unsigned char > nonce (32 , 0x00 );
3422
- if (commitpos != - 1 && IsWitnessEnabled (pindexPrev, consensusParams) && !block.vtx [0 ]->HasWitness ()) {
3402
+ if (commitpos != NO_WITNESS_COMMITMENT && IsWitnessEnabled (pindexPrev, consensusParams) && !block.vtx [0 ]->HasWitness ()) {
3423
3403
CMutableTransaction tx (*block.vtx [0 ]);
3424
3404
tx.vin [0 ].scriptWitness .stack .resize (1 );
3425
3405
tx.vin [0 ].scriptWitness .stack [0 ] = nonce;
@@ -3433,7 +3413,7 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
3433
3413
int commitpos = GetWitnessCommitmentIndex (block);
3434
3414
std::vector<unsigned char > ret (32 , 0x00 );
3435
3415
if (consensusParams.SegwitHeight != std::numeric_limits<int >::max ()) {
3436
- if (commitpos == - 1 ) {
3416
+ if (commitpos == NO_WITNESS_COMMITMENT ) {
3437
3417
uint256 witnessroot = BlockWitnessMerkleRoot (block, nullptr );
3438
3418
CHash256 ().Write (witnessroot).Write (ret).Finalize (witnessroot);
3439
3419
CTxOut out;
@@ -3571,7 +3551,7 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat
3571
3551
bool fHaveWitness = false ;
3572
3552
if (nHeight >= consensusParams.SegwitHeight ) {
3573
3553
int commitpos = GetWitnessCommitmentIndex (block);
3574
- if (commitpos != - 1 ) {
3554
+ if (commitpos != NO_WITNESS_COMMITMENT ) {
3575
3555
bool malleated = false ;
3576
3556
uint256 hashWitness = BlockWitnessMerkleRoot (block, &malleated);
3577
3557
// The malleation check is ignored; as the transaction tree itself
0 commit comments