Input selection algorithm

Rebased to vp-withdrawal.

Note I had to make some minor changes to make the test run again.

Also the createInputs and createInputsStore needs to be cleaned up. They are both taking a store right now and especially the createInputsStore name is misleading.
I know you've just moved this around, but there were XXXs before because I think we need to document them. Care to add the XXXs back or change the doc for createInputs() to explain we'll use these values and what implications they have?