2

Example of the first output being a masternode reward
Example of the first output being a proof-of-work reward

What determines the order of the outputs in the generation transaction?

As far as I understand it:

In src/miner.cpp in the CreateNewBlock function it is determined that the vout index for proof-of-work is 0. Line 86-90:

CMutableTransaction txNew;
txNew.vin.resize(1);
txNew.vin[0].prevout.SetNull();
txNew.vout.resize(1);
txNew.vout[0].scriptPubKey = scriptPubKeyIn;

Later on in the function it calls the FillBlockPayments function In src/masternode-payments.cpp Line 294:

FillBlockPayments(txNew, nHeight, blockReward, pblock->txoutMasternode, pblock->voutSuperblock);

which calls the FillBlockPayee function. Line 222:

mnpayments.FillBlockPayee(txNew, nBlockHeight, blockReward, txoutMasternodeRet);

There the masternode reward is appended as an additional vout to the transaction txNew. Line 287-291:

// split reward between miner ...
txNew.vout[0].nValue -= masternodePayment;
// ... and masternode
txoutMasternodeRet = CTxOut(masternodePayment, payee);
txNew.vout.push_back(txoutMasternodeRet);

Why then, in the generation transaction, is the first output not always the proof-of-work reward?

closed as off-topic by MeshCollider Jul 23 at 9:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about cryptocurrencies or projects that are not Bitcoin, and are not applicable to Bitcoin, are off-topic. For more information, see this meta-discussion." – MeshCollider
If this question can be reworded to fit the rules in the help center, please edit the question.