Move most of txToPairs into a new createTx func

Also changes it so that it adds new inputs incrementally as needed instead
of starting with an empty tx and adding all inputs again on each iteration.
Yeah, I also found this surprising but it is how the existing code behaves -- I just removed the for loop around this code, btw.