This adds some abstraction and make the code more readable by replacing byte operations on hex transactions by `CTransaction` & `CTxOut` objects.
The PR mentions a minor 4% increase in time for some tests, which is considered an acceptable compromise in exchange for more clarity.
The `import`s are not at the top of the module to avoid a circular import issue. This indicates that the `util` and `messages` modules would benefit from some refactoring.
This is a backport of Core PR15282