1
Finally, I've successfully made a raw transaction with Python and this is the last thing, which is totally mistic for me.
In my case, here's the input transaction and it's locking script is:
OP_DUP OP_HASH160 dab3cccc50d7ff2d1d2926ec85ca186e61aef105 OP_EQUALVERIFY OP_CHECKSIG
Why it's necessary to set up the unlocking script to the input's locking script before signing? In my understanding, all the stuff should work well even with blank locking script, because in fact we're signing only other parameters. Unlocking script and unlocking script lenght will be changed anyway, so what's the reason?
1But what about security - am I right, that before the transaction will be included into the block, miner can edit unlocking script + unlocking script lenght, and transaction will still be valid? – Sergey Potekhin – 2017-01-05T16:49:13.903
2Yes, that's called malleability, and it is possible. However, it cannot be avoided, as we can't have signatures that sign themselves (as they are in the unlocking script). A way around it is the Segregated Witness proposal, which does not prevent malleability, but makes the unlocking script not contribute to txid calculation. – Pieter Wuille – 2017-01-05T17:03:51.597