Prepare for non-malleable scripts

Not sure what else to call them. Script malleability means that a script can be manipulated such that it is used multiple times, even though permission was only given for the script to be used once.

This has a lot of preparatory code for preventing that. Luke needs to add deadline processing, and then I need to finish the integration with the event list.