Overload Script.getToAddress() with a variant that tries harder to determine a destination address.

I ended up duplicating this piece of code several times, so I thought it may be useful to have it in the framework.

Includes tests.