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.
I think this error declaration can be removed from here.  It looks like the first place it's assigned to is on line 199.