Refactor rawtransaction's SignTransaction into generic SignTransaction function
Summary: Backport of Core PR18115 part [1/9] : https://github.com/bitcoin/bitcoin/pull/18115/commits/2c52b59d0a44a86d94fee4e437978d822862c542
Test Plan:
ninja all check-all
Reviewers: #bitcoin_abc, PiRK
Reviewed By: PiRK
Differential Revision: https://reviews.bitcoinabc.org/D8094