Implement "getchains" RPC command to monitor blockchain forks.

Port over https://github.com/chronokings/huntercoin/pull/19 from
Huntercoin:  This implements a new RPC command "getchains" that can be
used to find all currently active chain heads.  This is similar to the
-printblocktree startup option, but it can be used without restarting
just via the RPC interface on a running daemon.
This assert should never really happen, and it shouldn't be possible to trigger it by invalid user input or something like that.  For me, this is precisely a situation where one wants to assert().  But if it is more in line with Bitcoin Core philosophy to throw a JSONRPCError, I can, of course, do that.