Port of addrindex patch https://github.com/jmcorgan/bitcoin/commit/4790f3c823a33fae44b82ef7962372e38b1b0131