cashscript
cashscript copied to clipboard
Add better support for "state simulation"
See comments in #98
We can add an OP_CODESEPARATOR between the constructor args and the bytecode. This should make it easier to make "state simulated" contracts. Since then OP_ACTIVEBYTECODE would always be the "base" bytecode, and we could add the "new" state in front of that.
Example syntax (for a contract with name ExampleContract):
bytes34 output = new OutputP2SH(bytes8(1000), hash160(new ExampleContract(tx.locktime + 100, 1000)));
Then the compiled output for new ExampleContract(tx.locktime + 100, 1000) will be something like this:
<VarInt> <1000> OP_CAT <VarInt> <tx.locktime + 100> OP_CAT OP_CAT OP_ACTIVEBYTECODE OP_CAT
We just need to figure out whether we can dynamically determine the VarInts and how to do that.
After discussion on Telegram I realised that OP_INPUTINDEX OP_UTXOBYTECODE only pushes the locking script (not the redeem script). While OP_ACTIVEBYTECODE pushes the redeem script. So I'll need to include OP_ACTIVEBYTECODE support in the upcoming next release. This makes the construction above slightly more tricky since I'll still have to account for the case with and without constructor args.
Now that CashTokens are live, I think the best way to do most state simulation is through NFT commitments. So I'll close this issue.