Refactor some common code in address.go.

Rather than repeating the same code in both the pay-to-pubkey-hash and
pay-to-script-hash encoding, refactor it into separate functions.  This
makes it easier to support new networks, for example, since it can be
changed in one place.