[checkqueue] support user-defined return type through std::optional
Summary:
The check type function now needs to return a std::optional<R> for some type R,
and the check queue overall will return std::nullopt if all individual checks
return that, or one of the non-nullopt values if there is at least one.
For most tests, we use R=int, but for the actual validation code, we make it return
the ScriptError.
This is a partial backport of core#31112
https://github.com/bitcoin/bitcoin/pull/31112/commits/1ac1c33f3f120bbe0bde4fa948299bc07cac47ee
Note that there is a minor difference in validation.cpp (scriptError vs error) because a nearly identical work on improving the error message was done independently by Bitcoin ABC and Bitcoin Core:
Test Plan: ninja all check-all
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Subscribers: Fabien
Differential Revision: https://reviews.bitcoinabc.org/D18876