It is better to ues an optional to determine whether the sighash type
is set rather than using 0 as a magic number.
This is a partial backport of core#22514 (the rest of the PR is not relevant, taproot related)
https://github.com/bitcoin/bitcoin/pull/22514/changes/eb9a1a2c595a03475fd4275b104676b7e2200f07