Implement getchains RPC command.

This patch adds a new RPC command "getchains" that returns all known heads of blockchain branches.  For heads not on the main chain, also all block hashes along the branch connecting it back to the fork point from the main chain are returned.