We should probably break this function up into getAddress, getPubKeys, getSortedPubkeys, and getRedeemScript, like I did in Treasure. That makes it easier to test and makes for more readable code.