Skip to content

Commit ada0caa

Browse files
committed
Make GetWitnessCommitmentIndex callable on blocks without a coinbase txn.
This isn't actually needed anywhere, but it's less brittle.
1 parent ebfd653 commit ada0caa

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
@@ -2901,9 +2901,11 @@ bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& pa
29012901
static int GetWitnessCommitmentIndex(const CBlock& block)
29022902
{
29032903
int commitpos = -1;
2904-
for (size_t o = 0; o < block.vtx[0]->vout.size(); o++) {
2905-
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) {
2906-
commitpos = o;
2904+
if (!block.vtx.empty()) {
2905+
for (size_t o = 0; o < block.vtx[0]->vout.size(); o++) {
2906+
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) {
2907+
commitpos = o;
2908+
}
29072909
}
29082910
}
29092911
return commitpos;

0 commit comments

Comments
 (0)