db: Make reusable base class for index databases.
Summary:
backported second commit (e5af5fc6f) from PR13243
https://github.com/bitcoin/bitcoin/commit/e5af5fc6f
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/D2934