[bitcoin/bitcoin] Simple refactoring: Common code for decoding of hex «objects» (#14009)

The template is not that long, and it’s only instanced twice. Not sure if it’s worth it.

utACK b9a19f3 anyway.