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

In my opinion, this make the code easier to read and maintain (by avoiding duplication) — but of course there might be an argument that templates should be used sparingly and only where absolutely necessary. But I think this use does not introduce any complexity for readers of the code, as it is immediately next to the only usages.