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 thought that would work but then I need to use the short declaration form in line 199, which redeclares changeAddr inside the if block and thus introduces a bug wherein tx.changeAddr ends up always empty.