Bitcoin
presegwit What is the transaction digest algorithm for transaction input validation?

For p2wsh and p2pkh, the BIP143 transaction digest algorithm works great. But how to serialize transactions to generate commit hashes for p2pkh, p2sh transactions?