index: Extract logic from TxIndex into reusable base class.
Summary:
backported third commit (61a1226d8) from PR13243
https://github.com/bitcoin/bitcoin/commit/61a1226d8
Depends on D2924
Test Plan: make check
Reviewers: #bitcoin_abc, deadalnix, jasonbcox, Fabien
Reviewed By: #bitcoin_abc, deadalnix
Maniphest Tasks: T630
Differential Revision: https://reviews.bitcoinabc.org/D2935