Skip to content

Commit 2fea10a

Browse files
gmaxwelllaanwj
authored andcommitted
Make GetWitnessCommitmentIndex callable on blocks without a coinbase txn.
This isn't actually needed anywhere, but it's less brittle. Github-Pull: #10146 Rebased-From: ada0caa
1 parent f15268d commit 2fea10a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/validation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,9 +2922,11 @@ bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& pa
29222922
static int GetWitnessCommitmentIndex(const CBlock& block)
29232923
{
29242924
int commitpos = -1;
2925-
for (size_t o = 0; o < block.vtx[0]->vout.size(); o++) {
2926-
if (block.vtx[0]->vout[o].scriptPubKey.size() >= 38 && block.vtx[0]->vout[o].scriptPubKey[0] == OP_RETURN && block.vtx[0]->vout[o].scriptPubKey[1] == 0x24 && block.vtx[0]->vout[o].scriptPubKey[2] == 0xaa && block.vtx[0]->vout[o].scriptPubKey[3] == 0x21 && block.vtx[0]->vout[o].scriptPubKey[4] == 0xa9 && block.vtx[0]->vout[o].scriptPubKey[5] == 0xed) {
2927-
commitpos = o;
2925+
if (!block.vtx.empty()) {
2926+
for (size_t o = 0; o < block.vtx[0]->vout.size(); o++) {
2927+
if (block.vtx[0]->vout[o].scriptPubKey.size() >= 38 && block.vtx[0]->vout[o].scriptPubKey[0] == OP_RETURN && block.vtx[0]->vout[o].scriptPubKey[1] == 0x24 && block.vtx[0]->vout[o].scriptPubKey[2] == 0xaa && block.vtx[0]->vout[o].scriptPubKey[3] == 0x21 && block.vtx[0]->vout[o].scriptPubKey[4] == 0xa9 && block.vtx[0]->vout[o].scriptPubKey[5] == 0xed) {
2928+
commitpos = o;
2929+
}
29282930
}
29292931
}
29302932
return commitpos;

0 commit comments

Comments
 (0)