Delegation in Bitcoin: Part 3
Previously, we have introduced two ways to delegate the right to spend one’s bitcoin: one at Script level, the other at transaction level.
We generalize the former to delegate to any script/smart contract, instead of a public key only. It allows one to authorize arbitrary smart contract to spend one’s bitcoin.
The full code is shown below:
Line 9 checks the delegated script is signed and thus authorized by the owner. Line 12 and 13 ensure the delegated script goes into the spending transaction’s output as the new locking script using OP_PUSH_TX, similar to the emulation of Pay to Script Hash (P2SH).