So far, I have found no information about how transaction fees are included in a transaction, other than the higher-level description found on the wiki:
https://en.bitcoin.it/wiki/Transaction_feesAll it says is that the outputs add up to less than the inputs, so that the miner can include themself for the "leftover" output. However, after finally understanding OP_CHECKSIG, I don't see how this possible with SIGHASH_ALL hash code. SIGHASH_ALL includes
all output scripts in the TxCopy that is serialized and signed by the sender, so the miner cannot modify/add any outputs without breaking the signature. But I also heard that the other hash codes are not used. Even if they were used, I'm having a tough time figuring out what they do.
Can anyone clarify how this is handled?