Refactor Wallet.txToPairs into smaller functions

Also add a unit test for one of them.